Reputation: 89
I am using sklearn precision and recall to get those scores. I got an error saying value error. Could anyone tell where am I doing wrong?
My y_test is as follows
443 positive
3615 positive
2030 negative
2993 positive
2870 positive
2907 negative
2215 positive
My Prediction is as follows
['positive' 'positive' 'positive' ..., 'positive' 'positive' 'positive']
Code:
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
precision_score(y_test, pred)
Error:
ValueError: pos_label=None is not a valid label: array(['negative', 'positive'],
dtype='<U8')
Upvotes: 2
Views: 3173
Reputation: 36619
Precision is defined as ratio of true positives to total predicted positives.
precision = tp / (tp + fp)
Now in your case, the program dont know which label is to be considered as positive class. So you need to define it yourself. Do this:
precision_score(y_test, pred, pos_label='positive')
Also, the error you shown: pos_label=None is not a valid label
tells that you may have a older version of scikit. Newer versions should throw this error (if pos_label
not specified):
pos_label=1 is not a valid label
So I would advice you to upgrade to latest version
Upvotes: 3