python - 适用于多个参数的 CatBoostClassifier

标签 python nlp catboost

我有以下用于分类器的文本数据

  1. 他是一名美国篮球运动员
  2. 他在英国踢足球。

我想预测数据中的 2 个值:国家/地区、运动项目。 示例:1) 美国 |篮球; 2) 英国 |足球

目前我正在使用 CatBoostClassifier() 来预测单个值(例如国家/地区):

vectorizer = CountVectorizer(ngram_range=[1, 2])
x = vectorizer.fit_transform(df['words']).toarray()
y = df['country'].astype(int)
grid = GridSearchCV(CatBoostClassifier(n_estimators=200, silent=False), cv=3,
                param_grid={'learning_rate': [0.03], 'max_depth': [3]})
grid.fit(x, y)
model = grid.best_estimator_

我可以使用分类器来预测 2 个或更多值并获得组合模型吗?

最佳答案

您可以使用sklearn.multioutput模块还支持 CatBoostClassifier。该模块提供的所有分类器都采用单输出的基本估计器,并将它们扩展到多输出估计器。您可以例如使用MultiOutputClassifier这样:

from catboost import CatBoostClassifier
from sklearn.multioutput import MultiOutputClassifier

clf = MultiOutputClassifier(CatBoostClassifier(n_estimators=200, silent=False))

由于这是一个 scikit-learn 估计器,您也可以像以前一样在网格搜索中使用它,如下所示:

grid = GridSearchCV(clf, param_grid={'estimator__learning_rate': [0.03], 'estimator__max_depth': [3]}, cv=3)
grid.fit(x, y)

用于训练模型的标签应采用以下格式:

import numpy as np

y = np.asarray([['USA', 'basketball'], ['UK', 'football']])

无需更改您的功能x

关于python - 适用于多个参数的 CatBoostClassifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62646722/

相关文章:

php - 在 PHP 中解析日期字符串

python-3.x - 使用之前训练好的模型在catboost中进行进一步预测

python - 在 VS Code 中设置 python 自动完成

python - 从 Python 应用程序调用 OpenWhisk 操作?

python - 函数调用堆栈 : keras_scratch_graph Error

machine-learning - catboost 算法中对称树背后的直觉是什么?

python - 从 Google Cloud Storage 加载保存的 CatBoost 模型 (.cbm)

python - 仅当 "."是 python 数据框列中的唯一值时才替换

python - 告诉 PyCharm 代码生成类的字段

python - 在 python 中使用 sklearn 为 n-gram 计算 TF-IDF