gpt4 book ai didi

scikit-learn - 如何获得具有所有极端方差的 PCA 所需的组件数量?

转载 作者:行者123 更新时间:2023-12-04 07:36:20 26 4
gpt4 key购买 nike

我正在尝试获取用于分类的组件数量。我读过类似的问题 Finding the dimension with highest variance using scikit-learn PCA以及关于此的 scikit 文档:

http://scikit-learn.org/dev/tutorial/statistical_inference/unsupervised_learning.html#principal-component-analysis-pca

但是,这仍然没有解决我的问题。我所有的 PCA 组件都非常大,因此我可以选择所有这些组件,但如果我这样做,PCA 将毫无用处。

我还阅读了 scikit learn 中的 PCA 库
http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
这表明L:

if n_components == ‘mle’, Minka’s MLE is used to guess the dimension if 0 < n_components < 1, 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



但是,我找不到有关使用此技术分析 PCA 的 n_components 的更多信息

这是我的PCA分析代码:
from sklearn.decomposition import PCA
pca = PCA()
pca.fit(x_array_train)
print(pca.explained_variance_)

结果:
   [  6.58902714e+50   6.23266555e+49   2.93568652e+49   2.25418736e+49
1.10063872e+49 3.25107359e+40 4.72113817e+39 1.40411862e+39
4.03270198e+38 1.60662882e+38 3.20028861e+28 2.35570241e+27
1.54944915e+27 8.05181151e+24 1.42231553e+24 5.05155955e+23
2.90909468e+23 2.60339206e+23 1.95672973e+23 1.22987336e+23
9.67133111e+22 7.07208772e+22 4.49067983e+22 3.57882593e+22
3.03546737e+22 2.38077950e+22 2.18424235e+22 1.79048845e+22
1.50871735e+22 1.35571453e+22 1.26605081e+22 1.04851395e+22
8.88191944e+21 6.91581346e+21 5.43786989e+21 5.05544020e+21
4.33110823e+21 3.18309135e+21 3.06169368e+21 2.66513522e+21
2.57173046e+21 2.36482212e+21 2.32203521e+21 2.06033130e+21
1.89039408e+21 1.51882514e+21 1.29284842e+21 1.26103770e+21
1.22012185e+21 1.07857244e+21 8.55143095e+20 4.82321416e+20
2.98301261e+20 2.31336276e+20 1.31712446e+20 1.05253795e+20
9.84992112e+19 8.27574150e+19 4.66007620e+19 4.09687463e+19
2.89855823e+19 2.79035170e+19 1.57015298e+19 1.39218538e+19
1.00594159e+19 7.31960049e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.29043685e+18 5.29043685e+18 5.29043685e+18
5.29043685e+18 5.24952686e+18 2.09685699e+18 4.16588190e+17]

我试过 PCA(n_components = 'mle') 但是我得到了这些错误..
    Traceback (most recent call last):
File "xx", line 166, in <module>
pca.fit(x_array_train)
File "xx", line 225, in fit
self._fit(X)
File "/Users/lib/python2.7/site-packages/sklearn/decomposition/pca.py", line 294, in _fit
n_samples, n_features)
File "/Users/lib/python2.7/site-packages/sklearn/decomposition/pca.py", line 98, in _infer_dimension_
ll[rank] = _assess_dimension_(spectrum, rank, n_samples, n_features)
File "/Users/lib/python2.7/site-packages/sklearn/decomposition/pca.py", line 83, in _assess_dimension_
(1. / spectrum_[j] - 1. / spectrum_[i])) + log(n_samples)
ValueError: math domain error

真的很感激任何帮助......

最佳答案

我没有使用 Python ,但我在 C++ 做了一些你需要的事情& opencv .希望您成功将其转换为任何语言。

// choose how many eigenvectors you want:
int nEigensOfInterest = 0;
float sum = 0.0;
for (int i = 0; i < mEiVal.rows; ++i)
{
sum += mEiVal.at<float>(i, 0);
if (((sum * 100) / (sumOfEigens)) > 80)
{
nEigensOfInterest = i;
break;
}
}
logfile << "No of Eigens of interest: " << nEigensOfInterest << std::endl << std::endl;

基本思想是决定您需要继续使用的“任何 %”组件。我选择了那些 80 . mEiVal是按降序排序的特征值的列矩阵。 sumOfEigens是所有特征值的总和。

我没有 scikit-learn 的经验,请告诉我,我会删除答案。

关于scikit-learn - 如何获得具有所有极端方差的 PCA 所需的组件数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30802444/

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