sklearn - Cross validation with multiple scores

前端 未结 5 1488
半阙折子戏
半阙折子戏 2020-12-23 17:46

I would like to compute the recall, precision and f-measure of a cross validation test for different classifiers. scik

5条回答
  •  半阙折子戏
    2020-12-23 18:40

    This might be helpful if you looking multiple-metrics with multi-classes. With the latest doc in scikit learn 0.19 and above; you can pass your own dictionary with metric functions;

    custom_scorer = {'accuracy': make_scorer(accuracy_score),
                     'balanced_accuracy': make_scorer(balanced_accuracy_score),
                     'precision': make_scorer(precision_score, average='macro'),
                     'recall': make_scorer(recall_score, average='macro'),
                     'f1': make_scorer(f1_score, average='macro'),
                     }
    scores = cross_validation.cross_val_score(clf, X_train, y_train,
            cv = 10, scoring = custom_scorer)
    
    

提交回复
热议问题