Sklearn metrics for multiclass classification

I performed the GaussianNB classification using sklearn. I tried to calculate the metrics using the following code:

print accuracy_score(y_test, y_pred) print precision_score(y_test, y_pred) 

The accuracy assessment works correctly, but the calculation of the accuracy of the calculations shows an error as:

ValueError: Target are multi-classes, but average = 'binary'. Choose a different middle setting.

The multiclass is used as the goal, can I have metric estimates of accuracy, recall, etc.?

+7
scikit-learn precision-recall machine-learning
source share
1 answer

The function call precision_score(y_test, y_pred) equivalent to precision_score(y_test, y_pred, pos_label=1, average='binary') . The documentation ( http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html ) tells us:

'binary':

Show only results for the class specified by pos_label. This only applies if the targets (y_ {true, pred}) are binary.

So the problem is that your labels are not binary, but probably disposable. Fortunately, there are other options that should work with your data:

precision_score(y_test, y_pred, average=None) will return accuracy metrics for each class, and

precision_score(y_test, y_pred, average='micro') will return the general ratio tp / (tp + fp)

The pos_label argument will be ignored if you select a different average parameter than binary .

+11
source share

All Articles