问题描述
我有一个用R开发的XGBoost模型,我想用Python进行校准。
它存储为xgb.model
文件。
我已使用以下代码行成功地将其加载到Python中。
model = xgboost.Booster(model_file="path_to_xgb.model")
我正在使用以下代码生成校准器对象,但是在尝试适合校准器时,出现运行时错误。
calibrator = CalibratedClassifierCV(model,cv = 'prefit',method = 'sigmoid')
calibrator.fit(Xtrain,Ytrain)
我看到的错误是
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/calibration.py",line 297,in _preproc
raise RuntimeError('classifier has no decision_function or '
RuntimeError: classifier has no decision_function or predict_proba method.
我已经照顾到数据集的不连续性,但是希望我能就如何进行此操作提供帮助。
谢谢
解决方法
您首先需要将XGBoost Booster
对象包装到与Scikit-Learn兼容的xgboost.XGBClassifier
对象中。