ValueError: C must be positive (LogisticRegression/SVC)
7 Dec 2025
1 min read
ValueError: C must be positive
$ python -c "from sklearn.linear_model import LogisticRegression; LogisticRegression(C=0).fit([[0,1],[1,0]],[0,1])"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ValueError: C <= 0 is not allowed for this solver.
Why this happens
Cmust be strictly positive.
Fix
- Set
C > 0.
Wrong code
LogisticRegression(C=0).fit(X, y)
Fixed code
LogisticRegression(C=1.0).fit(X, y)