I have created a 5-fold cross validation model and used cross_val_score function to calculate the precision and recall of the cross validated model as follows:
def print_accuracy_report(classifier, X, y, num_validations=5):
precision = cross_validation.cross_val_score(classifier,
X, y, scoring='precision', cv=num_validations)
print "Precision: " + str(round(100*precision.mean(), 2)) + "%"
recall = cross_validation.cross_val_score(classifier,
X, y, scoring='recall', cv=num_validations)
print "Recall: " + str(round(100*recall.mean(), 2)) + "%"
I wonder if I'm allowed to do these lines:
print "Precision: " + str(round(100*precision.mean(), 2)) + "%"
print "Recall: " + str(round(100*recall.mean(), 2)) + "%"
I mean does this precision.mean() and recall.mean() represent the precision and recall of the whole model?
Just for comparison's sake, in the scikit-learn's documentation I've seen the model's accuracy is calculated as :
from sklearn.model_selection import cross_val_score
clf = svm.SVC(kernel='linear', C=1)
scores = cross_val_score(clf, iris.data, iris.target, cv=5)
print(scores)
array([0.96..., 1. ..., 0.96..., 0.96..., 1. ])
print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))
Accuracy: 0.98 (+/- 0.03)
.mean()operation is authentic. Right? 2) How can I make them stratified as you said? Should I useprecision_weightedandreacall_weightedforscoringparameter? Should I useStratifiedKFold? – hyTuev Jan 24 '19 at 15:09