[英]XGBoost - Feature selection using XGBRegressor
I am trying to perform features selection (for regression tasks) by XGBRegressor()
. 我正在尝试通过
XGBRegressor()
执行功能选择(用于回归任务XGBRegressor()
。
More precisely, I would like to know: 更确切地说,我想知道:
feature_importances_
, utilized with XGBClassifier
, which I could use for regression. feature_importances_
,可以与XGBClassifier
一起XGBClassifier
,则可以将其用于回归分析。 plot_importance()
is reliable when it is used with XGBRegressor()
plot_importance()
与XGBRegressor()
使用时是可靠的 最后,我通过以下方式解决了这个问题:
model.booster().get_score(importance_type='weight')
Here is my solution (Xnames refers to the feature names): 这是我的解决方案(Xnames是功能名称):
def xgb_feature_importance(model_xgb, fnames=None):
b = model_xgb.booster()
fs = b.get_fscore()
all_features = [fs.get(f, 0.) for f in b.feature_names]
all_features = np.array(all_features, dtype=np.float32)
all_features_imp = all_features / all_features.sum()
if fnames is not None:
return pd.DataFrame({'X':fnames, 'IMP': all_features_imp})
else:
return all_features_imp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.