【发布时间】:2017-05-17 05:04:32
【问题描述】:
我正在使用python package 对多个分类变量进行多重对应分析。我正在研究一组地质数据,这里是一个示例预览:
Quartz Oxides Hematite Limonite Geothite Clay Soil_Type
1 2 3 4 1 0 A
2 1 4 3 0 1 B
3 4 2 1 4 0 A
4 3 1 2 0 3 C
0 2 3 4 1 2 D
1 0 2 4 3 4 C
0 - 不存在,1 - 极少量(痕量)存在,2 - 少量存在,3 - 中等量存在,4- 大量存在。
我的代码如下:
geology = pd.read_csv('geology_data.csv')
x = geology[['RigNumber','Quartz','Oxides','Hematite','Limonite','Geothite','Clay']].fillna(0)
y = geology[['Soil_Type']]
print 'Dimensionality Reduction'
mca_ben = mca.mca(x)
print mca_ben
mca_ind = mca.mca(x, benzecri=False)
print mca_ind
print(mca.MCA.__doc__)
但是我收到一条错误消息:
Traceback (most recent call last):
File "C:\Users\root\Desktop\Data\raw data\new raw\merged wit npt\multiclass without productive\parameter propagation\New Predict\clustering-mca.py", line 33, in <module>
mca_ben = mca.mca(x, ncols=31)
File "C:\Users\root\AppData\Roaming\Python\Python27\site-packages\mca.py", line 47, in __init__
self.D_r = numpy.diag(1/numpy.sqrt(self.r))
File "C:\Python27\lib\site-packages\numpy\lib\twodim_base.py", line 302, in diag
res = zeros((n, n), v.dtype)
MemoryError
我怀疑 mca 只限于二分虚拟变量。
我还尝试通过使用将每个虚拟变量转换为单独的列
x = pd.get_dummies(x)
但无济于事,我仍然遇到同样的错误。
请注意,我不想使用PCA because of obvious reasons.
我还使用了另一个名为prince 的python 包,并尝试了documentation 中的示例,不幸的是我也收到了错误:
Traceback (most recent call last):
File "C:\Users\root\Desktop\Data\raw data\new raw\merged wit npt\multiclass without productive\parameter propagation\New Predict\clustering-mca.py", line 14, in <module>
mca = prince.MCA(df, n_components=-1)
File "C:\Python27\lib\site-packages\prince\mca.py", line 42, in __init__
super(MCA, self).__init__(
TypeError: super() argument 1 must be type, not classobj
有什么建议吗?
【问题讨论】:
标签: python pandas pca dimensionality-reduction