我在校准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] - 1lgb_clf = lgb.train(params, lgtrain, num_boost_round=10000 , valid_sets=[lgtrain,lgvalid], early_stopping_rounds=50, verbose_eval=10)ypred = lgb_clf.predict(test, num_iteration=lgb_clf.best_iteration)
回答:
我不确定LightGBM的情况,但在XGBoost的情况下,如果你想校准概率,最好且可能唯一的方法是使用sklearn的CalibratedClassifierCV。
你可以在这里找到它 – https://scikit-learn.org/stable/modules/generated/sklearn.calibration.CalibratedClassifierCV.html
这里唯一的注意事项是CalibratedClassifierCV只能接受sklearn的估计器作为输入,所以你可能需要使用XGBoost的sklearn封装器,而不是传统的XGBoost API的.train函数。
你可以在这里找到XGBoost的sklearn封装器 – https://xgboost.readthedocs.io/en/latest/python/python_api.html#xgboost.XGBClassifier