class_docstr: Class for generating ML hyperparameter tuning problems.
  We propose different possible regressors and different dimensionalities.
  In each case, Nevergrad will optimize the parameters of a scikit learning.
  
  Parameters
  ----------
  regressor: str
      type of function we can use for doing the regression. Can be "mlp", "decision_tree", "decision_tree_depth",
      "keras_dense_nn", "any".
      "any" means that the regressor has one more parameter which is a discrete choice among sklearn possibilities.
  data_dimension: int
      dimension of the data we generate. None if not an artificial dataset.
  dataset: str
      type of dataset; can be diabetes, boston, artificial, artificialcoos, artificialsquare.
  overfitter: bool
      if we want the evaluation to be the same as during the optimization run. This means that instead
      of train/valid/error, we have train/valid/valid. This is for research purpose, when we want to check if an algorithm
      is particularly good or particularly bad because it fails to minimize the validation loss or because it overfits.
class_docstr_tok: ["Class","for","generating","ML","hyperparameter","tuning","problems",".","We","propose","different","possible","regressors","and","different","dimensionalities",".","In","each","case",",","Nevergrad","will","optimize","the","parameters","of","a","scikit","learning",".","Parameters","--","--","--","--","--","regressor",":","str","type","of","function","we","can","use","for","doing","the","regression",".","Can","be","``","mlp","''",",","``","decision_tree","''",",","``","decision_tree_depth","''",",","``","keras_dense_nn","''",",","``","any","''",".","``","any","''","means","that","the","regressor","has","one","more","parameter","which","is","a","discrete","choice","among","sklearn","possibilities",".","data_dimension",":","int","dimension","of","the","data","we","generate",".","None","if","not","an","artificial","dataset",".","dataset",":","str","type","of","dataset",";","can","be","diabetes",",","boston",",","artificial",",","artificialcoos",",","artificialsquare",".","overfitter",":","bool","if","we","want","the","evaluation","to","be","the","same","as","during","the","optimization","run",".","This","means","that","instead","of","train\/valid\/error",",","we","have","train\/valid\/valid",".","This","is","for","research","purpose",",","when","we","want","to","check","if","an","algorithm","is","particularly","good","or","particularly","bad","because","it","fails","to","minimize","the","validation","loss","or","because","it","overfits","."]
code: def __init__(
      self,
      regressor: str,
      data_dimension: tp.Optional[int] = None,
      dataset: str = "artificial",
      overfitter: bool = False,
  ) -> None:
      self.regressor = regressor
      self.data_dimension = data_dimension
      self.dataset = dataset
      self.overfitter = overfitter
      self.name = regressor + f"Dim{data_dimension}"
      self.num_data = 120  # default for artificial function
      self._cross_val_num = 10  # number of cross validation
      # Dimension does not make sense if we use a real world dataset.
      assert bool("artificial" in dataset) == bool(
          data_dimension is not None
      )
  
      # # Variables for storing the training set and the test set.
      self.X_train: np.ndarray = np.array([])
      self.y_train: np.ndarray
      self.X_test: np.ndarray
      self.y_test: np.ndarray
      # self.X: np.ndarray = np.array([])
      # self.y: np.ndarray
  
      # Variables for storing the cross-validation splits.
      self.X_train_cv: tp.List[
          tp.Any
      ] = []  # This will be the list of training subsets.
      self.X_valid_cv: tp.List[
          tp.Any
      ] = []  # This will be the list of validation subsets.
      self.y_train_cv: tp.List[tp.Any] = []
      self.y_valid_cv: tp.List[tp.Any] = []
  
      evalparams: tp.Dict[str, tp.Any] = {}
      if regressor == "decision_tree_depth":
          # Only the depth, as an evaluation.
          parametrization = p.Instrumentation(
              depth=p.Scalar(lower=1, upper=1200).set_integer_casting()
          )
          # We optimize only the depth, so we fix all other parameters than the depth
          params = dict(
              noise_free=False,
              criterion="friedman_mse",
              min_samples_split=0.00001,
              regressor="decision_tree",
              alpha=1.0,
              learning_rate="no",
              activation="no",
              solver="no",
          )
      elif regressor == "any":
          # First we define the list of parameters in the optimization
          parametrization = p.Instrumentation(
              depth=p.Scalar(
                  lower=1, upper=1200
              ).set_integer_casting(),  # Depth, in case we use a decision tree.
              criterion=p.Choice(
                  [
                      "friedman_mse",
                      "poisson",
                      "absolute_error",
                      "squared_error",
                  ],
                  # ["mse", "friedman_mse", "mae"]
              ),  # Criterion for building the decision tree.
              min_samples_split=p.Log(
                  lower=0.0000001, upper=1
              ),  # Min ratio of samples in a node for splitting.
              regressor=p.Choice(
                  ["mlp", "decision_tree"]
              ),  # Type of regressor.
              activation=p.Choice(
                  ["identity", "logistic", "tanh", "relu"]
              ),  # Activation function, in case we use a net.
              solver=p.Choice(
                  ["lbfgs", "sgd", "adam"]
              ),  # Numerical optimizer.
              learning_rate=p.Choice(
                  ["constant", "invscaling", "adaptive"]
              ),  # Learning rate schedule.
              alpha=p.Log(
                  lower=0.0000001, upper=1.0
              ),  # Complexity penalization.
          )
          # noise_free is False (meaning that we consider the cross-validation loss) during the optimization.
          params = dict(noise_free=False)
      elif regressor == "decision_tree":
          # We specify below the list of hyperparameters for the decision trees.
          parametrization = p.Instrumentation(
              depth=p.Scalar(lower=1, upper=1200).set_integer_casting(),
              criterion=p.Choice(
                  [
                      "friedman_mse",
                      "poisson",
                      "absolute_error",
                      "squared_error",
                  ]
              ),
              # criterion=p.Choice(["mse", "friedman_mse", "mae"]),
              min_samples_split=p.Log(lower=0.0000001, upper=1),
              regressor="decision_tree",
          )
          params = dict(
              noise_free=False,
              alpha=1.0,
              learning_rate="no",
              regressor="decision_tree",
              activation="no",
              solver="no",
          )
          evalparams = dict(
              params,
              criterion="friedman_mse",
              min_samples_split=0.00001,
          )
      elif regressor == "mlp":
          # Let us define the parameters of the neural network.
          parametrization = p.Instrumentation(
              activation=p.Choice(
                  ["identity", "logistic", "tanh", "relu"]
              ),
              solver=p.Choice(["lbfgs", "sgd", "adam"]),
              regressor="mlp",
              learning_rate=p.Choice(
                  ["constant", "invscaling", "adaptive"]
              ),
              alpha=p.Log(lower=0.0000001, upper=1.0),
          )
          params = dict(
              noise_free=False,
              regressor="mlp",
              depth=-3,
              criterion="no",
              min_samples_split=0.1,
          )
      elif regressor == "keras_dense_nn":
          parametrization = p.Instrumentation(
              activation=p.Choice(["selu", "sigmoid", "tanh", "relu"]),
              solver=p.Choice(["Adadelta", "RMSprop", "adam"]),
              regressor="keras_dense_nn",
              # metrics=p.Choice(["mae", "mse"]),
          )
          params = dict(
              noise_free=False,
              regressor="keras_dense_nn",
              depth=-3,
              criterion="no",
              min_samples_split=0.1,
              alpha=0.1,
              learning_rate="constant",
          )
      else:
          assert False, f"Problem type {regressor} undefined!"
      # build eval params if not specified
      if not evalparams:
          evalparams = dict(params)
      # For the evaluation we remove the noise (unless overfitter)
      evalparams["noise_free"] = not overfitter
      parametrization.function.proxy = not overfitter
      super().__init__(
          partial(self._ml_parametrization, **params),
          parametrization.set_name(""),
      )
      self._evalparams = evalparams
  
file_path: nevergrad/nevergrad/functions/ml/mlfunctionlib.py
imports: import typing
  from functools import partial
  import numpy
  import sklearn.datasets
  from sklearn.tree import DecisionTreeRegressor
  from sklearn.neural_network import MLPRegressor
  from sklearn.model_selection import train_test_split, KFold
  from sklearn.metrics import mean_squared_error
  import pandas
  from nevergrad.parametrization import parameter
  from ..base import ExperimentFunction
label_desc: Use image node_id 2 to create a new MLTuning object from inherited base classes: ExperimentFunction with example: obj = MLTuning(regressor, data_dimension, dataset, overfitter)