code: def _fit_estimator(estimator, X, y, sample_weight=None, **fit_params):
      estimator = clone(estimator)
      if sample_weight is not None:
          estimator.fit(X, y, sample_weight=sample_weight, **fit_params)
      else:
          estimator.fit(X, y, **fit_params)
      return estimator
  
imports: from abc import ABCMeta, abstractmethod
  from numbers import Integral
  import numpy
  import scipy.sparse
  from .base import BaseEstimator, ClassifierMixin, MetaEstimatorMixin, RegressorMixin, _fit_context, clone, is_classifier
  from .model_selection import cross_val_predict
  from .utils import Bunch, _print_elapsed_time, check_random_state
  from .utils._param_validation import HasMethods, StrOptions
  from .utils.metadata_routing import MetadataRouter, MethodMapping, _routing_enabled, process_routing
  from .utils.metaestimators import available_if
  from .utils.multiclass import check_classification_targets
  from .utils.parallel import Parallel, delayed
  from .utils.validation import _check_fit_params, check_is_fitted, has_fit_parameter
label_desc: Use image node_id 1 for calling a global function with example usage: _fit_estimator(estimator, X, y, sample_weight) and returns: estimator