Facing Valueerror: Target Is Multiclass But Average='binary'
Solution 1:
You need to add the 'average'
param. According to the documentation:
average : string, [None, ‘binary’ (default), ‘micro’, ‘macro’, ‘samples’, ‘weighted’]
This parameter is required for multiclass/multilabel targets. If
None
, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data:
Do this:
print("Precision Score : ",precision_score(y_test, y_pred,
pos_label='positive'
average='micro'))
print("Recall Score : ",recall_score(y_test, y_pred,
pos_label='positive'
average='micro'))
Replace 'micro'
with any one of the above options except 'binary'
. Also, in the multiclass setting, there is no need to provide the 'pos_label'
as it will be anyways ignored.
Update for comment:
Yes, they can be equal. Its given in the user guide here:
Note that for “micro”-averaging in a multiclass setting with all labels included will produce equal precision, recall and F, while “weighted” averaging may produce an F-score that is not between precision and recall.
Post a Comment for "Facing Valueerror: Target Is Multiclass But Average='binary'"