shaare.it

ValueError: C must be positive (LogisticRegression/SVC)

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

  • C must be strictly positive.

Fix

  • Set C > 0.

Wrong code

LogisticRegression(C=0).fit(X, y)

Fixed code

LogisticRegression(C=1.0).fit(X, y)