ValueError: Target is multiclass but average='binary' error for binary data

225 Views Asked by At

I encountered an issue when using the recall_score() function from scikit-learn in a binary classification scenario. Despite having binary target data (y_test containing only 0s and 1s), I received the following error message:

ValueError: Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].

The error occurs specifically on the line of code:

recall_ANOVA = recall_score(y_test, np.round(best_model_name_ANOVA.predict(X_test[selected_features_ANOVA]), 0))

My scikit version is 1.1.3

type_of_target(y_test) does return 'binary'

I have verified that y_test is indeed binary, and this issue only appears when a certain number of features is set beforehand in my code. I suspect it might be a bug or unexpected behavior.

Why does this error occur in a binary classification scenario and how to resolve it? Is this possibly a bug in scikit-learn, or am I missing something in my code?

0

There are 0 best solutions below