code: def _fit_calibrator(
      clf, predictions, y, classes, method, sample_weight=None
  ):
      """Fit calibrator(s) and return a `_CalibratedClassifier`
      instance.
  
      `n_classes` (i.e. `len(clf.classes_)`) calibrators are fitted.
      However, if `n_classes` equals 2, one calibrator is fitted.
  
      Parameters
      ----------
      clf : estimator instance
          Fitted classifier.
  
      predictions : array-like, shape (n_samples, n_classes) or (n_samples, 1) \
                      when binary.
          Raw predictions returned by the un-calibrated base classifier.
  
      y : array-like, shape (n_samples,)
          The targets.
  
      classes : ndarray, shape (n_classes,)
          All the prediction classes.
  
      method : {'sigmoid', 'isotonic'}
          The method to use for calibration.
  
      sample_weight : ndarray, shape (n_samples,), default=None
          Sample weights. If None, then samples are equally weighted.
  
      Returns
      -------
      pipeline : _CalibratedClassifier instance
      """
      Y = label_binarize(y, classes=classes)
      label_encoder = LabelEncoder().fit(classes)
      pos_class_indices = label_encoder.transform(clf.classes_)
      calibrators = []
      for class_idx, this_pred in zip(pos_class_indices, predictions.T):
          if method == "isotonic":
              calibrator = IsotonicRegression(out_of_bounds="clip")
          else:  # "sigmoid"
              calibrator = _SigmoidCalibration()
          calibrator.fit(this_pred, Y[:, class_idx], sample_weight)
          calibrators.append(calibrator)
  
      pipeline = _CalibratedClassifier(
          clf, calibrators, method=method, classes=classes
      )
      return pipeline
  
imports: import warnings
  from functools import partial
  from inspect import signature
  from math import log
  from numbers import Integral, Real
  import numpy
  from scipy.optimize import fmin_bfgs
  from scipy.special import expit, xlogy
  from sklearn.utils import Bunch
  from .base import BaseEstimator, ClassifierMixin, MetaEstimatorMixin, RegressorMixin, _fit_context, clone
  from .isotonic import IsotonicRegression
  from .model_selection import check_cv, cross_val_predict
  from .preprocessing import LabelEncoder, label_binarize
  from .svm import LinearSVC
  from .utils import _safe_indexing, column_or_1d, indexable
  from .utils._param_validation import HasMethods, Hidden, Interval, StrOptions, validate_params
  from .utils._plotting import _BinaryClassifierCurveDisplayMixin
  from .utils.metadata_routing import MetadataRouter, MethodMapping, _routing_enabled, process_routing
  from .utils.multiclass import check_classification_targets
  from .utils.parallel import Parallel, delayed
  from .utils.validation import _check_fit_params, _check_pos_label_consistency, _check_sample_weight, _num_samples, check_consistent_length, check_is_fitted
label_desc: Use image node_id 4 for calling a global function with example usage: _fit_calibrator(clf, predictions, y, classes, method, sample_weight) and returns: pipeline