code: def _fit(self, pairs, y):
      if not HAS_SKGGM:
          if self.verbose:
              print(
                  "SDML will use scikit-learn's graphical lasso solver."
              )
      else:
          if self.verbose:
              print("SDML will use skggm's graphical lasso solver.")
      pairs, y = self._prepare_inputs(pairs, y, type_of_inputs="tuples")
      n_features = pairs.shape[2]
      if n_features < 2:
          raise ValueError(
              f"Cannot fit SDML with {n_features} feature(s)"
          )
  
      # set up (the inverse of) the prior M
      # if the prior is the default (None), we raise a warning
      _, prior_inv = _initialize_metric_mahalanobis(
          pairs,
          self.prior,
          return_inverse=True,
          strict_pd=True,
          matrix_name="prior",
          random_state=self.random_state,
      )
      diff = pairs[:, 0] - pairs[:, 1]
      loss_matrix = (diff.T * y).dot(diff)
      emp_cov = prior_inv + self.balance_param * loss_matrix
  
      # our initialization will be the matrix with emp_cov's eigenvalues,
      # with a constant added so that they are all positive (plus an epsilon
      # to ensure definiteness). This is empirical.
      w, V = np.linalg.eigh(emp_cov)
      min_eigval = np.min(w)
      if min_eigval < 0.0:
          warnings.warn(
              "Warning, the input matrix of graphical lasso is not "
              "positive semi-definite (PSD). The algorithm may diverge, "
              "and lead to degenerate solutions. "
              "To prevent that, try to decrease the balance parameter "
              "`balance_param` and/or to set prior='identity'.",
              ConvergenceWarning,
          )
          w -= min_eigval  # we translate the eigenvalues to make them all positive
      w += 1e-10  # we add a small offset to avoid definiteness problems
      sigma0 = (V * w).dot(V.T)
      try:
          if HAS_SKGGM:
              theta0 = pinvh(sigma0)
              M, _, _, _, _, _ = quic(
                  emp_cov,
                  lam=self.sparsity_param,
                  msg=self.verbose,
                  Theta0=theta0,
                  Sigma0=sigma0,
              )
          else:
              _, M = graphical_lasso(
                  emp_cov,
                  alpha=self.sparsity_param,
                  verbose=self.verbose,
                  cov_init=sigma0,
              )
          raised_error = None
          w_mahalanobis, _ = np.linalg.eigh(M)
          not_spd = any(w_mahalanobis < 0.0)
          not_finite = not np.isfinite(M).all()
      # TODO: Narrow this to the specific exceptions we expect.
      except Exception as e:
          raised_error = e
          not_spd = (
              False  # not_spd not applicable here so we set to False
          )
          not_finite = (
              False  # not_finite not applicable here so we set to False
          )
      if raised_error is not None or not_spd or not_finite:
          msg = (
              "There was a problem in SDML when using {}'s graphical "
              "lasso solver."
          ).format("skggm" if HAS_SKGGM else "scikit-learn")
          if not HAS_SKGGM:
              skggm_advice = (
                  " skggm's graphical lasso can sometimes converge "
                  "on non SPD cases where scikit-learn's graphical "
                  "lasso fails to converge. Try to install skggm and "
                  "rerun the algorithm (see the README.md for the "
                  "right version of skggm)."
              )
              msg += skggm_advice
          if raised_error is not None:
              msg += (
                  " The following error message was thrown: {}.".format(
                      raised_error
                  )
              )
          raise RuntimeError(msg)
  
      self.components_ = components_from_metric(np.atleast_2d(M))
      return self
  
imports: import warnings
  import numpy
  from sklearn.base import TransformerMixin
  from scipy.linalg import pinvh
  from sklearn.covariance import graphical_lasso
  from sklearn.exceptions import ConvergenceWarning
  from .base_metric import MahalanobisMixin, _PairsClassifierMixin
  from .constraints import Constraints, wrap_pairs
  from ._util import components_from_metric, _initialize_metric_mahalanobis
label_desc: Use image node_id 2 for calling the _BaseSDML obj's underlying member method code with example usage: obj._fit(pairs, y) and returns: self