【问题标题】:How to specify more than one eval_metric for a CatBoostRegressor?如何为 CatBoostRegressor 指定多个 eval_metric?
【发布时间】:2023-04-04 17:52:01
【问题描述】:

我想为我的 CatBoostRegressor 指定多个评估指标:

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

所以我可以使用.get_best_score() 方法非常简单地获得结果,但它不接受列表中的指标。有没有办法做到这一点?我无法弄清楚,也找不到答案。我知道用另一种方法很容易解决,但我想知道这是否可以用不同的输入格式来完成,或者不支持。提前谢谢!

【问题讨论】:

    标签: python machine-learning catboost


    【解决方案1】:

    您应该将评估指标列表传递给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
    #  }}
    

    【讨论】:

      猜你喜欢
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 2012-01-15
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 2021-08-08
      相关资源
      最近更新 更多