Home > Enterprise >  Scikit learn metric giving unexpected error
Scikit learn metric giving unexpected error

Time:03-02

I'm fazed by something so simple.

I run the code below:

from sklearn.metrics import precision_score
y_true = [0, 1, 2, 0, 1, 2]
y_pred = [0, 2, 1, 0, 0, 1]
metrics.precision_score(y_true, y_pred, average='macro')

and I get the error

AttributeError: 'list' object has no attribute 'precision_score'

What is wrong with my code?

Scikit-learn==0.23.2

CodePudding user response:

Try :

precision_score(y_true, y_pred, average='macro')

Instead of

metrics.precision_score(y_true, y_pred, average='macro')

Maybe you created a variable metrics some where before this code

  • Related