Skip to content

Commit 882cbda

Browse files
genvalenglemaitre
andauthored
DOC Ensures that ShrunkCovariance passes numpydoc validation (scikit-learn#20571)
Co-authored-by: Guillaume Lemaitre <[email protected]>
1 parent 0a7e9ee commit 882cbda

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

maint_tools/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
"SelectPercentile",
129129
"SelfTrainingClassifier",
130130
"SequentialFeatureSelector",
131-
"ShrunkCovariance",
132131
"SimpleImputer",
133132
"SkewedChi2Sampler",
134133
"SparseCoder",

sklearn/covariance/_shrunk_covariance.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ def shrunk_covariance(emp_cov, shrinkage=0.1):
6161

6262

6363
class ShrunkCovariance(EmpiricalCovariance):
64-
"""Covariance estimator with shrinkage
64+
"""Covariance estimator with shrinkage.
6565
6666
Read more in the :ref:`User Guide <shrunk_covariance>`.
6767
6868
Parameters
6969
----------
7070
store_precision : bool, default=True
71-
Specify if the estimated precision is stored
71+
Specify if the estimated precision is stored.
7272
7373
assume_centered : bool, default=False
7474
If True, data will not be centered before computation.
@@ -97,6 +97,28 @@ class ShrunkCovariance(EmpiricalCovariance):
9797
9898
.. versionadded:: 0.24
9999
100+
See Also
101+
--------
102+
EllipticEnvelope : An object for detecting outliers in
103+
a Gaussian distributed dataset.
104+
EmpiricalCovariance : Maximum likelihood covariance estimator.
105+
GraphicalLasso : Sparse inverse covariance estimation
106+
with an l1-penalized estimator.
107+
GraphicalLassoCV : Sparse inverse covariance with cross-validated
108+
choice of the l1 penalty.
109+
LedoitWolf : LedoitWolf Estimator.
110+
MinCovDet : Minimum Covariance Determinant
111+
(robust estimator of covariance).
112+
OAS : Oracle Approximating Shrinkage Estimator.
113+
114+
Notes
115+
-----
116+
The regularized covariance is given by:
117+
118+
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
119+
120+
where mu = trace(cov) / n_features
121+
100122
Examples
101123
--------
102124
>>> import numpy as np
@@ -114,14 +136,6 @@ class ShrunkCovariance(EmpiricalCovariance):
114136
[0.2536..., 0.4110...]])
115137
>>> cov.location_
116138
array([0.0622..., 0.0193...])
117-
118-
Notes
119-
-----
120-
The regularized covariance is given by:
121-
122-
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
123-
124-
where mu = trace(cov) / n_features
125139
"""
126140

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

133147
def fit(self, X, y=None):
134-
"""Fit the shrunk covariance model according to the given training data
135-
and parameters.
148+
"""Fit the shrunk covariance model to X.
136149
137150
Parameters
138151
----------
@@ -146,6 +159,7 @@ def fit(self, X, y=None):
146159
Returns
147160
-------
148161
self : object
162+
Returns the instance itself.
149163
"""
150164
X = self._validate_data(X)
151165
# Not calling the parent object to fit, to avoid a potential

0 commit comments

Comments
 (0)