簡體   English   中英

如何為 CatBoostRegressor 指定多個 eval_metric?

[英]How to specify more than one eval_metric for a CatBoostRegressor?

我想為我的 CatBoostRegressor 指定多個評估指標:

model=catboost.CatBoostRegressor(eval_metric=['RMSE', 'MAE', 'R2'])

所以我可以使用.get_best_score()方法非常簡單地得到結果,但它不接受列表中的指標。 有沒有辦法做到這一點? 我無法弄清楚也找不到答案。 我知道用另一種方式解決很容易,但我想知道這是否可以使用不同的指標輸入格式來完成,或者不支持。 先感謝您!

您應該將評估指標列表傳遞給custom_metric而不是eval_metric

from catboost import CatBoostRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split

# generate the data
X, y = make_regression(n_samples=100, n_features=10, random_state=0)

# split the data
X_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.2, random_state=0)

# fit the model
model = CatBoostRegressor(iterations=10, custom_metric=['RMSE', 'MAE', 'R2'])
model.fit(X=X_train, y=y_train, eval_set=(X_valid, y_valid), silent=True)

# get the best score
print(model.get_best_score())

# {'learn': {
#     'MAE': 42.36387514896515, 
#     'R2': 0.9398622316668792, 
#     'RMSE': 54.878286259899525
#  },
# 'validation': {
#     'MAE': 102.37559908734613, 
#     'R2': 0.6989698975428136, 
#     'RMSE': 134.75006267018009
#  }}

暫無
暫無

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

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