我正在研究文本二元分类问题。由于类是高度不平衡的,所以我不得不使用像RandomOversampler()这样的采样技术。然后对于分类,我将使用RandomForestClassifier(),其参数需要使用GridSearchCV()进行调整。 我正在尝试创建一个管道来按顺序执行这些操作,但到目前为止失败了。它抛出“无效参数”。在
param_grid = {
'n_estimators': [5, 10, 15, 20],
'max_depth': [2, 5, 7, 9]
}
grid_pipe = make_pipeline(RandomOverSampler(),RandomForestClassifier())
grid_searcher = GridSearchCV(grid_pipe,param_grid,cv=10)
grid_searcher.fit(tfidf_train[predictors],tfidf_train[target])
您在
params
中定义的参数用于RandomForestClassifier,但是在gridSearchCV中,您没有传递RandomForestClassifier
对象。在您正在传递一个管道对象,您必须重命名该对象的参数才能访问内部RandomForestClassifier对象。在
将其更改为:
它会起作用的。在
相关问题 更多 >
编程相关推荐