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

Code before:
            the raw estimates.

        Returns
        -------
        covariance_corrected : ndarray of shape (n_features, n_features)
            Corrected robust covariance estimate.

        References
        ----------
        .. [Croux1999] Influence Function and Efficiency of the Minimum
            Covariance Determinant Scatter Matrix Estimator, 1999, Journal of
            Multivariate Analysis, Volume 71, Issue 2, Pages 161-190
        """

        # Check that the covariance of the support data is not equal to 0.
        # Otherwise self.dist_ = 0 and thus correction = 0.
        n_samples = len(self.dist_)
        n_support = np.sum(self.support_)
        if n_support < n_samples and np.allclose(self.raw_covariance_, 0):
            raise ValueError(
                "The covariance matrix of the support data "
                "is equal to 0, try to increase support_fraction"
            )
        consistency_factor = _consistency_factor(
            self.raw_covariance_.shape[0], n_support / n_samples
        )
        covariance_corrected = self.raw_covariance_ * consistency_factor
        self.dist_ /= consistency_factor
        return covariance_corrected

    def reweight_covariance(self, data):
        """Re-weight raw Minimum Covariance Determinant estimates.

        Re-weight observations using Rousseeuw's method (equivalent to
        deleting outlying observations from the data set before
        computing location and covariance estimates) described
        in [RVDriessen]_.

        Corrects the re-weighted covariance to be consistent at the normal
        distribution, following [Croux1999]_.

        Parameters
        ----------
        data : array-like of shape (n_samples, n_features)
            The data matrix, with p features and n samples.
            The data set must be the one which was used to compute
            the raw estimates.

        Returns
        -------
        location_reweighted : ndarray of shape (n_features,)

Review comment (suggestion):
```suggestion
        consistency_factor = _consistency_factor(
            n_features, n_support / n_samples
        )
```
and `n_features = self.raw_covariance_.shape[0]` or maybe `n_samples, n_features = data.shape` (if I understand correctly, this should only be called with `data=X` in `fit`). 

Code after:

        Correction using the asymptotic correction factor derived by [Croux1999]_.

        Parameters
        ----------
        data : array-like of shape (n_samples, n_features)
            The data matrix, with p features and n samples.
            The data set must be the one which was used to compute
            the raw estimates.

        Returns
        -------
        covariance_corrected : ndarray of shape (n_features, n_features)
            Corrected robust covariance estimate.

        References
        ----------
        .. [Croux1999] Influence Function and Efficiency of the Minimum
            Covariance Determinant Scatter Matrix Estimator, 1999, Journal of
            Multivariate Analysis, Volume 71, Issue 2, Pages 161-190
        """

        # Check that the covariance of the support data is not equal to 0.
        # Otherwise self.dist_ = 0 and thus correction = 0.
        n_samples = len(self.dist_)
        n_support = np.sum(self.support_)
        n_features = self.raw_covariance_.shape[0]
        if n_support < n_samples and np.allclose(self.raw_covariance_, 0):
            raise ValueError(
                "The covariance matrix of the support data "
                "is equal to 0, try to increase support_fraction"
            )
        consistency_factor = _consistency_factor(n_features, n_support / n_samples)
        covariance_corrected = self.raw_covariance_ * consistency_factor
        self.dist_ /= consistency_factor
        return covariance_corrected

    def reweight_covariance(self, data):
        """Re-weight raw Minimum Covariance Determinant estimates.

        Re-weight observations using Rousseeuw's method (equivalent to
        deleting outlying observations from the data set before
        computing location and covariance estimates) described
        in [RVDriessen]_.

        Corrects the re-weighted covariance to be consistent at the normal
        distribution, following [Croux1999]_.

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