docstr: Set n_iter=2 for the same reason as for SGD
docstr_tok: ["Set","n_iter=2","for","the","same","reason","as","for","SGD"]
code: def iterative_fit(self, X, y, n_iter=2, refit=False):
      """Set n_iter=2 for the same reason as for SGD"""
      import sklearn.preprocessing
      from sklearn.neural_network import MLPRegressor
  
      n_iter = max(n_iter, 2)
  
      if refit:
          self.estimator = None
          self.scaler = None
  
      if self.estimator is None:
          self._fully_fit = False
  
          self.max_iter = int(self.max_iter)
          self.hidden_layer_depth = int(self.hidden_layer_depth)
          self.num_nodes_per_layer = int(self.num_nodes_per_layer)
          self.hidden_layer_sizes = tuple(
              self.num_nodes_per_layer
              for i in range(self.hidden_layer_depth)
          )
          self.activation = str(self.activation)
          self.alpha = float(self.alpha)
          self.learning_rate_init = float(self.learning_rate_init)
          self.early_stopping = str(self.early_stopping)
          if self.early_stopping == "train":
              self.validation_fraction = 0.0
              self.tol = float(self.tol)
              self.n_iter_no_change = int(self.n_iter_no_change)
              self.early_stopping_val = False
          elif self.early_stopping == "valid":
              self.validation_fraction = float(self.validation_fraction)
              self.tol = float(self.tol)
              self.n_iter_no_change = int(self.n_iter_no_change)
              self.early_stopping_val = True
          else:
              raise ValueError(
                  "Set early stopping to unknown value %s"
                  % self.early_stopping
              )
          # elif self.early_stopping == "off":
          #     self.validation_fraction = 0
          #     self.tol = 10000
          #     self.n_iter_no_change = self.max_iter
          #     self.early_stopping_val = False
  
          self.solver = self.solver
  
          try:
              self.batch_size = int(self.batch_size)
          except ValueError:
              self.batch_size = str(self.batch_size)
  
          self.shuffle = check_for_bool(self.shuffle)
          self.beta_1 = float(self.beta_1)
          self.beta_2 = float(self.beta_2)
          self.epsilon = float(self.epsilon)
          self.beta_1 = float(self.beta_1)
          self.verbose = int(self.verbose)
  
          n_iter = int(np.ceil(n_iter))
  
          # initial fit of only increment trees
          self.estimator = MLPRegressor(
              hidden_layer_sizes=self.hidden_layer_sizes,
              activation=self.activation,
              solver=self.solver,
              alpha=self.alpha,
              batch_size=self.batch_size,
              learning_rate_init=self.learning_rate_init,
              max_iter=n_iter,
              shuffle=self.shuffle,
              random_state=self.random_state,
              verbose=self.verbose,
              warm_start=True,
              early_stopping=self.early_stopping_val,
              validation_fraction=self.validation_fraction,
              n_iter_no_change=self.n_iter_no_change,
              tol=self.tol,
              beta_1=self.beta_2,
              beta_2=self.beta_1,
              epsilon=self.epsilon,
              # We do not use these, see comments below in search space
              # momentum=self.momentum,
              # nesterovs_momentum=self.nesterovs_momentum,
              # power_t=self.power_t,
              # learning_rate=self.learning_rate,
              # max_fun=self.max_fun
          )
          self.scaler = sklearn.preprocessing.StandardScaler(copy=True)
  
          # Convert y to be at least 2d for the StandardScaler
          # [1,1,1] -> [[1], [1], [1]]
          if y.ndim == 1:
              y = y.reshape((-1, 1))
  
          self.scaler.fit(y)
      else:
          new_max_iter = min(
              self.max_iter - self.estimator.n_iter_, n_iter
          )
          self.estimator.max_iter = new_max_iter
  
      # Convert y to be at least 2d for the scaler
      # [1,1,1] -> [[1], [1], [1]]
      if y.ndim == 1:
          y = y.reshape((-1, 1))
  
      y_scaled = self.scaler.transform(y)
  
      # Flatten: [[0], [0], [0]] -> [0, 0, 0]
      if y_scaled.ndim == 2 and y_scaled.shape[1] == 1:
          y_scaled = y_scaled.flatten()
  
      self.estimator.fit(X, y_scaled)
  
      if (
          self.estimator.n_iter_ >= self.max_iter
          or self.estimator._no_improvement_count
          > self.n_iter_no_change
      ):
          self._fully_fit = True
  
      return self
  
file_path: auto-sklearn/autosklearn/pipeline/components/regression/mlp.py
imports: from typing import Optional
  import numpy
  from ConfigSpace.conditions import InCondition
  from ConfigSpace.configuration_space import ConfigurationSpace
  from ConfigSpace.hyperparameters import CategoricalHyperparameter, Constant, UniformFloatHyperparameter, UniformIntegerHyperparameter, UnParametrizedHyperparameter
  from autosklearn.askl_typing import FEAT_TYPE_TYPE
  from autosklearn.pipeline.components.base import AutoSklearnRegressionAlgorithm, IterativeComponent
  from autosklearn.pipeline.constants import DENSE, PREDICTIONS, SPARSE, UNSIGNED_DATA
  from autosklearn.util.common import check_for_bool
label_desc: Use image node_id 4 for calling the MLPRegressor obj's underlying member method code with example usage: obj.iterative_fit(X, y, n_iter, refit) and returns: self