Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Machine Learning by (19k points)

I have performed GaussianNB classification using a sklearn. I tried to calculate the metrics using the following code:

print accuracy_score(y_test, y_pred)

print precision_score(y_test, y_pred)

Accuracy score is working correctly but the precision score calculation is showing error as:

ValueError: Target is multiclass but average='binary'. Please choose another average setting.

As the target is multiclass, can I have the metric scores of precision, recall, etc.?

1 Answer

0 votes
by (33.1k points)

In your code, notice that the 

precision_score(y_test, y_pred) 

is equivalent to 

precision_score(y_test, y_pred, pos_label=1, average='binary'). 

'binary':

There report results for the class are specified by pos_label. This is applicable only if targets (y_{true,pred}) are binary.

Here labels are not binary, but probably one-hot encoded. There are other options which should work with your data:

For example:

precision_score(y_test, y_pred, average=None) 

will return the precision scores for each class, while

precision_score(y_test, y_pred, average='micro') 

will return the total ratio of tp/(tp + fp)

The pos_label argument will be ignored if you choose another average option than binary.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...