ledoit_wolf_shrinkage#

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

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

阅读更多的 User Guide .

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

计算Ledoit-Wolf缩小协方差收缩的数据。

assume_centered布尔,默认=假

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

block_sizeint,默认=1000

协方差矩阵将被拆分成的块的大小。

返回:
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 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...)