Covariance estimator with shrinkage
Read more in the :ref:`User Guide <shrunk_covariance>`.
Parameters ---------- store_precision : boolean, default True Specify if the estimated precision is stored
assume_centered : boolean, default False If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False, data will be centered before computation.
shrinkage : float, 0 <= shrinkage <= 1, default 0.1 Coefficient in the convex combination used for the computation of the shrunk estimate.
Attributes ---------- location_ : array-like, shape (n_features,) Estimated location, i.e. the estimated mean.
covariance_ : array-like, shape (n_features, n_features) Estimated covariance matrix
precision_ : array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. (stored only if store_precision is True)
Examples -------- >>> import numpy as np >>> from sklearn.covariance import ShrunkCovariance >>> from sklearn.datasets import make_gaussian_quantiles >>> 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) >>> cov = ShrunkCovariance().fit(X) >>> cov.covariance_ array([0.7387..., 0.2536...],
[0.2536..., 0.4110...]
) >>> cov.location_ array(0.0622..., 0.0193...
)
Notes ----- The regularized covariance is given by:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features