我想将 numpy 数组的第 12 列作为分类特征传递。
该列具有从 1 到 10 的 int 值。
我试过这个:
cbr.fit(X_train, y,
eval_set=(X_train_test, y_test),
cat_features=[X_train[:,12]],
use_best_model=True,
verbose=100)
Run Code Online (Sandbox Code Playgroud)
但是得到了这个错误:
CatboostError: 'data' 是 np.float32 的 numpy 数组,这意味着没有分类特征,但 'cat_features' 参数指定了非零数量的分类特征
如何在将 CatboostClassifier 用于 Multiclass 问题时使用“class_weights”。文档说它应该是一个列表,但是我需要按什么顺序放置权重?我有一个标签数组,其中包含从 -2 到 +2 的 15 个类,包括十进制数,与其他类相比,类 0 的密度要高得多。请帮忙。谢谢,
我尝试了二进制类,它更容易使用,但对多类一无所知。
cb_model_step1 = run_catboost(X_train, y_train_new, X_test, y_test_new, n_estimators = 1000, verbose=100, eta = 0.3, loss_function = 'MultiClassOneVsAll', class_weights = counter_new)
cb = CatBoostClassifier(thread_count=4, n_estimators=n_estimators, max_depth=10, class_weights = class_weights, eta=eta, loss_function = loss_function)
我在 google colaboratory 中使用 catboost 模块对提升分类器进行建模。我遵循了官方示例:
from catboost import CatBoostClassifier, Pool
train_data = [[1, 3], [0, 4], [1, 7], [0, 3]]
train_labels = [1, 0, 1, 1]
model = CatBoostClassifier(learning_rate=0.03)
model.fit(train_data,
train_labels,
verbose=False,
plot=True)
Run Code Online (Sandbox Code Playgroud)
但这在 Google Colab notebook 中没有显示任何情节。
这是我的 google colab 代码:
from catboost import CatBoostClassifier, Pool
train_data = [[1, 3], [0, 4], [1, 7], [0, 3]]
train_labels = [1, 0, 1, 1]
model = CatBoostClassifier(learning_rate=0.03)
model.fit(train_data,
train_labels,
verbose=False,
plot=True)
Run Code Online (Sandbox Code Playgroud)
Google colab 只是打印,<catboost.core.CatBoostClassifier at 0x7fc7a846d898>
而不是像 …
我正在尝试实现我的自定义损失函数。在分析恶化的预测质量时,我提到自定义损失函数在交叉验证上表现更差(至少不同),即使文档中提供了 Logloss 实现作为示例。我预计它等于“原生”catboost Logloss。
这是我正在使用的示例: https://catboost.ai/docs/concepts/python-usages-examples.html#user-define-loss-function
class LoglossObjective(object):
def calc_ders_range(self, approxes, targets, weights):
assert len(approxes) == len(targets)
if weights is not None:
assert len(weights) == len(approxes)
result = []
for index in range(len(targets)):
e = np.exp(approxes[index])
p = e / (1 + e)
der1 = targets[index] - p
der2 = -p * (1 - p)
if weights is not None:
der1 *= weights[index]
der2 *= weights[index]
result.append((der1, der2))
return result
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么用户定义的对数损失与catboost“本机”对数损失不同?以及如何让用户自定义的预测质量与“原生”一样好?
我有关于 CatBoostClassifier 的问题。
params = {
'loss_function' : 'Logloss',
'eval_metric' : 'AUC',
'verbose' : 200,
'random_seed' : 42,
'custom_metric' : 'AUC:hints=skip_train~false'
}
cbc = CatBoostClassifier(**params)
cbc.fit(x_tr, y_tr,
eval_set = (x_te, y_te),
use_best_model = True,
plot = True
);
predictions = cbc.predict(x_te)
Run Code Online (Sandbox Code Playgroud)
模型结果:
最佳测试 = 0.6786987522
但是当我尝试时:
from sklearn import metrics
auc = metrics.roc_auc_score(y_te, predictions)
auc
Run Code Online (Sandbox Code Playgroud)
我得到了0.5631684491978609
结果。为什么这个结果不同?第一个和第二个结果是什么意思?哪一项是我的 cbc 模型的最终指标?
有没有办法用 CatBoost 和 Optuna 进行修剪(在 LightGBM 中很容易,但在 Catboost 中我找不到任何提示)。我的代码是这样的
def objective(trial):
param = {
'iterations':trial.suggest_int('iterations', 100,1500, step=100),
'learning_rate':trial.suggest_uniform("learning_rate", 0.001, 0.3),
'random_strength':trial.suggest_int("random_strength", 1,10),
'max_bin':trial.suggest_categorical('max_bin', [2,3,4,5,6,8,10,20,30]),
'grow_policy':trial.suggest_categorical('grow_policy', ['SymmetricTree', 'Depthwise', 'Lossguide']),
"colsample_bylevel": trial.suggest_uniform("colsample_bylevel", 0.1, 1),
'od_type' : "Iter",
'od_wait' : 30,
"depth": trial.suggest_int("max_depth", 1,12),
"l2_leaf_reg": trial.suggest_loguniform("l2_leaf_reg", 1e-8, 100),
'custom_metric' : ['AUC'],
"loss_function": "Logloss",
}
if param['grow_policy'] == "SymmetricTree":
param["boosting_type"]= trial.suggest_categorical("boosting_type", ["Ordered", "Plain"])
else:
param["boosting_type"] = "Plain"
# Added subsample manually
param["subsample"] = trial.suggest_float("subsample", 0.1, 1)
### CV ###
# How to add a …
Run Code Online (Sandbox Code Playgroud)