I am trying to get the mean of precision and recall for BOTH positive and negative class in a 10-fold cross validation. My model is a binary classifier.
I ran the codes below and unfortunately it only returned the mean precision and recall for the positive class. How can I tell the algorithm to return the mean precision and recall scores for the negative class as well?
from sklearn.metrics import make_scorer, accuracy_score, precision_score, recall_score, f1_score
from sklearn.model_selection import cross_validate
scoring = {'accuracy' : make_scorer(accuracy_score),
'precision' : make_scorer(precision_score),
'recall' : make_scorer(recall_score),
'f1_score' : make_scorer(f1_score)}
results = cross_validate(model_unbalanced_data_10_times_weight, X, Y, cv=10, scoring=scoring)
np.mean(results['test_precision'])
np.mean(results['test_recall'])
I've also tried printing the classification report using the command "classification_report(y_test, predictions)
" which resulted in the printout in screenshot below. However, I believe the precision/recall scores from the classification report is based on 1 run only and not the average over 10 folds (correct me if I am wrong).
classification_report
fromsklearn.metrics
? It provides precision/recall scores by class which seems to fit yuor need. – anddt