【问题标题】:sci-kit learn TruncatedSVD explained_variance_ratio_ not in descending order? [duplicate]scikit学习截断的SVD解释_variance_ratio_不是按降序排列? [复制]
【发布时间】:2019-06-22 00:30:45
【问题描述】:

这个问题实际上与this one 重复,但在撰写本文时仍未得到解答。

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

重现行为的代码:

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_

【问题讨论】:

标签: python scikit-learn svd variance


【解决方案1】:

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

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_

【讨论】:

    猜你喜欢
    • 2018-08-15
    • 2016-05-19
    • 2012-03-06
    • 2020-08-27
    • 2015-11-15
    • 1970-01-01
    • 2019-10-22
    • 2021-11-24
    • 2020-09-02
    相关资源
    最近更新 更多