Krishnang K Dalal
Krishnang K Dalal

Reputation: 2566

Precision Score - TypeError: 'list' object is not callable

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

Answers (2)

seralouk
seralouk

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

PV8
PV8

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

Related Questions