gallantlab / pyrcca

Regularized kernel canonical correlation analysis in Python
Other
241 stars 73 forks source link

Still not working on Python2 #7

Closed kimrants closed 6 years ago

kimrants commented 6 years ago

Dear,

After your advice to install Python2 rather than Python3, I can still not get the package to work.

When running:

# Initialize a cca object as an instantiation of the CCACrossValidate class.
ccaCV = rcca.CCACrossValidate(kernelcca=False, numCCs = [1, 2, 3, 4], regs = [0.5, 0.1, 1e2, 1e4])

# Use the train() and validate() methods to run the analysis and perform cross-dataset prediction.
ccaCV.train([TCIA_train, TCGA_train], False)
testcorrsCV = ccaCV.validate([TCIA_test, TCGA_test])

I get this error-log, which I have no idea how to debug:


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-31-c44a925b202d> in <module>()
      3 
      4 # Use the train() and validate() methods to run the analysis and perform cross-dataset prediction.
----> 5 ccaCV.train([TCIA_train, TCGA_train], False)
      6 testcorrsCV = ccaCV.validate([TCIA_test, TCGA_test])

/Users/kimrants/PycharmProjects/thesis_code/Thesis_code/Packages/rcca.pyc in train(self, data, parallel)
    171                             kernelcca=self.kernelcca, ktype=self.ktype,
    172                             gausigma=self.gausigma, degree=self.degree,
--> 173                             cutoff=self.cutoff, selection=selection)
    174                         running_corr_mean_sum += fold_corr_mean
    175 

/Users/kimrants/PycharmProjects/thesis_code/Thesis_code/Packages/rcca.pyc in train_cvfold(data, reg, numCC, kernelcca, ktype, gausigma, degree, cutoff, selection)
    202                 for ind in chunk]
    203     notheldinds = list(set(range(nT)) - set(heldinds))
--> 204     comps = kcca([d[notheldinds] for d in data], reg, numCC,
    205                  kernelcca=kernelcca, ktype=ktype,
    206                  gausigma=gausigma, degree=degree)

/Users/kimrants/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/pandas/core/frame.pyc in __getitem__(self, key)
   2680         if isinstance(key, (Series, np.ndarray, Index, list)):
   2681             # either boolean or fancy integer index
-> 2682             return self._getitem_array(key)
   2683         elif isinstance(key, DataFrame):
   2684             return self._getitem_frame(key)

/Users/kimrants/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/pandas/core/frame.pyc in _getitem_array(self, key)
   2724             return self._take(indexer, axis=0)
   2725         else:
-> 2726             indexer = self.loc._convert_to_indexer(key, axis=1)
   2727             return self._take(indexer, axis=1)
   2728 

/Users/kimrants/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis, is_setter)
   1325                 if mask.any():
   1326                     raise KeyError('{mask} not in index'
-> 1327                                    .format(mask=objarr[mask]))
   1328 
   1329                 return com._values_from_object(indexer)

KeyError: '[ 0  1  4  5  7  8  9 11 12 14 15 16 17 18 19 20 21 22 23 24 25 28 29 31\n 32 33 34 35 36 37 38 39 41 42 43 44] not in index'

I really hope you can help.

nbilenko commented 6 years ago

Hi, are you working with pandas dataframes? Pyrcca expects data to be a list of numpy arrays.

kimrants commented 6 years ago

Hi Natalia,

Thank you!

This solved the immediate issue :)

/ Kim

nbilenko commented 6 years ago

Great!