Skip to content

DOC Ensures that ShrunkCovariance passes numpydoc validation #20571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
"SelectPercentile",
"SelfTrainingClassifier",
"SequentialFeatureSelector",
"ShrunkCovariance",
"SimpleImputer",
"SkewedChi2Sampler",
"SparseCoder",
Expand Down
38 changes: 26 additions & 12 deletions sklearn/covariance/_shrunk_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def shrunk_covariance(emp_cov, shrinkage=0.1):


class ShrunkCovariance(EmpiricalCovariance):
"""Covariance estimator with shrinkage
"""Covariance estimator with shrinkage.

Read more in the :ref:`User Guide <shrunk_covariance>`.

Parameters
----------
store_precision : bool, default=True
Specify if the estimated precision is stored
Specify if the estimated precision is stored.

assume_centered : bool, default=False
If True, data will not be centered before computation.
Expand Down Expand Up @@ -97,6 +97,28 @@ class ShrunkCovariance(EmpiricalCovariance):

.. versionadded:: 0.24

See Also
--------
EllipticEnvelope : An object for detecting outliers in
a Gaussian distributed dataset.
EmpiricalCovariance : Maximum likelihood covariance estimator.
GraphicalLasso : Sparse inverse covariance estimation
with an l1-penalized estimator.
GraphicalLassoCV : Sparse inverse covariance with cross-validated
choice of the l1 penalty.
LedoitWolf : LedoitWolf Estimator.
MinCovDet : Minimum Covariance Determinant
(robust estimator of covariance).
OAS : Oracle Approximating Shrinkage Estimator.

Notes
-----
The regularized covariance is given by:

(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)

where mu = trace(cov) / n_features

Examples
--------
>>> import numpy as np
Expand All @@ -114,14 +136,6 @@ class ShrunkCovariance(EmpiricalCovariance):
[0.2536..., 0.4110...]])
>>> cov.location_
array([0.0622..., 0.0193...])

Notes
-----
The regularized covariance is given by:

(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)

where mu = trace(cov) / n_features
"""

def __init__(self, *, store_precision=True, assume_centered=False, shrinkage=0.1):
Expand All @@ -131,8 +145,7 @@ def __init__(self, *, store_precision=True, assume_centered=False, shrinkage=0.1
self.shrinkage = shrinkage

def fit(self, X, y=None):
"""Fit the shrunk covariance model according to the given training data
and parameters.
"""Fit the shrunk covariance model to X.

Parameters
----------
Expand All @@ -146,6 +159,7 @@ def fit(self, X, y=None):
Returns
-------
self : object
Returns the instance itself.
"""
X = self._validate_data(X)
# Not calling the parent object to fit, to avoid a potential
Expand Down