假设我已经定义了这样一个回归器
tree = MultiOutputRegressor(DecisionTreeRegressor(random_state=0))
tree.fit(X_train, y_train)
现在我想做一个网格交叉验证来优化参数ccp_alpha
(我不知道它是否是优化的最佳参数,但我以它为例)。因此,我这样做:
alphas = np.arange(0,2,0.1)
pipe_tree = Pipeline(steps=[('scaler', scaler), ('pca', pca), ('tree', tree)], memory = 'tmp')
treeCV = GridSearchCV(pipe_tree, dict( pca__n_components=n_components, tree__ccp_alpha=alphas ), cv=5, scoring ='r2', n_jobs=-1)
start_time = time.time()
treeCV.fit(X_train, y_train)
问题是,我认为这个问题:
ValueError: Invalid parameter ccp_alpha for estimator Pipeline(memory='tmp',
steps=[('scaler', StandardScaler()), ('pca', PCA()),
('tree',
MultiOutputRegressor(estimator=DecisionTreeRegressor(random_state=0)))]). Check the list of available parameters with `estimator.get_params().keys()`.
如果我使用命令tree.get_params().keys()
,它将打印一个可能要在模型中更改的参数列表。我认为问题在于GridSearchCV()
命令中的这个tree__ccp_alpha=alphas
。但无论我做什么改变,都是行不通的
我不确定你的帖子里有什么内容,但它似乎是你决策树顶端的一个多重累加器。如果设置正确,它应该可以工作。首先,我们定义参数:
然后设置以下步骤:
玩具数据:
管道:
参数应该是
estimator__ccp_alpha
。因此,如果我们在它前面加上tree
,加上tree__estimator__ccp_alpha = alphas
,它就会起作用:如果我用你的:
我也犯了同样的错误
相关问题 更多 >
编程相关推荐