Skip to content

Commit dd5de3c

Browse files
authored
DOC Ensures that LedoitWolf passes numpydoc validation (scikit-learn#20578)
1 parent ded59b5 commit dd5de3c

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

maint_tools/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"LabelBinarizer",
5656
"LabelPropagation",
5757
"LabelSpreading",
58-
"LedoitWolf",
5958
"LinearSVR",
6059
"LocalOutlierFactor",
6160
"LocallyLinearEmbedding",

sklearn/covariance/_shrunk_covariance.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def ledoit_wolf(X, *, assume_centered=False, block_size=1000):
338338

339339

340340
class LedoitWolf(EmpiricalCovariance):
341-
"""LedoitWolf Estimator
341+
"""LedoitWolf Estimator.
342342
343343
Ledoit-Wolf is a particular form of shrinkage, where the shrinkage
344344
coefficient is computed using O. Ledoit and M. Wolf's formula as
@@ -385,22 +385,19 @@ class LedoitWolf(EmpiricalCovariance):
385385
386386
.. versionadded:: 0.24
387387
388-
Examples
388+
See Also
389389
--------
390-
>>> import numpy as np
391-
>>> from sklearn.covariance import LedoitWolf
392-
>>> real_cov = np.array([[.4, .2],
393-
... [.2, .8]])
394-
>>> np.random.seed(0)
395-
>>> X = np.random.multivariate_normal(mean=[0, 0],
396-
... cov=real_cov,
397-
... size=50)
398-
>>> cov = LedoitWolf().fit(X)
399-
>>> cov.covariance_
400-
array([[0.4406..., 0.1616...],
401-
[0.1616..., 0.8022...]])
402-
>>> cov.location_
403-
array([ 0.0595... , -0.0075...])
390+
EllipticEnvelope : An object for detecting outliers in
391+
a Gaussian distributed dataset.
392+
EmpiricalCovariance : Maximum likelihood covariance estimator.
393+
GraphicalLasso : Sparse inverse covariance estimation
394+
with an l1-penalized estimator.
395+
GraphicalLassoCV : Sparse inverse covariance with cross-validated
396+
choice of the l1 penalty.
397+
MinCovDet : Minimum Covariance Determinant
398+
(robust estimator of covariance).
399+
OAS : Oracle Approximating Shrinkage Estimator.
400+
ShrunkCovariance : Covariance estimator with shrinkage.
404401
405402
Notes
406403
-----
@@ -416,6 +413,23 @@ class LedoitWolf(EmpiricalCovariance):
416413
"A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices",
417414
Ledoit and Wolf, Journal of Multivariate Analysis, Volume 88, Issue 2,
418415
February 2004, pages 365-411.
416+
417+
Examples
418+
--------
419+
>>> import numpy as np
420+
>>> from sklearn.covariance import LedoitWolf
421+
>>> real_cov = np.array([[.4, .2],
422+
... [.2, .8]])
423+
>>> np.random.seed(0)
424+
>>> X = np.random.multivariate_normal(mean=[0, 0],
425+
... cov=real_cov,
426+
... size=50)
427+
>>> cov = LedoitWolf().fit(X)
428+
>>> cov.covariance_
429+
array([[0.4406..., 0.1616...],
430+
[0.1616..., 0.8022...]])
431+
>>> cov.location_
432+
array([ 0.0595... , -0.0075...])
419433
"""
420434

421435
def __init__(self, *, store_precision=True, assume_centered=False, block_size=1000):
@@ -425,8 +439,7 @@ def __init__(self, *, store_precision=True, assume_centered=False, block_size=10
425439
self.block_size = block_size
426440

427441
def fit(self, X, y=None):
428-
"""Fit the Ledoit-Wolf shrunk covariance model according to the given
429-
training data and parameters.
442+
"""Fit the Ledoit-Wolf shrunk covariance model to X.
430443
431444
Parameters
432445
----------
@@ -439,6 +452,7 @@ def fit(self, X, y=None):
439452
Returns
440453
-------
441454
self : object
455+
Returns the instance itself.
442456
"""
443457
# Not calling the parent object to fit, to avoid computing the
444458
# covariance matrix (and potentially the precision)

0 commit comments

Comments
 (0)