0

I recently discovered MLARAM classifier by Fernando Benites ; Elena Sapozhnikova. When trying to evaluate this classifier on a set of 11.000 documents. I used updated documentation from http://scikit.ml/api/skmultilearn.adapt.mlaram.html#skmultilearn.adapt.MLARAM and tried:

from skmultilearn.adapt import MLARAM

classifier = MLARAM(threshold=0.05, vigilance=0.95)
classifier.fit(x_train, y_train)
predictions = classifier.predict(x_test)
print(f1_score(y_test, predictions, average='micro'))

But this raises the following error:

KeyError                                  Traceback (most recent call last)
~\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2645             try:
-> 2646                 return self._engine.get_loc(key)
   2647             except KeyError:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 0

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-33-d5080bba579e> in <module>
      2 
      3 classifier = MLARAM(threshold=0.05, vigilance=0.95)
----> 4 classifier.fit(x_train, y_train)
      5 predictions = classifier.predict(x_test)
      6 print(f1_score(y_test, predictions, average='micro'))

C:\Program Files\Python37\lib\site-packages\skmultilearn\adapt\mlaram.py in fit(self, X, y)
    165         X = _normalize_input_space(X)
    166 
--> 167         y_0 = _get_label_vector(y, 0)
    168 
    169         if len(self.neurons) == 0:

C:\Program Files\Python37\lib\site-packages\skmultilearn\adapt\mlaram.py in _get_label_vector(y, i)
     35     if issparse(y):
     36         return numpy.squeeze(numpy.asarray(y[i].todense()))
---> 37     return y[i]
     38 
     39 def _concatenate_with_negation(row):

~\AppData\Roaming\Python\Python37\site-packages\pandas\core\frame.py in __getitem__(self, key)
   2798             if self.columns.nlevels > 1:
   2799                 return self._getitem_multilevel(key)
-> 2800             indexer = self.columns.get_loc(key)
   2801             if is_integer(indexer):
   2802                 indexer = [indexer]

~\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
   2646                 return self._engine.get_loc(key)
   2647             except KeyError:
-> 2648                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2649         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   2650         if indexer.ndim > 1 or indexer.size > 1:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 0

As documentation and discussions about this classifier is very sparse, I cannot figure out what the problem is.

Anyone else encountered issues with MLARAM and could give me a helping hand on this?

Any help appreciated!

Florian Schramm
  • 333
  • 3
  • 15

1 Answers1

0

So basically it was an issue with the lil_matrix. Using a lil_matrix ransformation worked for me. However, to be honest, I have no clue whats the exact reason for that.

from skmultilearn.adapt import MLARAM

# The variables have to be transformed before
x_train_MLARAM = lil_matrix(x_train).toarray()
y_train_MLARAM = lil_matrix(y_train).toarray()
x_test_MLARAM = lil_matrix(x_test).toarray()

classifier = MLARAM(threshold=0.05, vigilance=0.95)
classifier.fit(x_train_MLARAM, y_train_MLARAM)
predictions = classifier.predict(x_test_MLARAM)
print(f1_score(y_test, predictions, average='micro'))

Further information on the lil_matrix can be found here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.lil_matrix.html

Florian Schramm
  • 333
  • 3
  • 15