Multi-Label classification with GridSearch in StackingCVClassifier

147 views
Skip to first unread message

Bert Carremans

unread,
Feb 1, 2019, 2:43:13 AM2/1/19
to mlxtend
Hi, 

I am trying to fit a multi-class classification. For that I have a file of 50K rows and 26 target (binary) variables.
The explanatory variables are in an array with dimensions (50K, 324).

The code is the following:

rf1 = RandomForestClassifier()
rf2 = RandomForestClassifier()

np.random.seed(123456)
sclf = StackingCVClassifier(classifiers=[rf1],
                            use_probas=True,
                            meta_classifier=rf2,
                            verbose=0)

params = {'randomforestclassifier__n_estimators': [5, 10],
          'meta-randomforestclassifier__n_estimators': [5, 10]}

grid = GridSearchCV(estimator=sclf, 
                    param_grid=params, 
                    cv=3,
                    refit=True)
grid.fit(X_train.values, y_train.values)

cv_keys = ('mean_test_score', 'std_test_score', 'params')

for r, _ in enumerate(grid.cv_results_['mean_test_score']):
    print("%0.3f +/- %0.2f %r"
          % (grid.cv_results_[cv_keys[0]][r],
             grid.cv_results_[cv_keys[1]][r] / 2.0,
             grid.cv_results_[cv_keys[2]][r]))

print('Best parameters: %s' % grid.best_params_)
print('Accuracy: %.2f' % grid.best_score_)


When I want to apply a GridSearch with the StackingCVClassifier, I get the following error.

~/.local/lib/python3.6/site-packages/mlxtend/classifier/stacking_cv_classification.py in fit(self, X, y, groups, sample_weight)
    204                 single_model_prediction = np.array([]).reshape(0, 1)
    205             else:
--> 206                 single_model_prediction = np.array([]).reshape(0, len(set(y)))
    207
    208             for num, (train_index, test_index) in enumerate(skf):

TypeError: unhashable type: 'numpy.ndarray'


Is it possible to do muti-label classification with StackingCVClassifier?

Thanks!
Reply all
Reply to author
Forward
0 new messages