catboost eval_set在Scikit-Learn管道中无法使用
我正在尝试将x_valid
数据集传递到evar_set
从fit函数中的参数(从catboost库中)(这是 documentation )但是我收到以下错误:
ValueError: Pipeline.fit does not accept the cat_features parameter. You can pass parameters to specific steps of your pipeline using the stepname__parameter format, e.g. `Pipeline.fit(X, y, logisticregression__sample_weight=sample_weight)`.
我正在运行的代码是
catboost_model = CatBoostClassifier(learning_rate=0.02, eval_metric='AUC')
pipeline = Pipeline([("classifer", catboost_model)])
cat_columns = ['frontend_client_type']
X_train, X_valid, y_train, y_valid = train_test_split(df[cat_columns], df['label'], test_size=0.2)
pipeline = pipeline.fit(
X_train,
y_train,
cat_features=cat_columns,
classifer__eval_set=[(X_valid, y_valid)],
)
我的合成数据框架是
df = pd.DataFrame({'frontend_client_type':['android', 'android', 'ios', 'web', 'android'],
'label':[True, True, False, False, True]})
I am trying to pass X_valid
dataset into the eval_set
parameters in the fit function from CatBoost library (this is the link to the documentation) but I am getting the following error:
ValueError: Pipeline.fit does not accept the cat_features parameter. You can pass parameters to specific steps of your pipeline using the stepname__parameter format, e.g. `Pipeline.fit(X, y, logisticregression__sample_weight=sample_weight)`.
The code that I am running is
catboost_model = CatBoostClassifier(learning_rate=0.02, eval_metric='AUC')
pipeline = Pipeline([("classifer", catboost_model)])
cat_columns = ['frontend_client_type']
X_train, X_valid, y_train, y_valid = train_test_split(df[cat_columns], df['label'], test_size=0.2)
pipeline = pipeline.fit(
X_train,
y_train,
cat_features=cat_columns,
classifer__eval_set=[(X_valid, y_valid)],
)
My synthetic dataframe is
df = pd.DataFrame({'frontend_client_type':['android', 'android', 'ios', 'web', 'android'],
'label':[True, True, False, False, True]})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
classifer__cat_features = cat_columns
inpipeline.fit
而不是cat_features = cat_columns
。根据官方文件,
Use
classifer__cat_features=cat_columns
inpipeline.fit
instead ofcat_features=cat_columns
.According to official documentation,