【问题标题】:CatBoost eval_set not working inside scikit-learn pipelineCatBoost eval_set 在 scikit-learn 管道中不起作用
【发布时间】:2023-01-01 16:41:05
【问题描述】:

我正在尝试将 X_valid 数据集传递到 CatBoost 库的拟合函数中的 eval_set 参数(这是指向 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]})

【问题讨论】:

  • 安装管道时,应将cat_features=cat_columns替换为classifer__cat_features=cat_columns

标签: python scikit-learn catboost


【解决方案1】:

在 pipeline.fit 中使用 classifer__cat_features=cat_columns 而不是 cat_features=cat_columns。

根据官方文件,

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

【讨论】:

    猜你喜欢
    • 2015-08-14
    • 2021-03-17
    • 1970-01-01
    • 2018-09-04
    • 2017-02-25
    • 2021-06-30
    • 2018-07-21
    • 2022-01-11
    • 2018-07-29
    相关资源
    最近更新 更多