带有gridsearch的AdaBoost不能使用permutation_test_score

时间:2019-10-24 20:50:41

标签: python scikit-learn adaboost

我正在尝试针对随机机会评估AdaBoosted决策树的性能。

dcf = AdaBoostClassifier(DecisionTreeClassifier(max_depth=2,  
max_features="auto", min_samples_split=3, 
min_samples_leaf=14), 
algorithm="SAMME",random_state=123)
clf = GridSearchCV(dcf, param_grid, scoring='accuracy', cv=5)

clf.fit(train_dat, train_labels)

但是,当我要添加排列测试时:

score, permutation_scores, pvalue = permutation_test_score(
clf.best_estimator_, test_dat,test_labels, scoring="accuracy", cv=5, n_permutations=600, n_jobs=1)

我的错误是:

Traceback (most recent call last):
  File "adaboost-test.py", line 99, in <module>
    clf.best_estimator_, test_dat,test_labels, scoring="accuracy", cv=5, n_permutations=600, n_jobs=1)
  File "/usr/local/lib/python3.5/dist-packages/sklearn/model_selection/_validation.py", line 1092, in permutation_test_score
    score = _permutation_test_score(clone(estimator), X, y, groups, cv, scorer)
  File "/usr/local/lib/python3.5/dist-packages/sklearn/model_selection/_validation.py", line 1109, in _permutation_test_score
    estimator.fit(X_train, y_train)
  File "/usr/local/lib/python3.5/dist-packages/sklearn/ensemble/weight_boosting.py", line 427, in fit
    return super().fit(X, y, sample_weight)
  File "/usr/local/lib/python3.5/dist-packages/sklearn/ensemble/weight_boosting.py", line 150, in fit
    random_state)
  File "/usr/local/lib/python3.5/dist-packages/sklearn/ensemble/weight_boosting.py", line 490, in _boost
    random_state)
  File "/usr/local/lib/python3.5/dist-packages/sklearn/ensemble/weight_boosting.py", line 579, in _boost_discrete
    raise ValueError('BaseClassifier in AdaBoostClassifier '
ValueError: BaseClassifier in AdaBoostClassifier ensemble is worse than random, ensemble can not be fit.

1 个答案:

答案 0 :(得分:0)

您的错误消息说明了一切。

ValueError: BaseClassifier in AdaBoostClassifier ensemble is worse than random, ensemble can not be fit.

此错误来自AdaBoostClassifier(),而不是您的排列测试。您的基础学习者对于数据的某些排列过于虚弱,无法给您任何有意义的结果。检查您的数据和决策树模型。