首页 > 解决方案 > 在 lightgbm 或 XGBoost 中校准概率

问题描述

嗨,我需要帮助来校准 lightgbm 中的概率

下面是我的代码

cv_results = lgb.cv(params, lgtrain, nfold=10, stratified=False, num_boost_round = num_rounds, verbose_eval=10, early_stopping_rounds = 50, seed = 50)

best_nrounds = cv_results.shape[0] - 1

lgb_clf = lgb.train(参数,lgtrain,num_boost_round=10000,valid_sets=[lgtrain,lgvalid],early_stopping_rounds=50,verbose_eval=10)

ypred = lgb_clf.predict(测试,num_iteration=lgb_clf.best_iteration)

标签: pythonmachine-learningxgboostlightgbm

解决方案


我不确定 LighGBM,但在 XGBoost 的情况下,如果你想校准概率,最好也是最可能的唯一方法是使用来自 sklearn 的 CalibratedClassifierCV

你可以在这里找到它 - https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html

这里唯一的问题是 CalibratedClassifierCV 仅将 sklearn 的估计器作为输入,因此您可能必须使用 sklearn 包装器进行 XGBoost 而不是传统的 XGBoost API 的 .train 函数。

您可以在此处找到 XGBoost 的 sklearn 包装器 - https://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.XGBClassifier

我希望它能回答你的问题。


推荐阅读