sci-kit 学习 TruncatedSVD 解释_variance_ratio_ 不是降序排列? [英] sci-kit learn TruncatedSVD explained_variance_ratio_ not in descending order?

查看:37
本文介绍了sci-kit 学习 TruncatedSVD 解释_variance_ratio_ 不是降序排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题实际上是这个问题的重复,但在撰写本文时仍未得到答复.

This question is actually a duplicate of this one, which however remains unanswered at the time of writing.

为什么来自 TruncatedSVDexplained_variance_ratio_ 不像来自 PCA 那样按降序排列?根据我的经验,列表的第一个元素似乎总是最低的,然后在第二个元素处,该值向上跳,然后从那里按降序排列.为什么 explained_variance_ratio_[0] explained_variance_ratio_[1] ( > explained_variance_ratio_[2] > explained_variance_ratio_[3] ...)?这是否意味着第二个组件"实际上解释了最大的差异(不是第一个)?

Why is the explained_variance_ratio_ from TruncatedSVD not in descending order like it would be from PCA? In my experience it seems that the first element of the list is always the lowest, and then at the second element the value jumps up and then goes in descending order from there. Why is explained_variance_ratio_[0] < explained_variance_ratio_[1] ( > explained_variance_ratio_[2] > explained_variance_ratio_[3] ...)? Does this mean the second "component" actually explains the most variance (not the first)?

重现行为的代码:

from sklearn.decomposition import TruncatedSVD

n_components = 50
X_test = np.random.rand(50,100)

model = TruncatedSVD(n_components=n_components, algorithm = 'randomized')
model.fit_transform(X_test)
model.explained_variance_ratio_

推荐答案

如果你先缩放数据,那么我认为解释的方差比率将按降序排列:

If you scale the data first, then I think the explained variance ratios will be in descending order:

from sklearn.decomposition import TruncatedSVD
from sklearn.preprocessing import StandardScaler

n_components = 50
X_test = np.random.rand(50,100)

scaler = StandardScaler()
X_test = scaler.fit_transform(X_test)

model = TruncatedSVD(n_components=n_components, algorithm = 'randomized')
model.fit_transform(X_test)
model.explained_variance_ratio_

这篇关于sci-kit 学习 TruncatedSVD 解释_variance_ratio_ 不是降序排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆