TypeError: '>=' not supported between instances of 'str' and 'int' 利用PCA报错解决

CA为主成分分析库

导入方式:from sklearn.decomposition import PCA

其中默认有三个主要参数:


n_components

此参数可以帮我们指定希望PCA降维后的特征维度数目,可以是int型的数字123,也可以是阈值百分比,类似98%,也可以指定为string类型,MLE


copy

类型:bool,True或者False,缺省时默认为True,
意义:表示是否在运行算法时,将原始数据复制一份。如果为True,则运行PCA算法后,原始数据的值不会有任何改变。因为是在原始数据的副本上进行运算的。


whiten

类型:bool,缺省时默认为False
意义:白化,目的是每个特征具有相同的方差。


svd_solver

指定奇异值分解SVD的方法,有4个可以选择的值:{‘auto’, ‘full’, ‘arpack’, ‘randomized’,}具体详见【http://www.cnblogs.com/pinard/p/6243025.html

但是在pca = PCA(n_components = ‘mle’)(MLE即极大似然估计)时报错

TypeError: ‘>=’ not supported between instances of ‘str’ and ‘int’

通过查看help(PCA)发现,当n_components == ‘mle’时,需要和参数svd_solver一起使用,且svd_solver需要选择full参数


即pca = PCA(n_components = ‘mle’,svd_solver=’full’)才可执行成功

猜你喜欢

转载自blog.csdn.net/qq_32811489/article/details/81068626