<s> """<STR_LIT>""" <EOL> import sys <EOL> import warnings <EOL> import numpy as np <EOL> from numpy . testing import assert_almost_equal , assert_array_equal <EOL> from sklearn . datasets import load_digits , load_boston <EOL> from sklearn . datasets import make_regression , make_multilabel_classification <EOL> from sklearn . externals . six . moves import cStringIO as StringIO <EOL> from sklearn . metrics import roc_auc_score <EOL> from sklearn . neural_network import MLPClassifier <EOL> from sklearn . neural_network import MLPRegressor <EOL> from sklearn . preprocessing import LabelBinarizer <EOL> from sklearn . preprocessing import StandardScaler , MinMaxScaler <EOL> from scipy . sparse import csr_matrix <EOL> from sklearn . utils . testing import ( assert_raises , assert_greater , assert_equal , <EOL> assert_false ) <EOL> np . seterr ( all = '<STR_LIT>' ) <EOL> ACTIVATION_TYPES = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:relu>" ] <EOL> digits_dataset_multi = load_digits ( n_class = <NUM_LIT:3> ) <EOL> X_digits_multi = MinMaxScaler ( ) . fit_transform ( digits_dataset_multi . data [ : <NUM_LIT:200> ] ) <EOL> y_digits_multi = digits_dataset_multi . target [ : <NUM_LIT:200> ] <EOL> digits_dataset_binary = load_digits ( n_class = <NUM_LIT:2> ) <EOL> X_digits_binary = MinMaxScaler ( ) . fit_transform ( <EOL> digits_dataset_binary . data [ : <NUM_LIT:200> ] ) <EOL> y_digits_binary = digits_dataset_binary . target [ : <NUM_LIT:200> ] <EOL> classification_datasets = [ ( X_digits_multi , y_digits_multi ) , <EOL> ( X_digits_binary , y_digits_binary ) ] <EOL> boston = load_boston ( ) <EOL> Xboston = StandardScaler ( ) . fit_transform ( boston . data ) [ : <NUM_LIT:200> ] <EOL> yboston = boston . target [ : <NUM_LIT:200> ] <EOL> def test_alpha ( ) : <EOL> X = X_digits_binary [ : <NUM_LIT:100> ] <EOL> y = y_digits_binary [ : <NUM_LIT:100> ] <EOL> alpha_vectors = [ ] <EOL> alpha_values = np . arange ( <NUM_LIT:2> ) <EOL> absolute_sum = lambda x : np . sum ( np . abs ( x ) ) <EOL> for alpha in alpha_values : <EOL> mlp = MLPClassifier ( hidden_layer_sizes = <NUM_LIT:10> , alpha = alpha , random_state = <NUM_LIT:1> ) <EOL> mlp . fit ( X , y ) <EOL> alpha_vectors . append ( np . array ( [ absolute_sum ( mlp . coefs_ [ <NUM_LIT:0> ] ) , <EOL> absolute_sum ( mlp . coefs_ [ <NUM_LIT:1> ] ) ] ) ) <EOL> for i in range ( len ( alpha_values ) - <NUM_LIT:1> ) : <EOL> assert ( alpha_vectors [ i ] > alpha_vectors [ i + <NUM_LIT:1> ] ) . all ( ) <EOL> def test_fit ( ) : <EOL> X = np . array ( [ [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> y = np . array ( [ <NUM_LIT:0> ] ) <EOL> mlp = MLPClassifier ( algorithm = '<STR_LIT>' , learning_rate_init = <NUM_LIT:0.1> , alpha = <NUM_LIT:0.1> , <EOL> activation = '<STR_LIT>' , random_state = <NUM_LIT:1> , max_iter = <NUM_LIT:1> , <EOL> hidden_layer_sizes = <NUM_LIT:2> , momentum = <NUM_LIT:0> ) <EOL> mlp . coefs_ = [ <NUM_LIT:0> ] * <NUM_LIT:2> <EOL> mlp . intercepts_ = [ <NUM_LIT:0> ] * <NUM_LIT:2> <EOL> mlp . classes_ = [ <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> mlp . n_outputs_ = <NUM_LIT:1> <EOL> mlp . coefs_ [ <NUM_LIT:0> ] = np . array ( [ [ <NUM_LIT:0.1> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT:0.1> ] , [ <NUM_LIT:0.5> , <NUM_LIT:0> ] ] ) <EOL> mlp . coefs_ [ <NUM_LIT:1> ] = np . array ( [ [ <NUM_LIT:0.1> ] , [ <NUM_LIT> ] ] ) <EOL> mlp . intercepts_ [ <NUM_LIT:0> ] = np . array ( [ <NUM_LIT:0.1> , <NUM_LIT:0.1> ] ) <EOL> mlp . intercepts_ [ <NUM_LIT:1> ] = np . array ( [ <NUM_LIT:1.0> ] ) <EOL> mlp . _coef_grads = [ ] * <NUM_LIT:2> <EOL> mlp . _intercept_grads = [ ] * <NUM_LIT:2> <EOL> mlp . label_binarizer_ . y_type_ = '<STR_LIT>' <EOL> mlp . n_iter_ = <NUM_LIT:0> <EOL> mlp . learning_rate_ = <NUM_LIT:0.1> <EOL> mlp . n_layers_ = <NUM_LIT:3> <EOL> mlp . _coef_grads = [ <NUM_LIT:0> ] * ( mlp . n_layers_ - <NUM_LIT:1> ) <EOL> mlp . _intercept_grads = [ <NUM_LIT:0> ] * ( mlp . n_layers_ - <NUM_LIT:1> ) <EOL> mlp . out_activation_ = '<STR_LIT>' <EOL> mlp . t_ = <NUM_LIT:0> <EOL> mlp . best_loss_ = np . inf <EOL> mlp . loss_curve_ = [ ] <EOL> mlp . _no_improvement_count = <NUM_LIT:0> <EOL> mlp . _intercept_velocity = [ np . zeros_like ( intercepts ) for <EOL> intercepts in <EOL> mlp . intercepts_ ] <EOL> mlp . _coef_velocity = [ np . zeros_like ( coefs ) for coefs in <EOL> mlp . coefs_ ] <EOL> mlp . partial_fit ( X , y , classes = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> assert_almost_equal ( mlp . coefs_ [ <NUM_LIT:0> ] , np . array ( [ [ <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , - <NUM_LIT> ] ] ) , <EOL> decimal = <NUM_LIT:3> ) <EOL> assert_almost_equal ( mlp . coefs_ [ <NUM_LIT:1> ] , np . array ( [ [ <NUM_LIT> ] , [ <NUM_LIT> ] ] ) , <EOL> decimal = <NUM_LIT:3> ) <EOL> assert_almost_equal ( mlp . intercepts_ [ <NUM_LIT:0> ] , <EOL> np . array ( [ <NUM_LIT> , <NUM_LIT> ] ) , decimal = <NUM_LIT:3> ) <EOL> assert_almost_equal ( mlp . intercepts_ [ <NUM_LIT:1> ] , np . array ( <NUM_LIT> ) , decimal = <NUM_LIT:3> ) <EOL> assert_almost_equal ( mlp . decision_function ( X ) , <NUM_LIT> , decimal = <NUM_LIT:3> ) <EOL> def test_gradient ( ) : <EOL> for n_labels in [ <NUM_LIT:2> , <NUM_LIT:3> ] : <EOL> n_samples = <NUM_LIT:5> <EOL> n_features = <NUM_LIT:10> <EOL> X = np . random . random ( ( n_samples , n_features ) ) <EOL> y = <NUM_LIT:1> + np . mod ( np . arange ( n_samples ) + <NUM_LIT:1> , n_labels ) <EOL> Y = LabelBinarizer ( ) . fit_transform ( y ) <EOL> for activation in ACTIVATION_TYPES : <EOL> mlp = MLPClassifier ( activation = activation , hidden_layer_sizes = <NUM_LIT:10> , <EOL> algorithm = '<STR_LIT>' , alpha = <NUM_LIT> , <EOL> learning_rate_init = <NUM_LIT> , max_iter = <NUM_LIT:1> , <EOL> random_state = <NUM_LIT:1> ) <EOL> mlp . fit ( X , y ) <EOL> theta = np . hstack ( [ l . ravel ( ) for l in mlp . coefs_ + <EOL> mlp . intercepts_ ] ) <EOL> layer_units = ( [ X . shape [ <NUM_LIT:1> ] ] + [ mlp . hidden_layer_sizes ] + <EOL> [ mlp . n_outputs_ ] ) <EOL> activations = [ ] <EOL> deltas = [ ] <EOL> coef_grads = [ ] <EOL> intercept_grads = [ ] <EOL> activations . append ( X ) <EOL> for i in range ( mlp . n_layers_ - <NUM_LIT:1> ) : <EOL> activations . append ( np . empty ( ( X . shape [ <NUM_LIT:0> ] , <EOL> layer_units [ i + <NUM_LIT:1> ] ) ) ) <EOL> deltas . append ( np . empty ( ( X . shape [ <NUM_LIT:0> ] , <EOL> layer_units [ i + <NUM_LIT:1> ] ) ) ) <EOL> fan_in = layer_units [ i ] <EOL> fan_out = layer_units [ i + <NUM_LIT:1> ] <EOL> coef_grads . append ( np . empty ( ( fan_in , fan_out ) ) ) <EOL> intercept_grads . append ( np . empty ( fan_out ) ) <EOL> def loss_grad_fun ( t ) : <EOL> return mlp . _loss_grad_lbfgs ( t , X , Y , activations , deltas , <EOL> coef_grads , intercept_grads ) <EOL> [ value , grad ] = loss_grad_fun ( theta ) <EOL> numgrad = np . zeros ( np . size ( theta ) ) <EOL> n = np . size ( theta , <NUM_LIT:0> ) <EOL> E = np . eye ( n ) <EOL> epsilon = <NUM_LIT> <EOL> for i in range ( n ) : <EOL> dtheta = E [ : , i ] * epsilon <EOL> numgrad [ i ] = ( ( loss_grad_fun ( theta + dtheta ) [ <NUM_LIT:0> ] - <EOL> loss_grad_fun ( theta - dtheta ) [ <NUM_LIT:0> ] ) / <EOL> ( epsilon * <NUM_LIT> ) ) <EOL> assert_almost_equal ( numgrad , grad ) <EOL> def test_lbfgs_classification ( ) : <EOL> for X , y in classification_datasets : <EOL> X_train = X [ : <NUM_LIT> ] <EOL> y_train = y [ : <NUM_LIT> ] <EOL> X_test = X [ <NUM_LIT> : ] <EOL> expected_shape_dtype = ( X_test . shape [ <NUM_LIT:0> ] , y_train . dtype . kind ) <EOL> for activation in ACTIVATION_TYPES : <EOL> mlp = MLPClassifier ( algorithm = '<STR_LIT>' , hidden_layer_sizes = <NUM_LIT:50> , <EOL> max_iter = <NUM_LIT> , shuffle = True , random_state = <NUM_LIT:1> , <EOL> activation = activation ) <EOL> mlp . fit ( X_train , y_train ) <EOL> y_predict = mlp . predict ( X_test ) <EOL> assert_greater ( mlp . score ( X_train , y_train ) , <NUM_LIT> ) <EOL> assert_equal ( ( y_predict . shape [ <NUM_LIT:0> ] , y_predict . dtype . kind ) , <EOL> expected_shape_dtype ) <EOL> def test_lbfgs_regression ( ) : <EOL> X = Xboston <EOL> y = yboston <EOL> for activation in ACTIVATION_TYPES : <EOL> mlp = MLPRegressor ( algorithm = '<STR_LIT>' , hidden_layer_sizes = <NUM_LIT:50> , <EOL> max_iter = <NUM_LIT> , shuffle = True , random_state = <NUM_LIT:1> , <EOL> activation = activation ) <EOL> mlp . fit ( X , y ) <EOL> assert_greater ( mlp . score ( X , y ) , <NUM_LIT> ) <EOL> def test_learning_rate_warmstart ( ) : <EOL> X = [ [ <NUM_LIT:3> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:6> ] , [ <NUM_LIT:5> , <NUM_LIT:6> ] , [ - <NUM_LIT:2> , - <NUM_LIT:4> ] ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> for learning_rate in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> mlp = MLPClassifier ( algorithm = '<STR_LIT>' , hidden_layer_sizes = <NUM_LIT:4> , <EOL> learning_rate = learning_rate , max_iter = <NUM_LIT:1> , <EOL> power_t = <NUM_LIT> , warm_start = True ) <EOL> mlp . fit ( X , y ) <EOL> prev_eta = mlp . _optimizer . learning_rate <EOL> mlp . fit ( X , y ) <EOL> post_eta = mlp . _optimizer . learning_rate <EOL> if learning_rate == '<STR_LIT>' : <EOL> assert_equal ( prev_eta , post_eta ) <EOL> elif learning_rate == '<STR_LIT>' : <EOL> assert_equal ( mlp . learning_rate_init / pow ( <NUM_LIT:8> + <NUM_LIT:1> , mlp . power_t ) , <EOL> post_eta ) <EOL> def test_multilabel_classification ( ) : <EOL> X , y = make_multilabel_classification ( n_samples = <NUM_LIT:50> , random_state = <NUM_LIT:0> , <EOL> return_indicator = True ) <EOL> mlp = MLPClassifier ( algorithm = '<STR_LIT>' , hidden_layer_sizes = <NUM_LIT:50> , alpha = <NUM_LIT> , <EOL> max_iter = <NUM_LIT> , random_state = <NUM_LIT:0> , activation = '<STR_LIT>' , <EOL> learning_rate_init = <NUM_LIT> ) <EOL> mlp . fit ( X , y ) <EOL> assert_equal ( mlp . score ( X , y ) , <NUM_LIT:1> ) <EOL> mlp = MLPClassifier ( algorithm = '<STR_LIT>' , hidden_layer_sizes = <NUM_LIT:50> , max_iter = <NUM_LIT> , <EOL> random_state = <NUM_LIT:0> , activation = '<STR_LIT>' , alpha = <NUM_LIT> , <EOL> learning_rate_init = <NUM_LIT> ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> mlp . partial_fit ( X , y , classes = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> assert_greater ( mlp . score ( X , y ) , <NUM_LIT> ) <EOL> def test_multioutput_regression ( ) : <EOL> X , y = make_regression ( n_samples = <NUM_LIT:200> , n_targets = <NUM_LIT:5> ) <EOL> mlp = MLPRegressor ( algorithm = '<STR_LIT>' , hidden_layer_sizes = <NUM_LIT:50> , max_iter = <NUM_LIT:200> , <EOL> random_state = <NUM_LIT:1> ) <EOL> mlp . fit ( X , y ) <EOL> assert_greater ( mlp . score ( X , y ) , <NUM_LIT> ) <EOL> def test_partial_fit_classes_error ( ) : <EOL> X = [ [ <NUM_LIT:3> , <NUM_LIT:2> ] ] <EOL> y = [ <NUM_LIT:0> ] <EOL> clf = MLPClassifier ( algorithm = '<STR_LIT>' ) <EOL> clf . partial_fit ( X , y , classes = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> assert_raises ( ValueError , clf . partial_fit , X , y , classes = [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> def test_partial_fit_classification ( ) : <EOL> for X , y in classification_datasets : <EOL> X = X <EOL> y = y <EOL> mlp = MLPClassifier ( algorithm = '<STR_LIT>' , max_iter = <NUM_LIT:100> , random_state = <NUM_LIT:1> , <EOL> tol = <NUM_LIT:0> , alpha = <NUM_LIT> , learning_rate_init = <NUM_LIT> ) <EOL> mlp . fit ( X , y ) <EOL> pred1 = mlp . predict ( X ) <EOL> mlp = MLPClassifier ( algorithm = '<STR_LIT>' , random_state = <NUM_LIT:1> , alpha = <NUM_LIT> , <EOL> learning_rate_init = <NUM_LIT> ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> mlp . partial_fit ( X , y , classes = np . unique ( y ) ) <EOL> pred2 = mlp . predict ( X ) <EOL> assert_array_equal ( pred1 , pred2 ) <EOL> assert_greater ( mlp . score ( X , y ) , <NUM_LIT> ) <EOL> def test_partial_fit_regression ( ) : <EOL> X = Xboston <EOL> y = yboston <EOL> for momentum in [ <NUM_LIT:0> , <NUM_LIT> ] : <EOL> mlp = MLPRegressor ( algorithm = '<STR_LIT>' , max_iter = <NUM_LIT:100> , activation = '<STR_LIT:relu>' , <EOL> random_state = <NUM_LIT:1> , learning_rate_init = <NUM_LIT> , <EOL> batch_size = X . shape [ <NUM_LIT:0> ] , momentum = momentum ) <EOL> with warnings . catch_warnings ( record = True ) : <EOL> mlp . fit ( X , y ) <EOL> pred1 = mlp . predict ( X ) <EOL> mlp = MLPRegressor ( algorithm = '<STR_LIT>' , activation = '<STR_LIT:relu>' , <EOL> learning_rate_init = <NUM_LIT> , random_state = <NUM_LIT:1> , <EOL> batch_size = X . shape [ <NUM_LIT:0> ] , momentum = momentum ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> mlp . partial_fit ( X , y ) <EOL> pred2 = mlp . predict ( X ) <EOL> assert_almost_equal ( pred1 , pred2 , decimal = <NUM_LIT:2> ) <EOL> score = mlp . score ( X , y ) <EOL> assert_greater ( score , <NUM_LIT> ) <EOL> def test_partial_fit_errors ( ) : <EOL> X = [ [ <NUM_LIT:3> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:6> ] ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> assert_raises ( ValueError , <EOL> MLPClassifier ( <EOL> algorithm = '<STR_LIT>' ) . partial_fit , <EOL> X , y , <EOL> classes = [ <NUM_LIT:2> ] ) <EOL> assert_false ( hasattr ( MLPClassifier ( algorithm = '<STR_LIT>' ) , '<STR_LIT>' ) ) <EOL> def test_params_errors ( ) : <EOL> X = [ [ <NUM_LIT:3> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:6> ] ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> clf = MLPClassifier <EOL> assert_raises ( ValueError , clf ( hidden_layer_sizes = - <NUM_LIT:1> ) . fit , X , y ) <EOL> assert_raises ( ValueError , clf ( max_iter = - <NUM_LIT:1> ) . fit , X , y ) <EOL> assert_raises ( ValueError , clf ( shuffle = '<STR_LIT:true>' ) . fit , X , y ) <EOL> assert_raises ( ValueError , clf ( alpha = - <NUM_LIT:1> ) . fit , X , y ) <EOL> assert_raises ( ValueError , clf ( learning_rate_init = - <NUM_LIT:1> ) . fit , X , y ) <EOL> assert_raises ( ValueError , clf ( algorithm = '<STR_LIT>' ) . fit , X , y ) <EOL> assert_raises ( ValueError , clf ( learning_rate = '<STR_LIT>' ) . fit , X , y ) <EOL> assert_raises ( ValueError , clf ( activation = '<STR_LIT>' ) . fit , X , y ) <EOL> def test_predict_proba_binary ( ) : <EOL> X = X_digits_binary [ : <NUM_LIT:50> ] <EOL> y = y_digits_binary [ : <NUM_LIT:50> ] <EOL> clf = MLPClassifier ( hidden_layer_sizes = <NUM_LIT:5> ) <EOL> clf . fit ( X , y ) <EOL> y_proba = clf . predict_proba ( X ) <EOL> y_log_proba = clf . predict_log_proba ( X ) <EOL> ( n_samples , n_classes ) = y . shape [ <NUM_LIT:0> ] , <NUM_LIT:2> <EOL> proba_max = y_proba . argmax ( axis = <NUM_LIT:1> ) <EOL> proba_log_max = y_log_proba . argmax ( axis = <NUM_LIT:1> ) <EOL> assert_equal ( y_proba . shape , ( n_samples , n_classes ) ) <EOL> assert_array_equal ( proba_max , proba_log_max ) <EOL> assert_array_equal ( y_log_proba , np . log ( y_proba ) ) <EOL> assert_equal ( roc_auc_score ( y , y_proba [ : , <NUM_LIT:1> ] ) , <NUM_LIT:1.0> ) <EOL> def test_predict_proba_multi ( ) : <EOL> X = X_digits_multi [ : <NUM_LIT:10> ] <EOL> y = y_digits_multi [ : <NUM_LIT:10> ] <EOL> clf = MLPClassifier ( hidden_layer_sizes = <NUM_LIT:5> ) <EOL> clf . fit ( X , y ) <EOL> y_proba = clf . predict_proba ( X ) <EOL> y_log_proba = clf . predict_log_proba ( X ) <EOL> ( n_samples , n_classes ) = y . shape [ <NUM_LIT:0> ] , np . unique ( y ) . size <EOL> proba_max = y_proba . argmax ( axis = <NUM_LIT:1> ) <EOL> proba_log_max = y_log_proba . argmax ( axis = <NUM_LIT:1> ) <EOL> assert_equal ( y_proba . shape , ( n_samples , n_classes ) ) <EOL> assert_array_equal ( proba_max , proba_log_max ) <EOL> assert_array_equal ( y_log_proba , np . log ( y_proba ) ) <EOL> def test_sparse_matrices ( ) : <EOL> X = X_digits_binary [ : <NUM_LIT:50> ] <EOL> y = y_digits_binary [ : <NUM_LIT:50> ] <EOL> X_sparse = csr_matrix ( X ) <EOL> mlp = MLPClassifier ( random_state = <NUM_LIT:1> , hidden_layer_sizes = <NUM_LIT:15> ) <EOL> mlp . fit ( X , y ) <EOL> pred1 = mlp . decision_function ( X ) <EOL> mlp . fit ( X_sparse , y ) <EOL> pred2 = mlp . decision_function ( X_sparse ) <EOL> assert_almost_equal ( pred1 , pred2 ) <EOL> pred1 = mlp . predict ( X ) <EOL> pred2 = mlp . predict ( X_sparse ) <EOL> assert_array_equal ( pred1 , pred2 ) <EOL> def test_tolerance ( ) : <EOL> X = [ [ <NUM_LIT:3> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:6> ] ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> clf = MLPClassifier ( tol = <NUM_LIT:0.5> , max_iter = <NUM_LIT> , algorithm = '<STR_LIT>' , verbose = <NUM_LIT:10> ) <EOL> clf . fit ( X , y ) <EOL> assert_greater ( clf . max_iter , clf . n_iter_ ) <EOL> def test_verbose_sgd ( ) : <EOL> X = [ [ <NUM_LIT:3> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:6> ] ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> clf = MLPClassifier ( algorithm = '<STR_LIT>' , max_iter = <NUM_LIT:2> , verbose = <NUM_LIT:10> , <EOL> hidden_layer_sizes = <NUM_LIT:2> ) <EOL> old_stdout = sys . stdout <EOL> sys . stdout = output = StringIO ( ) <EOL> clf . fit ( X , y ) <EOL> clf . partial_fit ( X , y ) <EOL> sys . stdout = old_stdout <EOL> assert '<STR_LIT>' in output . getvalue ( ) <EOL> def test_early_stopping ( ) : <EOL> X = X_digits_binary [ : <NUM_LIT:100> ] <EOL> y = y_digits_binary [ : <NUM_LIT:100> ] <EOL> tol = <NUM_LIT> <EOL> clf = MLPClassifier ( tol = tol , max_iter = <NUM_LIT> , algorithm = '<STR_LIT>' , <EOL> early_stopping = True ) <EOL> clf . fit ( X , y ) <EOL> assert_greater ( clf . max_iter , clf . n_iter_ ) <EOL> valid_scores = clf . validation_scores_ <EOL> best_valid_score = clf . best_validation_score_ <EOL> assert_equal ( max ( valid_scores ) , best_valid_score ) <EOL> assert_greater ( best_valid_score + tol , valid_scores [ - <NUM_LIT:2> ] ) <EOL> assert_greater ( best_valid_score + tol , valid_scores [ - <NUM_LIT:1> ] ) <EOL> def test_adaptive_learning_rate ( ) : <EOL> X = [ [ <NUM_LIT:3> , <NUM_LIT:2> ] , [ <NUM_LIT:1> , <NUM_LIT:6> ] ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:0> ] <EOL> clf = MLPClassifier ( tol = <NUM_LIT:0.5> , max_iter = <NUM_LIT> , algorithm = '<STR_LIT>' , <EOL> learning_rate = '<STR_LIT>' , verbose = <NUM_LIT:10> ) <EOL> clf . fit ( X , y ) <EOL> assert_greater ( clf . max_iter , clf . n_iter_ ) <EOL> assert_greater ( <NUM_LIT> , clf . _optimizer . learning_rate ) </s>
