code: def _sigmoid_calibration(
      predictions,
      y,
      sample_weight=None,
      max_abs_prediction_threshold=30,
  ):
      """Probability Calibration with sigmoid method (Platt 2000)
  
      Parameters
      ----------
      predictions : ndarray of shape (n_samples,)
          The decision function or predict proba for the samples.
  
      y : ndarray of shape (n_samples,)
          The targets.
  
      sample_weight : array-like of shape (n_samples,), default=None
          Sample weights. If None, then samples are equally weighted.
  
      Returns
      -------
      a : float
          The slope.
  
      b : float
          The intercept.
  
      References
      ----------
      Platt, "Probabilistic Outputs for Support Vector Machines"
      """
      predictions = column_or_1d(predictions)
      y = column_or_1d(y)
  
      F = predictions  # F follows Platt's notations
  
      scale_constant = 1.0
      max_prediction = np.max(np.abs(F))
  
      # If the predictions have large values we scale them in order to bring
      # them within a suitable range. This has no effect on the final
      # (prediction) result because linear models like Logisitic Regression
      # without a penalty are invariant to multiplying the features by a
      # constant.
      if max_prediction >= max_abs_prediction_threshold:
          scale_constant = max_prediction
          # We rescale the features in a copy: inplace rescaling could confuse
          # the caller and make the code harder to reason about.
          F = F / scale_constant
  
      # Bayesian priors (see Platt end of section 2.2):
      # It corresponds to the number of samples, taking into account the
      # `sample_weight`.
      mask_negative_samples = y <= 0
      if sample_weight is not None:
          prior0 = (sample_weight[mask_negative_samples]).sum()
          prior1 = (sample_weight[~mask_negative_samples]).sum()
      else:
          prior0 = float(np.sum(mask_negative_samples))
          prior1 = y.shape[0] - prior0
      T = np.zeros_like(y, dtype=np.float64)
      T[y > 0] = (prior1 + 1.0) / (prior1 + 2.0)
      T[y <= 0] = 1.0 / (prior0 + 2.0)
      T1 = 1.0 - T
  
      def objective(AB):
          # From Platt (beginning of Section 2.2)
          P = expit(-(AB[0] * F + AB[1]))
          loss = -(xlogy(T, P) + xlogy(T1, 1.0 - P))
          if sample_weight is not None:
              return (sample_weight * loss).sum()
          else:
              return loss.sum()
  
      def grad(AB):
          # gradient of the objective function
          P = expit(-(AB[0] * F + AB[1]))
          TEP_minus_T1P = T - P
          if sample_weight is not None:
              TEP_minus_T1P *= sample_weight
          dA = np.dot(TEP_minus_T1P, F)
          dB = np.sum(TEP_minus_T1P)
          return np.array([dA, dB])
  
      AB0 = np.array([0.0, log((prior0 + 1.0) / (prior1 + 1.0))])
      AB_ = fmin_bfgs(objective, AB0, fprime=grad, disp=False)
  
      # The tuned multiplicative parameter is converted back to the original
      # input feature scale. The offset parameter does not need rescaling since
      # we did not rescale the outcome variable.
      return AB_[0] / scale_constant, AB_[1]
  
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 5 for calling a global function with example usage: _sigmoid_calibration(predictions, y, sample_weight, max_abs_prediction_threshold) and returns: unknown,  AB_, np, unknown, loss