From f07f67cc5872ff56062d1d4709ae78ebaaa1f934 Mon Sep 17 00:00:00 2001 From: genvalen Date: Tue, 20 Jul 2021 22:09:37 -0400 Subject: [PATCH 1/2] Remove LedoitWolf from DOCSTRING_IGNORE_LIST. --- maint_tools/test_docstrings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/maint_tools/test_docstrings.py b/maint_tools/test_docstrings.py index 9c270ccbe6783..e7e33bab286a1 100644 --- a/maint_tools/test_docstrings.py +++ b/maint_tools/test_docstrings.py @@ -55,7 +55,6 @@ "LabelBinarizer", "LabelPropagation", "LabelSpreading", - "LedoitWolf", "LinearSVR", "LocalOutlierFactor", "LocallyLinearEmbedding", From 53e3bb58fdb5db991e50d1667a6be267a1bff829 Mon Sep 17 00:00:00 2001 From: genvalen Date: Tue, 20 Jul 2021 22:36:58 -0400 Subject: [PATCH 2/2] Ensure LedoitWolf passes numpydoc validation. --- sklearn/covariance/_shrunk_covariance.py | 50 +++++++++++++++--------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/sklearn/covariance/_shrunk_covariance.py b/sklearn/covariance/_shrunk_covariance.py index 1e2e612852309..5e6e00008eda5 100644 --- a/sklearn/covariance/_shrunk_covariance.py +++ b/sklearn/covariance/_shrunk_covariance.py @@ -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 @@ -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 ----- @@ -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): @@ -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 ---------- @@ -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)