python - 在 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)
解决方案
我不确定 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
我希望它能回答你的问题。
推荐阅读
- javascript - JS SDK 性能测试
- google-analytics - 检索停用 Google Analytics Services SDK 的 Google Analytics 历史数据
- javascript - Un-TAR 和 un-GZip 文件存储为 JavaScript 缓冲区
- r - 根据常用值组合 R 中的数据框行
- laravel - 如何通过 API 创建好友请求
- javascript - 我们如何在 django 中的 onclick 函数中动态添加 id?
- matplotlib - 如何不填充 plt 多边形补丁
- javascript - 如何通过传递参数从列表数组中检索特定数据作为字符串?
- angular - tinyMCE 和来自 CDN 网络的 tinyMCE 显示扭曲的图标
- google-cloud-storage - Google Cloud Storage - 控制 bot 对公共文件的访问。限制 b 类操作