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 _ml_parametrization(
      self,
      depth: int,  # Parameters for regression trees.
      criterion: str,
      min_samples_split: float,
      solver: str,  # Parameters for neural nets.
      activation: str,
      alpha: float,
      learning_rate: str,
      regressor: str,  # Choice of learner.
      noise_free: bool,  # Whether we work on the test set (the real cost) on an approximation (CV error on train). -> not really noise
  ) -> float:
      if not self.X_train.size:  # lazzy initialization
          self.make_dataset(self.data_dimension, self.dataset)
      # num_cv-folds cross-validation
      result = 0.0
      # Fit regression model
      if regressor == "decision_tree":
          regr = DecisionTreeRegressor(
              max_depth=depth,
              criterion=criterion,
              min_samples_split=min_samples_split,
              random_state=0,
          )
      elif regressor == "mlp":
          regr = MLPRegressor(
              alpha=alpha,
              activation=activation,
              solver=solver,
              learning_rate=learning_rate,
              random_state=0,
          )
      elif regressor == "keras_dense_nn":
          try:
              from tensorflow import (
                  keras,
              )  # pylint: disable=import-outside-toplevel
          except ImportError as e:
              raise ImportError(
                  "Please install keras (pip install keras) to use keras ml tuning"
              ) from e
  
          regr = keras.Sequential(
              [
                  keras.layers.Dense(
                      64,
                      activation=activation,
                      input_shape=(self.X_train.shape[1],),
                  ),
                  keras.layers.Dense(1),
              ]
          )
          regr.compile(optimizer=solver, loss="mse", metrics=["mae"])
      else:
          raise ValueError(f"Unknown regressor {regressor}.")
  
      fit_additional_params = (
          dict(verbose=0, epochs=350)
          if regressor == "keras_dense_nn"
          else {}
      )
  
      if (
          noise_free
      ):  # noise_free is True when we want the result on the test set.
          X_test = self.X_test
          y_test = self.y_test
          regr.fit(self.X_train, self.y_train, **fit_additional_params)
          pred_test = regr.predict(self.X_test)
          return mean_squared_error(self.y_test, pred_test)
  
      # We do a cross-validation.
      for X, y, X_test, y_test in zip(
          self.X_train_cv,
          self.y_train_cv,
          self.X_valid_cv,
          self.y_valid_cv,
      ):
          assert isinstance(
              depth, int
          ), f"depth has class {type(depth)} and value {depth}."
  
          regr.fit(X, y, **fit_additional_params)
          # Predict
          pred_test = regr.predict(X_test)
          try:
              result += mean_squared_error(y_test, pred_test)
          except ValueError:
              result += 5.0e20
  
      return result / self._cross_val_num
  
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 1 for calling the MLTuning obj's underlying member method code with example usage: obj._ml_parametrization(depth, criterion, min_samples_split, solver, activation, alpha, learning_rate, regressor, noise_free) and returns: unknown, mean_squared_error