[英]TypeError: PCA() got an unexpected keyword argument 'n_components'
Hi I was trying to implement the PCA(), but I'm getting an error, '嗨,我正在尝试实现 PCA(),但出现错误,'
TypeError: PCA() got an unexpected keyword argument 'n_components'.类型错误:PCA() 得到了一个意外的关键字参数“n_components”。
from sklearn.decomposition import PCA
#Principal component analysis
def PCA(X,Y):
pca = PCA(n_components=2)
X = pca.fit_transform(X)
plot_2d_space(X, Y, 'Imbalanced dataset (2 PCA components)')
Can someone please tell me a possible reason for this有人可以告诉我一个可能的原因吗
First you are importing from sklearn.decomposition import PCA
and then you're using same name for your function def PCA
首先,您from sklearn.decomposition import PCA
,然后您的函数def PCA
使用相同的名称
So next time you'll call the function, it will call your function not from the scikit-learn
function.因此,下次您调用该函数时,它将不会从scikit-learn
函数中调用您的函数。
So basically pca = PCA(n_components=2)
expects the arguments X and Y where you're passing n_components
.所以基本上pca = PCA(n_components=2)
期望参数 X 和 Y 传递n_components
。
Solution :解决方案:
Change the name of your function and it should work:更改函数的名称,它应该可以工作:
def PCA_2(X,Y):
pca = PCA(n_components=2)
X = pca.fit_transform(X)
plot_2d_space(X, Y, 'Imbalanced dataset (2 PCA components)')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.