python - 带有网格搜索的 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.
解决方案
您的错误消息说明了一切。
ValueError: BaseClassifier in AdaBoostClassifier ensemble is worse than random, ensemble can not be fit.
此错误来自AdaBoostClassifier()
,而不是您的排列测试。您的基础学习器太弱,无法对您的数据进行特定排列,无法为您提供任何有意义的结果。检查您的数据和决策树模型。
推荐阅读
- c# - 对 c# web api 2 RESTful web 服务的 Angular 发布请求
- node.js - REST 和 UDP 服务器之间的通信
- python - Plot.ly/Dash:删除子弹图周围的所有填充
- typescript - 如何定义从抽象类扩展但绝不是顶级抽象类的类型?
- python - 根据实现在 setup.py 脚本中指定其他依赖项(PyPy / CPython 支持)
- reactjs - Meteor Accounts.onEmailVerificationLink 中的 Redux 调度
- java - 在 for 循环期间从 String 和 StringBuilder 列表中删除项目不会给出相同的输出
- javascript - 如何从元素绑定数据Web组件
- c# - 使用 Unity 引擎和 C# 在代码中进行排序和二进制搜索
- c# - 如何在c#中打印出矩形值?