在Python中创建一系列PCA对象?
我有一个问题,我想在同一数据集中应用具有不同组件的PCA。
我认为可以创建具有不同组件大小的PCA对象数组,然后以后在数据上使用它们。
但是,当我尝试运行以下代码时,我会遇到错误。
pca_sizes = np.array([10,50,100,250,500])
samples = np.shape(pca_sizes)
for i in range(len(pca_sizes)):
pca_comp[i] = PCA(n_components = pca_sizes[i])
我会收到以下错误
TypeError Traceback (most recent call last)
Input In [50], in <cell line: 3>()
2 samples = np.shape(pca_sizes)
3 for i in range(len(pca_sizes)):
----> 4 pca_comp[i] = PCA(n_components = pca_sizes[i])
TypeError: float() argument must be a string or a number, not 'PCA'
我尝试查找,但是似乎我不太了解阵列是如何工作的,因为我来自C背景。
任何指针都将不胜感激。
谢谢!
I have a problem where I'd like to apply PCA with varying number of components to the same dataset.
I assumed that It was possible to create an array of PCA objects with different component sizes and then use them later on the data.
But, I'm getting an error while I'm trying to run the following code.
pca_sizes = np.array([10,50,100,250,500])
samples = np.shape(pca_sizes)
for i in range(len(pca_sizes)):
pca_comp[i] = PCA(n_components = pca_sizes[i])
and I get the following error
TypeError Traceback (most recent call last)
Input In [50], in <cell line: 3>()
2 samples = np.shape(pca_sizes)
3 for i in range(len(pca_sizes)):
----> 4 pca_comp[i] = PCA(n_components = pca_sizes[i])
TypeError: float() argument must be a string or a number, not 'PCA'
I tried looking up, but it seems like I don't quite understand how arrays work since I'm coming from a C background.
Any pointers would be appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系弄清楚了。显然,我可以使用此三元运算符来生成不同类型,对象,尺寸等的列表。
显然,这也可用于存储具有不同尺寸的多维阵列。
无论如何,我几乎可以很好地理解这一点,以便正确解释其工作原理。
但这将解决我在这里看到的问题。
Nevermind figured it out. Apparently, I can use this ternary operator to generate lists of different types, objects, sizes etc etc.
This apparently can be used to store multi dimensional arrays with varying sizes too.
Anyways, I donot understand this nearly well enough to make proper explanation of how this works.
But this will fix the issue I see here.