Reputation: 599
I am using scikit-lear for classification. I am using cross validation for finding effectiveness of the classification algorithm. I want to compute accuracy, precision, recall, F1 measure. Currently I am using following code.
dt = DecisionTreeClassifier(max_depth=dt_est)
dt_acc = cross_validation.cross_val_score(dt,x_data_tfidf.toarray(), target_arr, cv=cv, scoring='accuracy')
dt_f1 = cross_validation.cross_val_score(dt,x_data_tfidf.toarray(), target_arr, cv=cv,scoring='f1')
dt_pre = cross_validation.cross_val_score(dt,x_data_tfidf.toarray(), target_arr, cv=cv, scoring='precision')
dt_re = cross_validation.cross_val_score(dt,x_data_tfidf.toarray(), target_arr, cv=cv, scoring='recall')
Is there any way using which I can get all (accuracy, precision, recall, f1) in single computation? Currently I have to compute all the metric individually.
Upvotes: 0
Views: 1206
Reputation: 28788
Unfortunately this is not currently possible out of the box, but we are working on it. You can define your own scoring object that computes all of them and prints them / stores them somewhere.
FYI an unfinished PR is here.
Upvotes: 1
Reputation: 46
I am not sure if there is any wrapper function is provided by sklearn but something like this can save you some time.
scores = ['accuracy', 'f1', 'precision', 'recall']
metrics = {score: cross_validation.cross_val_score(dt,x_data_tfidf.toarray(), target_arr, cv=cv,scoring=score) for score in scores}
Upvotes: 1