You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import numpy.random
from sklearn.neural_network import MLPRegressor
if __name__ == '__main__':
x = numpy.random.normal(size=(200, 4))
y = x[:, 0] * 2 + x[:, 1] * 3 + x[:, 3] + numpy.random.normal(size=(200,))
algo = MLPRegressor(early_stopping=True).fit(x, y)
algo.partial_fit(x, y)
Expected Results
If early stopping is not supported for partial fit, it should handle this gracefully. If this is a bug - it should be fixed.
Actual Results
Traceback (most recent call last):
File "/Users/ilyastolyarov/Repos/new/clpu/examples/usecases/script.py", line 12, in <module>
algo.partial_fit(x, y)
File "/Users/ilyastolyarov/Repos/new/clpu/.venv/lib/python3.8/site-packages/sklearn/neural_network/_multilayer_perceptron.py", line 1640, in partial_fit
return self._fit(X, y, incremental=True)
File "/Users/ilyastolyarov/Repos/new/clpu/.venv/lib/python3.8/site-packages/sklearn/neural_network/_multilayer_perceptron.py", line 471, in _fit
self._fit_stochastic(
File "/Users/ilyastolyarov/Repos/new/clpu/.venv/lib/python3.8/site-packages/sklearn/neural_network/_multilayer_perceptron.py", line 653, in _fit_stochastic
self._update_no_improvement_count(early_stopping, X_val, y_val)
File "/Users/ilyastolyarov/Repos/new/clpu/.venv/lib/python3.8/site-packages/sklearn/neural_network/_multilayer_perceptron.py", line 721, in _update_no_improvement_count
if self.loss_curve_[-1] > self.best_loss_ - self.tol:
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
Thank you for opening this issue! I agree we should have a better error message. A code comment states that early_stopping does not work with partial_fit:
Describe the bug
WIth
sklearn = 1.2.1
, when usingearly_stopping = True
,fit
works fine, but partial fit produces the following error:I think this is related to this change: #24683.
Steps/Code to Reproduce
Expected Results
If early stopping is not supported for partial fit, it should handle this gracefully. If this is a bug - it should be fixed.
Actual Results
Versions
The text was updated successfully, but these errors were encountered: