ValueError: Unknown label type: continuous in scikit-learn (tested)
ValueError: Unknown label type: continuous means you called fit on a classifier (often LogisticRegression) with a float target. Use a regressor if you are predicting a number, or bin the target into classes. Unknown label type: unknown is an object-dtype y; fix it with astype(int). Tested on scikit-learn 1.9.1.
1. The error
import numpy as np
from sklearn.linear_model import LogisticRegression
rng = np.random.default_rng(0)
X = rng.normal(size=(100, 3))
y = X @ [1.5, -2.0, 0.5] + rng.normal(size=100) # a continuous target
LogisticRegression().fit(X, y)
Output:
Traceback (most recent call last):
File "/w/c1.py", line 7, in <module>
LogisticRegression().fit(X, y)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/usr/local/lib/python3.15/site-packages/sklearn/base.py", line 1403, in wrapper
return fit_method(estimator, *args, **kwargs)
File "/usr/local/lib/python3.15/site-packages/sklearn/linear_model/_logistic.py", line 1447, in fit
check_classification_targets(y)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/usr/local/lib/python3.15/site-packages/sklearn/utils/multiclass.py", line 230, in check_classification_targets
raise ValueError(
...<3 lines>...
)
ValueError: Unknown label type: continuous. Maybe you are trying to fit a classifier, which expects discrete classes on a regression target with continuous values.
LogisticRegression, RandomForestClassifier, SVC and every other classifier call check_classification_targets(y) in fit. A float target with fractional values is continuous, so the fit stops with Unknown label type: continuous.
2. Fix: use a regressor, or turn the target into classes
import numpy as np
from sklearn.linear_model import LinearRegression, LogisticRegression
rng = np.random.default_rng(0)
X = rng.normal(size=(100, 3))
y = X @ [1.5, -2.0, 0.5] + rng.normal(size=100)
# It really is a number to predict: use a regressor
print("R2:", round(LinearRegression().fit(X, y).score(X, y), 4))
# It should be classes: bin it first
y_cls = np.digitize(y, bins=[-1, 1]) # 0 = low, 1 = mid, 2 = high
clf = LogisticRegression().fit(X, y_cls)
print("classes:", clf.classes_, "accuracy:", round(clf.score(X, y_cls), 4))
Output:
R2: 0.8967
classes: [0 1 2] accuracy: 0.83
If you want to predict the number itself, swap the classifier for its regressor (LinearRegression, RandomForestRegressor, SVR). Note that LogisticRegression is a classifier despite its name. If you really want classes, bin the target first with np.digitize or pd.cut.
3. Unknown label type: unknown (object dtype)
import numpy as np
from sklearn.linear_model import LogisticRegression
X = np.array([[0.0], [1.0], [2.0], [3.0]])
for y in (np.array([0.0, 0.0, 1.0, 1.0]), # float labels, whole numbers
np.array([0, 0, 1, 1], dtype=object), # ints in an object array
np.array(["0", "0", "1", "1"])): # strings
try:
print(y.dtype, "->", LogisticRegression().fit(X, y).classes_)
except ValueError as e:
print(y.dtype, "->", type(e).__name__ + ":", e)
Output:
float64 -> [0. 1.]
object -> ValueError: Unknown label type: unknown. Maybe you are trying to fit a classifier, which expects discrete classes on a regression target with continuous values.
<U1 -> ['0' '1']
Float labels that are whole numbers (0.0, 1.0) are accepted, and so are strings. An object-dtype array of ints is not: that gives Unknown label type: unknown. This often happens when y comes from a pandas column that once held mixed values or None.
import numpy as np
from sklearn.linear_model import LogisticRegression
X = np.array([[0.0], [1.0], [2.0], [3.0]])
y = np.array([0, 0, 1, 1], dtype=object)
print(LogisticRegression().fit(X, y.astype(int)).classes_)
Output:
[0 1]
Convert it with y.astype(int) (or df["label"].astype(int)) before fitting.
4. Related errors from splitting a continuous target
import numpy as np
from sklearn.model_selection import StratifiedKFold
rng = np.random.default_rng(0)
X = rng.normal(size=(100, 3))
y = X @ [1.5, -2.0, 0.5] + rng.normal(size=100)
next(StratifiedKFold(n_splits=5).split(X, y))
Output:
Traceback (most recent call last):
File "/w/c6.py", line 7, in <module>
next(StratifiedKFold(n_splits=5).split(X, y))
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.15/site-packages/sklearn/model_selection/_split.py", line 411, in split
for train, test in super().split(X, y, groups):
~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/usr/local/lib/python3.15/site-packages/sklearn/model_selection/_split.py", line 142, in split
for test_index in self._iter_test_masks(X, y, groups):
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/usr/local/lib/python3.15/site-packages/sklearn/model_selection/_split.py", line 845, in _iter_test_masks
test_folds = self._make_test_folds(X, y)
File "/usr/local/lib/python3.15/site-packages/sklearn/model_selection/_split.py", line 788, in _make_test_folds
raise ValueError(
...<3 lines>...
)
ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead.
StratifiedKFold refuses continuous targets.
import numpy as np
from sklearn.model_selection import train_test_split
rng = np.random.default_rng(0)
X = rng.normal(size=(100, 3))
y = X @ [1.5, -2.0, 0.5] + rng.normal(size=100)
try:
train_test_split(X, y, stratify=y, random_state=0)
except ValueError as e:
print("ValueError:", str(e)[:200], "...")
# Stratify on bins of y instead (quartiles), keep y itself continuous
bins = np.digitize(y, np.quantile(y, [0.25, 0.5, 0.75]))
X_tr, X_te, y_tr, y_te = train_test_split(X, y, stratify=bins, random_state=0)
print("train/test sizes:", len(y_tr), len(y_te))
Output:
ValueError: The least populated classes in y have only 1 member, which is too few. The minimum number of groups for any class cannot be less than 2. Classes with too few members are: [-7.264813983203227, -6.70659 ...
train/test sizes: 75 25
train_test_split(..., stratify=y) treats every distinct float as its own class, so each has one member and it fails. To keep the target continuous but split evenly, stratify on quartile bins of y as shown.
Related: ValueError: continuous is not supported (metrics) ยท lbfgs failed to converge.
Frequently asked questions
How do I fix 'Unknown label type: continuous'?
Use a regressor (LinearRegression, RandomForestRegressor) for a numeric target, or bin y into classes with np.digitize or pd.cut before fitting a classifier.
Why does LogisticRegression give Unknown label type: continuous?
LogisticRegression is a classifier. It needs discrete labels; a float target with fractional values is 'continuous'.
What does 'Unknown label type: unknown' mean?
y is an object-dtype array (for example ints stored as Python objects). Convert it with y.astype(int).
Written with AI assistance. Measured on 2026-10-23 in Docker: python:3-slim (Python 3.15.1) with scikit-learn 1.9.1. Each block was run verbatim and the output pasted unedited. PlainTables is our extension; Python and scikit-learn are free.