簡體   English   中英

Python Catboost:多類 F1 得分自定義指標

[英]Python Catboost: Multiclass F1 score custom metric

您如何找到多類 Catboost 分類器的每個 class 的 F1 分數? 我已經閱讀了文檔github 存儲庫,其中有人提出了同樣的問題。 但是,我無法弄清楚實現這一目標的代碼鍛造。 我知道我必須在CatBoostClassifier()中使用custom_metric參數,但是當我想要我的多類數據集的每個 class 的F1分數時,我不知道 custom_metric 可以接受什么custom_metric

假設您有一個玩具數據集(來自文檔):

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)

你應該使用 TotalF1

params = {
    'leaf_estimation_method': 'Gradient',
    'learning_rate': 0.01,
    'max_depth': 8,
    'bootstrap_type': 'Bernoulli',
    'objective': 'MultiClass',
    'eval_metric': 'MultiClass',
    'subsample': 0.8,
    'random_state': 42,
    'verbose': 0,
    "eval_metric" : 'TotalF1',
    "early_stopping_rounds" : 100
    }

https://catboost.ai/docs/concepts/loss-functions-multiclassification.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM