ValueError: Classification metrics can't handle a mix of binary and continuous targets
You passed probabilities or regression outputs into a metric that expects class labels. Threshold or argmax the predictions first — or switch to a metric that wants scores.
Updated
The error
ValueError: Classification metrics can't handle a mix of binary and continuous targets
Variants swap the two type words: multiclass and continuous, binary and continuous-multioutput.
What it means
A metric like accuracy_score compares two lists of class labels: truth versus prediction, both discrete. One of the lists you passed contains continuous numbers — probabilities like 0.73, or regression outputs like 12.4. The metric names both types it saw; the second one is usually the intruder.
Why it happens
Three common routes:
- You called
model.predict_proba(X)and fed the probabilities toaccuracy_score. Probabilities are not labels yet. - You trained a regressor on a yes/no problem, so even
.predictreturns continuous values. - With neural networks, the model outputs one probability (or several logits) per class and you skipped the conversion to a label.
How to fix it
1. Use .predict when the metric wants labels.
from sklearn.metrics import accuracy_score
preds = model.predict(X_test) # labels, not probabilities
print(accuracy_score(y_test, preds))2. Converting probabilities yourself? Threshold or argmax.
proba = model.predict_proba(X_test)
preds = (proba[:, 1] >= 0.5).astype(int) # binary: threshold column 1import numpy as np
preds = np.argmax(proba, axis=1) # multiclass: highest-probability class3. Some metrics want the scores — do not convert for those. roc_auc_score and log_loss measure ranking and calibration; give them probabilities:
from sklearn.metrics import roc_auc_score
print(roc_auc_score(y_test, proba[:, 1]))The rule: accuracy, precision, recall, F1, confusion matrix take labels; ROC-AUC and log loss take scores.
4. If a regressor is answering a classification question, change the model. Use a classifier and this whole ambiguity disappears — see the related error below for that trap.
How to prevent it
Print the first five values of whatever you pass to a metric. Labels look like [0, 1, 1, 0, 2]; scores look like [0.73, 0.11, ...]. Match each metric to its input type on purpose, and keep the conversion (threshold or argmax) as one explicit, visible line.