python - 具有 2 个组件的 pca 输出 1 个功能
问题描述
我有一个包含 10 个元素的列表,我选择了 5 个特征来创建我的输入并将输入列表转换为一个数组;然后我应用了组件数=2的pca:
idx = {0, 2, 3, 7, 8}
Input = array([Input[x] for x in idx]).reshape((1, -1))
print (Input.shape) # prints (1, 5)
pca = PCA(n_components=2).fit(Input)
Input = pca.transform(Input)
print (Input.shape) #prints (1, 1)
为什么在 n_components=2 的 pca 之后我的输入形状是 (1,1) 而不是 (1,2) ?
解决方案
是的,这是预期的行为。
根据PCA 的文档:
actual n_components = min(n_samples, specified n_components)
在这里n_samples = 1
(如您在 中所示) ,PCA 返回Input.shape
的实际值为 1。n_components
推荐阅读
- python - 如何从频率表创建 pd.Series?
- typescript - 什么是使用 RxJS 在包含数组的 Observable 上迭代(并应用一些逻辑)的优雅解决方案?
- python - postgres DB 中的大 INSERTS 的 asyncpg 问题
- gps - GPS neo-6m 我需要请求数据吗?
- r - 在r中找到列表中每一行的最大值?
- python - 如何在 PySpark 中使用 RDD 聚合()和 groupBy()找到最大值
- javascript - 使用画布的模糊效果
- spring-batch - Spring Batch:如何将执行上下文放入我的 ItemListenerSupport 类中?
- sql - 如何仅为从事多个项目的员工显示员工姓名和正在从事的项目数量?
- python - 网页抓取时如何搜索部分id?