估算器的参数 min_impurity_decrease 无效
Posted
技术标签:
【中文标题】估算器的参数 min_impurity_decrease 无效【英文标题】:Invalid parameter min_impurity_decrease for estimator 【发布时间】:2021-12-24 18:45:45 【问题描述】:DTC = DecisionTreeClassifier(max_depth=15)
RFC = RandomForestClassifier(max_depth=15)
BC = BaggingClassifier(base_estimator=DTC)
ADB = AdaBoostClassifier(base_estimator=DTC)
params =
"n_estimators": [10, 20, 100],
'max_features': [1.0, 2.0, 3.0],
"min_impurity_decrease": [1.0, 2.0, 3.0]
GSC1 = GridSearchCV(estimator=BC, param_grid=params, cv=5)
GSC1.fit(X_Train, Y_Train)
GSC_BC_Score = GSC1.score(X_Test, Y_Test)
Invalid parameter min_impurity_decrease for estimator BaggingClassifier(base_estimator=DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini', max_depth=15, max_features=None, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, min_samples_leaf=1, min_samples_split=2, min_weight_fraction_leaf=0.0,presort='deprecated',
random_state=None, splitter='best'), bootstrap=True, bootstrap_features=False, max_features=1.0, max_samples=1.0, n_estimators=10, n_jobs=None, oob_score=False, random_state=None, verbose=0, warm_start=False).
Check the list of available parameters with estimator.get_params().keys().
【问题讨论】:
【参考方案1】:在您的情况下,您可以检查键,因此对于 DTC 的参数输入,这些具有前缀 base_estimator__
。
BC.get_params().keys()
dict_keys(['base_estimator__ccp_alpha', 'base_estimator__class_weight', 'base_estimator__criterion', 'base_estimator__max_depth', 'base_estimator__max_features', 'base_estimator__max_leaf_nodes', 'base_estimator__min_impurity_decrease', 'base_estimator__min_impurity_split', 'base_estimator__min_samples_leaf', 'base_estimator__min_samples_split', 'base_estimator__min_weight_fraction_leaf', 'base_estimator__random_state', 'base_estimator__splitter', 'base_estimator', 'bootstrap', 'bootstrap_features', 'max_features', 'max_samples', 'n_estimators', 'n_jobs', 'oob_score', 'random_state', 'verbose', 'warm_start'])
因此,在您的情况下,我假设您将 n 个估计器传递给 bagging,然后将其传递给决策树,所以它是这样的:
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import make_classification
DTC = DecisionTreeClassifier(max_depth=15)
BC = BaggingClassifier(base_estimator=DTC)
X,y = make_classification()
params =
"n_estimators": [10, 20, 100],
'base_estimator__max_features': [2, 5, 10],
"base_estimator__min_impurity_decrease": [1.0, 2.0, 3.0]
GSC1 = GridSearchCV(estimator=BC, param_grid=params , cv=5)
GSC1.fit(X, y)
【讨论】:
以上是关于估算器的参数 min_impurity_decrease 无效的主要内容,如果未能解决你的问题,请参考以下文章
如何使用GridSearchCV获取所有模型(每组参数一个)?