首页 > 解决方案 > 带有网格搜索的 AdaBoost 不能使用 permutation_test_score

问题描述

我正在尝试针对随机机会评估我的 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.

标签: pythonscikit-learnadaboost

解决方案


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

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

此错误来自AdaBoostClassifier(),而不是您的排列测试。您的基础学习器太弱,无法对您的数据进行特定排列,无法为您提供任何有意义的结果。检查您的数据和决策树模型。


推荐阅读