Kevin M
Kevin M

Reputation: 61

early_stopping set to False, but iteration stops before max_iter in Sklearn MLPClassifier

I work on sklearn MLPClassifier for making neural network model

from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score
clf = MLPClassifier(activation='logistic', learning_rate_init=0.5, early_stopping=False, max_iter=500, random_state=42, hidden_layer_sizes=(10,1)).fit(X_train, y_train)

I set early_stopping to False, and set max_iter to 500. It stops on 41st iteration and gets loss=0.0989939. Why it didn't reach maximum iteration?

Upvotes: 1

Views: 969

Answers (1)

Ben Reiniger
Ben Reiniger

Reputation: 12644

See the descriptions of the parameters tol and n_iter_no_change: if the weights converge sufficiently, then learning will stop early.

That's distinct from the use of early_stopping, which cuts short the learning when a validation score stops improving (generally, worsens because of overfitting). In your case, the model's weights just aren't moving enough to justify further calculations. If you really want to reach 500 iterations, you can set tol=0 or n_iter_no_change=500.

Upvotes: 1

Related Questions