gpt4 book ai didi

python - Sklearn PCA 解释方差和解释方差比差异

转载 作者:行者123 更新时间:2023-12-04 00:25:33 29 4
gpt4 key购买 nike

我正在尝试从特征向量中获取方差。
explained_variance_ratio_有什么区别和 explained_variance_PCA ?

最佳答案

解释方差的 百分比 是:

explained_variance_ratio_

方差 即协方差矩阵的特征值是:
explained_variance_

公式: explained_variance_ratio_ = explained_variance_ / np.sum(explained_variance_)
示例:
import numpy as np
from sklearn.decomposition import PCA
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
pca = PCA(n_components=2)
pca.fit(X)
pca.explained_variance_
array([7.93954312, 0.06045688]) # the actual eigenvalues (variance)

pca.explained_variance_ratio_ # the percentage of the variance
array([0.99244289, 0.00755711])

同样基于上述公式:
7.93954312 / (7.93954312+ 0.06045688) = 0.99244289
从文档:

explained_variance_ : array, shape (n_components,) The amount of variance explained by each of the selected components.

Equal to n_components largest eigenvalues of the covariance matrix of X.

New in version 0.18.

explained_variance_ratio_ : array, shape (n_components,) Percentage of variance explained by each of the selected components.

If n_components is not set then all components are stored and the sum of the ratios is equal to 1.0.

关于python - Sklearn PCA 解释方差和解释方差比差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57293716/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com