code: def _parallel_fit(
      estimator,
      X,
      y,
      train,
      test,
      param_grid,
      is_classification,
      selector,
      scorer,
      mask_img,
      class_index,
      clustering_percentile,
  ):
      """Find the best estimator for a fold within a job.
  
      This function tries several parameters for the estimator for the train and
      test fold provided and save the one that performs best.
  
      Fit may be performed after some preprocessing step :
      * clustering with ReNA if clustering_percentile < 100
      * feature screening if screening_percentile < 100
      """
      X_train, y_train = X[train], y[train]
      X_test, y_test = X[test], y[test]
  
      # for FREM Classifier and Regressor : start by doing a quick ReNA
      # clustering to reduce the number of feature by agglomerating similar ones
  
      if clustering_percentile < 100:
          n_clusters = int(
              X_train.shape[1] * clustering_percentile / 100.0
          )
          clustering = ReNA(
              mask_img,
              n_clusters=n_clusters,
              n_iter=20,
              threshold=1e-7,
              scaling=False,
          )
          X_train = clustering.fit_transform(X_train)
          X_test = clustering.transform(X_test)
  
      do_screening = (X_train.shape[1] > 100) and selector is not None
  
      if do_screening:
          X_train = selector.fit_transform(X_train, y_train)
          X_test = selector.transform(X_test)
  
      # If there is no parameter grid, then we use a suitable grid (by default)
      param_grid = ParameterGrid(
          _check_param_grid(estimator, X_train, y_train, param_grid)
      )
  
      # collect all parameter names from the grid
      all_params = set()
      for params in param_grid:
          all_params.update(params.keys())
  
      best_score = None
      for params in param_grid:
          estimator = clone(estimator).set_params(**params)
          estimator.fit(X_train, y_train)
  
          if is_classification:
              score = scorer(estimator, X_test, y_test)
              if hasattr(estimator, "coef_") and np.all(
                  estimator.coef_ == 0
              ):
                  score = 0
          else:  # regression
              score = scorer(estimator, X_test, y_test)
  
          # Store best parameters and estimator coefficients
          if (best_score is None) or (score >= best_score):
              best_score = score
              if hasattr(estimator, "coef_"):
                  best_coef = np.reshape(estimator.coef_, (1, -1))
                  best_intercept = estimator.intercept_
                  dummy_output = None
              else:
                  best_coef, best_intercept = None, None
                  if isinstance(estimator, DummyClassifier):
                      dummy_output = estimator.class_prior_
                  elif isinstance(estimator, DummyRegressor):
                      dummy_output = estimator.constant_
  
              if isinstance(
                  estimator, (RidgeCV, RidgeClassifierCV, LassoCV)
              ):
                  params["best_alpha"] = estimator.alpha_
              elif isinstance(estimator, LogisticRegressionCV):
                  params["best_C"] = estimator.C_.item()
              best_params = params
  
              # fill in any missing param from param_grid
              for param in all_params:
                  if param not in best_params:
                      best_params[param] = getattr(estimator, param)
  
      if best_coef is not None:
          if do_screening:
              best_coef = selector.inverse_transform(best_coef)
  
          if clustering_percentile < 100:
              best_coef = clustering.inverse_transform(best_coef)
  
      return (
          class_index,
          best_coef,
          best_intercept,
          best_params,
          best_score,
          dummy_output,
      )
  
imports: import itertools
  import warnings
  from typing import Iterable
  import numpy
  from joblib import Parallel, delayed
  from sklearn import clone
  from sklearn.base import BaseEstimator, MultiOutputMixin
  from sklearn.dummy import DummyClassifier, DummyRegressor
  from sklearn.linear_model import LassoCV, LogisticRegressionCV, RidgeClassifierCV, RidgeCV
  from sklearn.metrics import check_scoring, get_scorer
  from sklearn.model_selection import LeaveOneGroupOut, ParameterGrid, ShuffleSplit, StratifiedShuffleSplit, check_cv
  from sklearn.preprocessing import LabelBinarizer
  from sklearn.svm import SVR, LinearSVC, l1_min_c
  from sklearn.utils.extmath import safe_sparse_dot
  from sklearn.utils.validation import check_is_fitted, check_X_y
  from nilearn._utils import CacheMixin, fill_doc
  from nilearn._utils.cache_mixin import _check_memory
  from nilearn._utils.masker_validation import check_embedded_masker
  from nilearn._utils.param_validation import check_feature_screening
  from nilearn.experimental.surface import SurfaceMasker
  from nilearn.regions.rena_clustering import ReNA
label_desc: Use image node_id 6 for calling a global function with example usage: _parallel_fit(estimator, X, y, train, test, param_grid, is_classification, selector, scorer, mask_img, class_index, clustering_percentile) and returns: class_index,  best_coef,  best_intercept,  best_params,  best_score,  dummy_output