Reputation: 2566
I'm getting the following error when using precision_score
from scikit-learn
.
precision_score(y_sm[test_index], prediction)
>>> TypeError: 'list' object is not callable
prediction.shape
>>> (2830,)
y_sm[test_index].shape
>>> (2830,)
What is wrong here? Thanks a lot in advance.
Upvotes: 0
Views: 673
Reputation: 33197
Are you sure that you do not have defined a list
with name precision_score
?
Try:
print(precision_score)
Does it return a list or a function?
Upvotes: 1
Reputation: 6270
You can check your type with:
type(prediction)
probably it will return: list.
Based on the documentation of precision_score:
parameters:
y_true : 1d array-like, or label indicator array / sparse matrix
Ground truth (correct) target values.
y_pred : 1d array-like, or label indicator array / sparse matrix
Estimated targets as returned by a classifier.
You have to use an 1d array-like:
import numpy as np
prediction_a = np.asarray(prediction, dtype=np.float32)
y_sm[test_index]_a = np.asarray(y_sm[test_index], dtype=np.float32)
precision_score(y_sm[test_index]_a, prediction_a)
Upvotes: 1