Skip to content

DOC Ensures that LedoitWolf passes numpydoc validation #20578

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 2 commits into from
Jul 21, 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 @@ -55,7 +55,6 @@
"LabelBinarizer",
"LabelPropagation",
"LabelSpreading",
"LedoitWolf",
"LinearSVR",
"LocalOutlierFactor",
"LocallyLinearEmbedding",
Expand Down
50 changes: 32 additions & 18 deletions sklearn/covariance/_shrunk_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def ledoit_wolf(X, *, assume_centered=False, block_size=1000):


class LedoitWolf(EmpiricalCovariance):
"""LedoitWolf Estimator
"""LedoitWolf Estimator.

Ledoit-Wolf is a particular form of shrinkage, where the shrinkage
coefficient is computed using O. Ledoit and M. Wolf's formula as
Expand Down Expand Up @@ -385,22 +385,19 @@ class LedoitWolf(EmpiricalCovariance):

.. versionadded:: 0.24

Examples
See Also
--------
>>> import numpy as np
>>> from sklearn.covariance import LedoitWolf
>>> real_cov = np.array([[.4, .2],
... [.2, .8]])
>>> np.random.seed(0)
>>> X = np.random.multivariate_normal(mean=[0, 0],
... cov=real_cov,
... size=50)
>>> cov = LedoitWolf().fit(X)
>>> cov.covariance_
array([[0.4406..., 0.1616...],
[0.1616..., 0.8022...]])
>>> cov.location_
array([ 0.0595... , -0.0075...])
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.
MinCovDet : Minimum Covariance Determinant
(robust estimator of covariance).
OAS : Oracle Approximating Shrinkage Estimator.
ShrunkCovariance : Covariance estimator with shrinkage.

Notes
-----
Expand All @@ -416,6 +413,23 @@ class LedoitWolf(EmpiricalCovariance):
"A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices",
Ledoit and Wolf, Journal of Multivariate Analysis, Volume 88, Issue 2,
February 2004, pages 365-411.

Examples
--------
>>> import numpy as np
>>> from sklearn.covariance import LedoitWolf
>>> real_cov = np.array([[.4, .2],
... [.2, .8]])
>>> np.random.seed(0)
>>> X = np.random.multivariate_normal(mean=[0, 0],
... cov=real_cov,
... size=50)
>>> cov = LedoitWolf().fit(X)
>>> cov.covariance_
array([[0.4406..., 0.1616...],
[0.1616..., 0.8022...]])
>>> cov.location_
array([ 0.0595... , -0.0075...])
"""

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

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

Parameters
----------
Expand All @@ -439,6 +452,7 @@ def fit(self, X, y=None):
Returns
-------
self : object
Returns the instance itself.
"""
# Not calling the parent object to fit, to avoid computing the
# covariance matrix (and potentially the precision)
Expand Down