sklearn metrics for multiclass classification

The function call precision_score(y_test, y_pred) is 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’:

Only report results for the class specified by pos_label. This is applicable only if targets (y_{true,pred}) are binary.

So the problem is that your labels are not binary, but probably one-hot encoded. Fortunately, there are other options which should work with your data:

precision_score(y_test, y_pred, average=None) will return the precision scores for each class, while

precision_score(y_test, y_pred, average="micro") will return the total ratio
of tp/(tp + fp)

The pos_label argument will be ignored if you choose another average option than binary.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)