shaare.it

ValueError: 'tol' must be positive

ValueError: tol non-positive

$ python -c "from sklearn.linear_model import SGDClassifier; SGDClassifier(tol=0).fit([[0],[1]],[0,1])"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: tol must be > 0

Why this happens

Tolerance thresholds must be positive.

Fix

Provide a small positive number like 1e-3.

Wrong code

from sklearn.linear_model import SGDClassifier
SGDClassifier(tol=0)

Fixed code

from sklearn.linear_model import SGDClassifier
SGDClassifier(tol=1e-3)