code: def __init__(
      self,
      X_train,
      MR_train,
      X_val,
      MR_val,
      fe_type="rf",
      fe=None,
      n_estimators=200,
      max_features=0.5,
      min_samples_leaf=10,
      regularization=0.001,
  ):
      # Features and the target model response
      self.X_train = X_train
      self.MR_train = MR_train
      self.X_val = X_val
      self.MR_val = MR_val
  
      # Forest Ensemble Parameters
      self.n_estimators = n_estimators
      self.max_features = max_features
      self.min_samples_leaf = min_samples_leaf
  
      # Local Linear Model Parameters
      self.regularization = regularization
  
      # Data parameters
      num_features = X_train.shape[1]
      self.num_features = num_features
      num_train = X_train.shape[0]
      self.num_train = num_train
      num_val = X_val.shape[0]
  
      # Fit a Forest Ensemble to the model response
      if fe is None:
          if fe_type == "rf":
              fe = RandomForestRegressor(
                  n_estimators=n_estimators,
                  min_samples_leaf=min_samples_leaf,
                  max_features=max_features,
              )
          elif fe_type == "gbrt":
              fe = GradientBoostingRegressor(
                  n_estimators=n_estimators,
                  min_samples_leaf=min_samples_leaf,
                  max_features=max_features,
                  max_depth=None,
              )
          else:
              print("Unknown FE type ", fe)
              import sys
  
              sys.exit(0)
          fe.fit(X_train, MR_train)
      else:
          self.n_estimators = n_estimators = len(fe.estimators_)
      self.fe = fe
  
      train_leaf_ids = fe.apply(X_train)
      self.train_leaf_ids = train_leaf_ids
  
      val_leaf_ids_list = fe.apply(X_val)
  
      # Compute the feature importances: Non-normalized @ Root
      scores = np.zeros(num_features)
      if fe_type == "rf":
          for i in range(n_estimators):
              splits = fe[
                  i
              ].tree_.feature  # -2 indicates leaf, index 0 is root
              if splits[0] != -2:
                  scores[splits[0]] += fe[i].tree_.impurity[
                      0
                  ]  # impurity reduction not normalized per tree
      elif fe_type == "gbrt":
          for i in range(n_estimators):
              splits = fe[
                  i, 0
              ].tree_.feature  # -2 indicates leaf, index 0 is root
              if splits[0] != -2:
                  scores[splits[0]] += fe[i, 0].tree_.impurity[
                      0
                  ]  # impurity reduction not normalized per tree
      self.feature_scores = scores
      mostImpFeats = np.argsort(-scores)
  
      # Find the number of features to use for MAPLE
      retain_best = 0
      rmse_best = np.inf
      for retain in range(1, num_features + 1):
          # Drop less important features for local regression
          X_train_p = np.delete(X_train, mostImpFeats[retain:], axis=1)
          X_val_p = np.delete(X_val, mostImpFeats[retain:], axis=1)
  
          lr_predictions = np.empty([num_val], dtype=float)
  
          for i in range(num_val):
              weights = self.training_point_weights(
                  val_leaf_ids_list[i]
              )
  
              # Local linear model
              lr_model = Ridge(alpha=regularization)
              lr_model.fit(X_train_p, MR_train, weights)
              lr_predictions[i] = lr_model.predict(
                  X_val_p[i].reshape(1, -1)
              )
  
          rmse_curr = np.sqrt(
              mean_squared_error(lr_predictions, MR_val)
          )
  
          if rmse_curr < rmse_best:
              rmse_best = rmse_curr
              retain_best = retain
  
      self.retain = retain_best
      self.X = np.delete(X_train, mostImpFeats[retain_best:], axis=1)
  
imports: import numpy
  import pandas
  from sklearn.model_selection import train_test_split
  from .._explainer import Explainer
  import numpy
  from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor
  from sklearn.linear_model import Ridge
  from sklearn.metrics import mean_squared_error
label_desc: Use image node_id 1 to create a new MAPLE object  with example: obj = MAPLE(X_train, MR_train, X_val, MR_val, fe_type, fe, n_estimators, max_features, min_samples_leaf, regularization)