我正在使用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
有什么建议吗?
最佳答案
我不确定第一个错误,但第二个错误可能是因为 Prince 是一个仅包含 python3 的包,不支持 python 2。
关于python - 使用 mca 和 Prince 模块在 Python 中使用非二进制分类虚拟变量进行多重对应分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44016017/