scikitlearn PCA方法中百分比值的解释

2024-06-28 20:50:48 发布

您现在位置:Python中文网/ 问答频道 /正文

在scikitlearn中,有一个称为PCA的方法。此方法采用百分比参数。This site解释此参数如下:

Notice the code below has .95 for the number of components parameter. It means that scikit-learn choose the minimum number of principal components such that 95% of the variance is retained.

> from sklearn.decomposition import PCA
> # Make an instance of the Model 
> pca = PCA(.95)

我对这个解释的解释有点不知所措。假设PCA的输出如下:

  • PC1解释了70%的完全方差
  • PC2解释了15%的完全方差
  • PC3解释了完全方差的10%
  • PC4解释了完全方差的4%
  • PC5解释了完全方差的1%

PCA(0.71)语句会返回PC1和PC5(因为它们都能准确解释71%的方差),还是会返回PC1和PC2?如果我想检索0.5%的方差,即PCA(0.005)语句将返回哪个PC?在


Tags: ofthe方法number参数thatcomponents语句
2条回答

你会触及一个更为普遍的观点,尽管在实践中经常使用,但很少有人明确提及,甚至在教程和介绍性说明中也没有。虽然我从来没有想过这样的问题,但从初学者的角度来看,这是完全有道理的(初学者通常不受某些惯例的约束,经验丰富的实践者认为这是理所当然的,而且往往他们甚至没有注意到这些惯例……)。在

通常,当我们选择主成分的数量时(例如,用于降维、可视化等),我们选择一个数字k,它隐含的意思是“从PC1开始,按顺序继续,直到(并包括)PCk”。这就是R中caret包的^{}函数背后的原理(也可以说是在任何软件包中执行类似任务的所有函数的后面)。在

换言之,至少据我所知,在你所描述的这种情况下,我们从不通过“切利采摘”来选择PC(例如,以PC2、PC4和PC5为例)。相反,我们总是选择一个k < n(这里是n=5),然后我们继续获取所有第一个k的PC,即从PC1开始。在

documentation说明了0 < n_components < 1的情况:

if 0 < n_components < 1 and svd_solver == 'full',

select the number of components such that the amount of variance that needs to be explained is greater than the percentage specified by n_components.

如果你提到这样的话,你会更清楚:

if 0 < n_components < 1 and svd_solver == 'full',

select the minimum number of components from the sorted list (descending order) according to their respective explained variance values such that the amount of variance that needs to be explained is greater than the percentage specified by n_components

这样就不会有歧义了。在

之后:

PCA(0.71)将返回PC1和PC2

PCA(0.005)-(不太可能的情况)将返回PC1

相关问题 更多 >