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 .
ml4294
source share