ValueError: Solver not supported for given penalty (LogisticRegression)
7 Dec 2025
1 min read
ValueError: logistic solver vs penalty
$ python -c "from sklearn.linear_model import LogisticRegression; LogisticRegression(penalty='l1', solver='lbfgs').fit([[0,1],[1,0],[1,1]],[0,1,0])"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ValueError: Solver lbfgs supports only 'l2' or 'none' penalties.
Why this happens
- Using a solver that doesn’t support the chosen penalty.
Fix
- Use compatible pairs, e.g.,
penalty='l1'withsolver='liblinear'orsaga.
Wrong code
LogisticRegression(penalty='l1', solver='lbfgs').fit(X, y)
Fixed code
LogisticRegression(penalty='l1', solver='liblinear').fit(X, y)