catboost eval_set在Scikit-Learn管道中无法使用

发布于 2025-02-08 19:25:41 字数 1185 浏览 1 评论 0原文

我正在尝试将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南汐寒笙箫 2025-02-15 19:25:42

使用classifer__cat_features = cat_columns in pipeline.fit而不是cat_features = cat_columns

根据官方文件,

“管道的目的是组装几个步骤,这些步骤可以在设置不同的参数的同时可以交叉验证在一起。为此,它可以使用其名称和由“ __'隔开的参数名称”设置各个步骤的参数。 “ sklearn Pipeline文档

Use classifer__cat_features=cat_columns in pipeline.fit instead of cat_features=cat_columns.

According to official documentation,

"The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters. For this, it enables setting parameters of the various steps using their names and the parameter name separated by a '__'"sklearn pipeline documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文