shrinkage
: float, default=0.1
Coefficient in the convex combination used for the computation
of the shrunk estimate. Range is [0, 1].
Returns:
- shrunk_cov : ndarray of shape (…, n_features, n_features)
Shrunk covariance matrices.
Notes
The regularized (shrunk) covariance is given by:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features.
Examples
import numpy as np
from sklearn.datasets import make_gaussian_quantiles
from sklearn.covariance import empirical_covariance, shrunk_covariance
real_cov = np.array([[.8, .3], [.3, .4]])
rng = np.random.RandomState(0)
X = rng.multivariate_normal(mean=[0, 0], cov=real_cov, size=500)
shrunk_covariance(empirical_covariance(X))
array([[0.739, 0.254],
[0.254, 0.411]])