0

I am using sklearn.metrics.classification_report to evaluate the result of my classification.

y_pred = np.argmax(model.predict(X_test), axis=1)
y_true = np.argmax(y_test, axis=1)
print(classification_report(y_true, y_pred, target_names=list(le.classes_)))

And here is my result:

              precision    recall  f1-score   support

 Technology       0.00      0.00      0.00         1
 Travel           0.00      0.00      0.00         5
 Fashion          0.00      0.00      0.00        25
 Entertainment    0.72      1.00      0.84       130
 Art              0.00      0.00      0.00         7
 Politic          0.00      0.00      0.00        12

 avg / total       0.52      0.72      0.61       180

The problem is actually I have 7 labels. The order goes Technology, Travel, Fashion, Entertainment, Art, Politic, Sports. Actually I don't have any Art label in my y_true result but the report lists in order so, it lists Art but skips Sports. It writes the result of Politic for Art and the result of Sports goes to Politic's row.

Why does not it skip the Art? I have no idea how can I solve this.

beginner
  • 229
  • 1
  • 4
  • 11

1 Answers1

2

The index labels in the classification report are the values of the argument "target_names". Please make sure, you are giving the right values to that argument.

According to your required output, you should have target_names = ["Technology", "Travel", "Fashion", "Entertainment", "Politic", "Sports"]

I would suggest, please check the output of your "le.classes_" and I am not sure which transformer 'le' refers to.

  • I have checked before. le.classes I defined in label encoder which are my labels. {list(le.classes_)} [u'Technology', u'Travel', u'Fashion', u'Entertainment', u'Art', u'Politic', u'Sports'] – beginner May 03 '18 at 15:01
  • For example, If I increase the size of validation data and if it includes all labels then the classification table show the result correctly. – beginner May 03 '18 at 15:06