用于多个参数的 CatBoostClassifier
CatBoostClassifier for multiple parameters
我有以下分类器文本数据
- 他是美国篮球运动员
- 他在英国踢足球。
我想预测我的数据中的 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
module which also supports the CatBoostClassifier
. All the classifiers provided by this module take a base estimator for single output and extend them to multioutput estimators. You can e.g. use the 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
。
我有以下分类器文本数据
- 他是美国篮球运动员
- 他在英国踢足球。
我想预测我的数据中的 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
module which also supports the CatBoostClassifier
. All the classifiers provided by this module take a base estimator for single output and extend them to multioutput estimators. You can e.g. use the 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
。