-2

So i have a Classification Report and i am currently making it display the overall Accuracy to two decimal places. I would like to change it to display Precision instead. However, is that even possible since it is technically displaying other Metrics including Precision already?

Current Code

print(classification_report(y_train, y_pred, target_names = target_names))
print('Accuracy {:.2f}'.format(accuracy_score(y_train, y_pred)))

I would like it to then become

print(classification_report(y_train, y_pred, target_names = target_names))
print('Accuracy {:.2f}'.format(precision_score(y_train, y_pred)))

When i try this i get errors. I already tried consulting the documentation on Sklearn, but i could not find anything. Any help will be greatly appreciated.

Thanks.

  • what is the error that you are getting? btw `classification_report` itself has the precision values. – Venkatachalam Jun 01 '20 at 07:43
  • It states 'NameError: name 'Precision_score' is not defined'. I was told by someone it is possible to switch it from Accuracy to Precision, but i cannot find info stating how. I just want to know if i can actually change the .format() to Precision from Accuracy. – JustAnotherCoder Jun 01 '20 at 23:47
  • have you imported `precision_score` from `sklearn.metrics`? – Venkatachalam Jun 02 '20 at 05:01
  • No. I will try it later today and see how it goes. – JustAnotherCoder Jun 03 '20 at 00:41
  • So i imported it and i trued to use it but i get this error 'ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].' So i guess i need to get the resolved and it should work. – JustAnotherCoder Jun 04 '20 at 01:01
  • Yep i got it working. Thank you for the help. – JustAnotherCoder Jun 04 '20 at 01:04

1 Answers1

-1

The resolution was to declare the following import

from sklearn.metrics import classification_report, accuracy_score, precision_score

And then write this beneath my Classification Report and specify what type of result i wanted after reading this post:

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

print('TEXT: {:.2f}'.format(precision_score(y_train, y_pred, average='weighted')))