ledoit_wolf_shrinkage#

sklearn.covariance.ledoit_wolf_shrinkage(X, assume_centered=False, block_size=1000)[source]#

Estimate the shrunk Ledoit-Wolf covariance matrix.

Read more in the User Guide.

Parameters:
Xarray-like of shape (n_samples, n_features)

Data from which to compute the Ledoit-Wolf shrunk covariance shrinkage.

assume_centeredbool, default=False

If True, data will not be centered before computation. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, data will be centered before computation.

block_sizeint, default=1000

Size of blocks into which the covariance matrix will be split.

Returns:
shrinkagefloat

Coefficient in the convex combination used for the computation of the shrunk estimate.

Notes

The regularized (shrunk) covariance is:

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

where mu = trace(cov) / n_features

Examples

>>> import numpy as np
>>> from sklearn.covariance import ledoit_wolf_shrinkage
>>> real_cov = np.array([[.4, .2], [.2, .8]])
>>> rng = np.random.RandomState(0)
>>> X = rng.multivariate_normal(mean=[0, 0], cov=real_cov, size=50)
>>> shrinkage_coefficient = ledoit_wolf_shrinkage(X)
>>> shrinkage_coefficient
np.float64(0.23...)