2

I am using a python package for multiple correspondence analysis on multiple categorical variable. I am studying a set geological data, here is a sample preview:

    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 - not present, 1 - present in very small (trace) amounts, 2 - present in small amount, 3 - present in medium amount, 4- present in abundant amounts.

my code is as follow:

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__)

However I am receiving an error stating:

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

I am suspecting that mca is only limited to dichotomous dummy variables.

I also tried to transform each dummy variable into separate columns by using

x = pd.get_dummies(x)

but to no avail, I am still getting the same error.

Note that I do not want to use PCA because of obvious reasons.

I also used another python package called prince and I tried the example found in the documentation, unfortunately I am also receiving an error:

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

Any advice?

Gerard
  • 518
  • 4
  • 19

2 Answers2

2

I'm not sure about the first, but the second error is likely because prince is a python3-only package which doesn't support python 2.

Brian Bloniarz
  • 411
  • 4
  • 3
2

I am using python 3 and the mca-library. You should create an indicator matrix and perform the MCA on that matrix, the class mca has a dummy function:

dummy(DF, cols=None)

then you can use it as:

x_dummy = mca.dummy(x)
mca_ben = mca.mca(x_dummy) 
KenHBS
  • 6,756
  • 6
  • 37
  • 52