@@ -391,8 +391,11 @@ def _initialize(self, y, layer_units, dtype):
391
391
if self .early_stopping :
392
392
self .validation_scores_ = []
393
393
self .best_validation_score_ = - np .inf
394
+ self .best_loss_ = None
394
395
else :
395
396
self .best_loss_ = np .inf
397
+ self .validation_scores_ = None
398
+ self .best_validation_score_ = None
396
399
397
400
def _init_coef (self , fan_in , fan_out , dtype ):
398
401
# Use the initialization method recommended by
@@ -686,6 +689,7 @@ def _fit_stochastic(
686
689
# restore best weights
687
690
self .coefs_ = self ._best_coefs
688
691
self .intercepts_ = self ._best_intercepts
692
+ self .validation_scores_ = np .array (self .validation_scores_ )
689
693
690
694
def _update_no_improvement_count (self , early_stopping , X_val , y_val ):
691
695
if early_stopping :
@@ -919,12 +923,24 @@ class MLPClassifier(ClassifierMixin, BaseMultilayerPerceptron):
919
923
loss_ : float
920
924
The current loss computed with the loss function.
921
925
922
- best_loss_ : float
926
+ best_loss_ : float or None
923
927
The minimum loss reached by the solver throughout fitting.
928
+ If `early_stopping=True`, this attribute is set ot `None`. Refer to
929
+ the fitted attribute `best_validation_score_` instead.
924
930
925
931
loss_curve_ : list of shape (`n_iter_`,)
926
932
The ith element in the list represents the loss at the ith iteration.
927
933
934
+ validation_scores_ : ndarray of shape (n_iter_,) or None
935
+ The score at each iteration on a held-out validation set. The score
936
+ reported is the accuracy score. Only available if `early_stopping=True`,
937
+ otherwise the attribute is set to `None`.
938
+
939
+ best_validation_score_ : float or None
940
+ The best validation score (i.e. accuracy score) that triggered the
941
+ early stopping. Only available if `early_stopping=True`, otherwise the
942
+ attribute is set to `None`.
943
+
928
944
t_ : int
929
945
The number of training samples seen by the solver during fitting.
930
946
@@ -1388,11 +1404,23 @@ class MLPRegressor(RegressorMixin, BaseMultilayerPerceptron):
1388
1404
1389
1405
best_loss_ : float
1390
1406
The minimum loss reached by the solver throughout fitting.
1407
+ If `early_stopping=True`, this attribute is set ot `None`. Refer to
1408
+ the fitted attribute `best_validation_score_` instead.
1391
1409
1392
1410
loss_curve_ : list of shape (`n_iter_`,)
1393
1411
Loss value evaluated at the end of each training step.
1394
1412
The ith element in the list represents the loss at the ith iteration.
1395
1413
1414
+ validation_scores_ : ndarray of shape (n_iter_,) or None
1415
+ The score at each iteration on a held-out validation set. The score
1416
+ reported is the R2 score. Only available if `early_stopping=True`,
1417
+ otherwise the attribute is set to `None`.
1418
+
1419
+ best_validation_score_ : float or None
1420
+ The best validation score (i.e. R2 score) that triggered the
1421
+ early stopping. Only available if `early_stopping=True`, otherwise the
1422
+ attribute is set to `None`.
1423
+
1396
1424
t_ : int
1397
1425
The number of training samples seen by the solver during fitting.
1398
1426
Mathematically equals `n_iters * X.shape[0]`, it means
0 commit comments