我想为我的CatBoostRegressor指定多个评估指标:
model=catboost.CatBoostRegressor(eval_metric=['RMSE', 'MAE', 'R2'])因此,我可以使用.get_best_score()方法非常简单地获得结果,但它不接受列表中的指标。有没有办法做到这一点?我想不出来,也找不到答案。我知道另一种方法很容易解决,但我想知道是否可以使用不同的指标或其他输入格式来实现这一点,或者它不受支持。提前谢谢你!
发布于 2021-07-07 14:01:54
您应该将评估指标列表传递给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
# }}https://stackoverflow.com/questions/68225301
复制相似问题