如何找到多类 Catboost 分类器每个类的 F1 分数?我已经读过文档 https://catboost.ai/docs/concepts/python-reference_catboostclassifier.html和github 仓库 https://github.com/catboost/catboost/issues/490有人问同样的问题。但是,我无法弄清楚实现这一目标的代码设计。我明白我必须使用custom_metric
参数输入CatBoostClassifier()
但我不知道什么论点是可以接受的custom_metric
当我想要的时候F1
我的多类数据集每个类的得分。
假设您有一个玩具数据集(来自文档):
from catboost import Pool
cat_features = [0, 1, 2]
data = [["a","b", 1, 4, 5, 6],
["a","b", 4, 5, 6, 7],
["c","d", 30, 40, 50, 60]]
label = [0, 1, 2]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.2)
train_pool = Pool(X_train, y_train, cat_features=categorical_features_indices)
validate_pool = Pool(X_test, y_test, cat_features=categorical_features_indices)
params = {"loss_function": "MultiClass",
"depth": symmetric_tree_depth,
"num_trees": 500,
# "eval_metric": "F1", # this doesn't work
"verbose": False}
model = CatBoostClassifier(**params)
model.fit(train_pool, eval_set=validate_pool)