使用MAPIE为GradientBoostingRegressor求置信区间遇参数错误求助
问题解决:GradientBoostingRegressor 意外参数 'objective'
错误原因
scikit-learn 的 GradientBoostingRegressor 类没有objective这个初始化参数,你可能混淆了XGBoost/LightGBM等其他梯度提升库的参数设置。同时,结合你使用MapieQuantileRegressor做分位数回归的需求,当前设置的loss="squared_error"也不符合要求。
修复后的代码
from sklearn.model_selection import train_test_split import numpy as np from sklearn.linear_model import LinearRegression from sklearn.datasets import make_regression from sklearn.ensemble import GradientBoostingRegressor from matplotlib import pyplot as plt from mapie.regression import MapieQuantileRegressor # 移除objective参数,将loss改为分位数回归对应的'quantile' Model = GradientBoostingRegressor( n_estimators=500, max_depth=4, min_samples_split=5, learning_rate=0.01, loss="quantile", # 分位数回归需要设置这个损失函数 alpha=0.1 # 指定分位数,和后续Mapie的alpha保持一致 ) X, y = make_regression(n_samples=5000, n_features=1, noise=20, random_state=59) X_train, X_tmp, y_train, y_tmp = train_test_split(X, y, test_size=2000, random_state=42) X_calib, X_test, y_calib, y_test = train_test_split(X_tmp, y_tmp, test_size=1000, random_state=42) alpha = 0.1 mapie = MapieQuantileRegressor(estimator=Model, cv="split", alpha=alpha) mapie.fit(X_train, y_train, X_calib=X_calib, y_calib=y_calib) y_pred, y_pis = mapie.predict(X_test)
关键说明
- 移除
objective='quantile':该参数不属于scikit-learn的GradientBoostingRegressor - 修改
loss参数:分位数回归需要设置loss="quantile",同时通过alpha参数指定目标分位数(和后续Mapie的alpha保持一致即可) - scikit-learn的GradientBoostingRegressor分位数回归逻辑:通过
loss="quantile"配合alpha定义分位数损失,实现分位数预测,适配MapieQuantileRegressor的使用场景
内容的提问来源于stack exchange,提问作者Karol
相关产品推荐
相关产品推荐

