Python 在pyscripter中使用内置函数(PCA)
有人能建议如何使用pyscripter中的PCA内置函数吗。首先,我导入了pcaPython 在pyscripter中使用内置函数(PCA),python,pca,pyscripter,Python,Pca,Pyscripter,有人能建议如何使用pyscripter中的PCA内置函数吗。首先,我导入了pca from matplotlib.mlab import PCA 然后是代码区 results = PCA(arr1) print("-----------------------PCA-----------------------") print(results) 其中arr1是从文件读取的数据集(数字)。但我得到的属性错误为: Traceback (most recent call last): File
from matplotlib.mlab import PCA
然后是代码区
results = PCA(arr1)
print("-----------------------PCA-----------------------")
print(results)
其中arr1是从文件读取的数据集(数字)。但我得到的属性错误为:
Traceback (most recent call last):
File "C:\Users\pooja\Documents\project\traingsom.py", line 282, in <module>
results = PCA(arr1)
File "C:\Python27\lib\site-packages\matplotlib\mlab.py", line 845, in __init__
n, m = a.shape
AttributeError: 'list' object has no attribute 'shape'
回溯(最近一次呼叫最后一次):
文件“C:\Users\pooja\Documents\project\traingsom.py”,第282行,在
结果=主成分分析(arr1)
文件“C:\Python27\lib\site packages\matplotlib\mlab.py”,第845行,在\uuu init中__
n、 m=a.形状
AttributeError:“列表”对象没有属性“形状”
请帮助..在mlab的源代码中,它说“
*a*:一个numobervations x numdims数组
”。
您应该这样使用它:
import numpy as np
from matplotlib.mlab import PCA
dataMatrix = np.array(aListOfLists) # Convert a list-of-lists into a numpy array. aListOfLists is the data points in a regular list-of-lists type matrix.
myPCA = PCA(dataMatrix) # make a new PCA object from a numpy array object
希望有帮助。:) 谢谢。我修改了,但现在的错误是:回溯(最近一次调用):文件“C:\Users\pooja\Documents\project\pca.py”,第37行,在myPCA=pca(数据矩阵)文件“C:\Python27\lib\site packages\matplotlib\mlab.py”中,第845行,在init n中,m=a。形状值错误:需要超过1个值才能解包。。。。。。。。。。。。我想知道PCA的内置函数是否能进行所有的均值、协方差等计算too@Devi似乎不是。你必须先让para通过右边。