ledoit_wolf#

sklearn.covariance.ledoit_wolf(X, *, assume_centered=False, block_size=1000)[源代码]#

估计缩小的Ledoit-Wolf协方差矩阵。

阅读更多的 User Guide .

参数:
X形状类似阵列(n_samples,n_features)

计算协方差估计值的数据。

assume_centered布尔,默认=假

如果为True,则数据在计算前不会集中。对于处理均值明显等于零但不完全为零的数据很有用。如果为假,则在计算之前将数据集中。

block_sizeint,默认=1000

协方差矩阵将被拆分成的块的大小。这纯粹是内存优化,不影响结果。

返回:
shrunk_cov形状的nd数组(n_features,n_features)

缩小协方差。

shrinkage浮子

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

注意到

正规化(缩小)协方差是:

(1 -收缩) * cov + shrinkage * mo * NP. identification(n_features)

其中μ = Trace(cov)/ n_features

示例

>>> import numpy as np
>>> from sklearn.covariance import empirical_covariance, ledoit_wolf
>>> 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)
>>> covariance, shrinkage = ledoit_wolf(X)
>>> covariance
array([[0.44..., 0.16...],
       [0.16..., 0.80...]])
>>> shrinkage
np.float64(0.23...)