I'm using sklearn Random Forrest to train my model. With the same input features for the model I tried passing the target labels first with label_binarize to create one hot encodings of my target labels and second I tried using label_encoder to encode my target labels. In both cases I'm getting different accuracy score. Is there a specific reason why this is happening, as I'm just using a different method to encode the labels without changing any input features.

  • 1
    $\begingroup$ Ben has answered accurately. You may check your y_pred and can see rows with zero for all classes. Those rows are impacting the accuracy $\endgroup$ – 10xAI May 18 '20 at 11:41

Yes. With y being a 1d array of integers (as after LabelEncoder), sklearn treats it as a multiclass classification problem. With y being a 2d binary array (as after LabelBinarizer), sklearn treats it as a multilabel problem.

Presumably, the multilabel model is predicting no labels for some of the rows. (With your actual data not being multilabel, the sum of probabilities across all classes from the model will probably still be 1, so the model will never predict more than one class. And if always exactly one class gets predicted, the accuracy score for the multiclass and multilabel models should be the same.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.