@@ -348,6 +348,8 @@ def _fit(self, X, y, incremental=False):
348
348
# l-bfgs does not support mini-batches
349
349
if self .algorithm == 'l-bfgs' :
350
350
batch_size = n_samples
351
+ elif self .batch_size == 'auto' :
352
+ batch_size = min (200 , n_samples )
351
353
else :
352
354
if self .batch_size < 1 or self .batch_size > n_samples :
353
355
warnings .warn ("Got `batch_size` less than 1 or larger than "
@@ -493,7 +495,11 @@ def _fit_stochastic(self, X, y, activations, deltas, coef_grads,
493
495
y_val = None
494
496
495
497
n_samples = X .shape [0 ]
496
- batch_size = np .clip (self .batch_size , 1 , n_samples )
498
+
499
+ if self .batch_size == 'auto' :
500
+ batch_size = min (200 , n_samples )
501
+ else :
502
+ batch_size = np .clip (self .batch_size , 1 , n_samples )
497
503
498
504
try :
499
505
for it in range (self .max_iter ):
@@ -714,9 +720,10 @@ class MLPClassifier(BaseMultilayerPerceptron, ClassifierMixin):
714
720
alpha : float, optional, default 0.0001
715
721
L2 penalty (regularization term) parameter.
716
722
717
- batch_size : int, optional, default 200
723
+ batch_size : int, optional, default 'auto'
718
724
Size of minibatches for stochastic optimizers.
719
725
If the algorithm is 'l-bfgs', the classifier will not use minibatch.
726
+ When set to "auto", `batch_size=min(200, n_samples)`
720
727
721
728
learning_rate : {'constant', 'invscaling', 'adaptive'}, default 'constant'
722
729
Learning rate schedule for weight updates.
@@ -864,7 +871,7 @@ class MLPClassifier(BaseMultilayerPerceptron, ClassifierMixin):
864
871
"""
865
872
def __init__ (self , hidden_layer_sizes = (100 ,), activation = "relu" ,
866
873
algorithm = 'adam' , alpha = 0.0001 ,
867
- batch_size = 200 , learning_rate = "constant" ,
874
+ batch_size = 'auto' , learning_rate = "constant" ,
868
875
learning_rate_init = 0.001 , power_t = 0.5 , max_iter = 200 ,
869
876
shuffle = True , random_state = None , tol = 1e-4 ,
870
877
verbose = False , warm_start = False , momentum = 0.9 ,
@@ -1067,9 +1074,10 @@ class MLPRegressor(BaseMultilayerPerceptron, RegressorMixin):
1067
1074
alpha : float, optional, default 0.0001
1068
1075
L2 penalty (regularization term) parameter.
1069
1076
1070
- batch_size : int, optional, default 200
1077
+ batch_size : int, optional, default 'auto'
1071
1078
Size of minibatches for stochastic optimizers.
1072
1079
If the algorithm is 'l-bfgs', the classifier will not use minibatch.
1080
+ When set to "auto", `batch_size=min(200, n_samples)`
1073
1081
1074
1082
learning_rate : {'constant', 'invscaling', 'adaptive'}, default 'constant'
1075
1083
Learning rate schedule for weight updates.
@@ -1211,7 +1219,7 @@ class MLPRegressor(BaseMultilayerPerceptron, RegressorMixin):
1211
1219
"""
1212
1220
def __init__ (self , hidden_layer_sizes = (100 ,), activation = "relu" ,
1213
1221
algorithm = 'adam' , alpha = 0.0001 ,
1214
- batch_size = 200 , learning_rate = "constant" ,
1222
+ batch_size = 'auto' , learning_rate = "constant" ,
1215
1223
learning_rate_init = 0.001 ,
1216
1224
power_t = 0.5 , max_iter = 200 , shuffle = True ,
1217
1225
random_state = None , tol = 1e-4 ,
0 commit comments