Repository: scikit-learn/scikit-learn
File: sklearn/discriminant_analysis.py (Python)

Code before:
        "reg_param": [Interval(Real, 0, 1, closed="both")],
        "store_covariance": ["boolean"],
        "tol": [Interval(Real, 0, None, closed="left")],
        "covariance_estimator": [HasMethods("fit"), None],
    }

    def __init__(
        self,
        *,
        solver="svd",
        shrinkage=None,
        priors=None,
        reg_param=0.0,
        store_covariance=False,
        tol=1.0e-4,
        covariance_estimator=None,
    ):
        self.solver = solver
        self.shrinkage = shrinkage
        self.priors = priors
        self.reg_param = reg_param
        self.store_covariance = store_covariance
        self.tol = tol
        self.covariance_estimator = covariance_estimator

    def _solve_eigen(self, X, shrinkage, covariance_estimator):
        """Eigenvalue solver.

        The eigenvalue solver uses the eigen decomposition of the data
        to compute the rotation and scaling matrices used for scoring
        new samples. This solver supports use of any covariance estimator.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training data.

        shrinkage : 'auto', float or None
            Shrinkage parameter, possible values:
              - None: no shrinkage.
              - 'auto': automatic shrinkage using the Ledoit-Wolf lemma.
              - float between 0 and 1: fixed shrinkage constant.

            Shrinkage parameter is ignored if  `covariance_estimator` is not None

        covariance_estimator : estimator, default=None
            If not None, `covariance_estimator` is used to estimate the
            covariance matrices instead of relying the empirical covariance
            estimator (with potential shrinkage). The object should have a fit
            method and a ``covariance_`` attribute like the estimators in
            sklearn.covariance. If None the shrinkage parameter drives the estimate.

Review comment (suggestion):
Lease use `self.shrinkage` and `self.covariance_estimator` directly instead of passing them as argument to this private method.

Code after:

    _parameter_constraints: dict = {
        "solver": [StrOptions({"svd", "eigen"})],
        "shrinkage": [StrOptions({"auto"}), Interval(Real, 0, 1, closed="both"), None],
        "priors": ["array-like", None],
        "reg_param": [Interval(Real, 0, 1, closed="both")],
        "store_covariance": ["boolean"],
        "tol": [Interval(Real, 0, None, closed="left")],
        "covariance_estimator": [HasMethods("fit"), None],
    }

    def __init__(
        self,
        *,
        solver="svd",
        shrinkage=None,
        priors=None,
        reg_param=0.0,
        store_covariance=False,
        tol=1.0e-4,
        covariance_estimator=None,
    ):
        self.solver = solver
        self.shrinkage = shrinkage
        self.priors = priors
        self.reg_param = reg_param
        self.store_covariance = store_covariance
        self.tol = tol
        self.covariance_estimator = covariance_estimator

    def _solve_eigen(self, X):
        """Eigenvalue solver.

        The eigenvalue solver uses the eigen decomposition of the data
        to compute the rotation and scaling matrices used for scoring
        new samples. This solver supports use of any covariance estimator.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training data.
        """
        n_samples, n_features = X.shape

        cov = _cov(X, self.shrinkage, self.covariance_estimator)
        scaling, rotation = linalg.eigh(cov)  # scalings are eigenvalues
        rotation = rotation[:, np.argsort(scaling)[::-1]]  # sort eigenvectors
        scaling = scaling[np.argsort(scaling)[::-1]]  # sort eigenvalues
        return scaling, rotation, cov

    def _solve_svd(self, X):