0
我想通過XGBRegressor()
執行功能選擇(用於迴歸任務)。XGBoost - 使用XGBRegressor的功能選擇
更確切地說,我想知道:
- 如果有類似的方法
feature_importances_
,與XGBClassifier
利用,這我可以用迴歸。 - 如果當它被用來與
XGBRegressor()
我想通過XGBRegressor()
執行功能選擇(用於迴歸任務)。XGBoost - 使用XGBRegressor的功能選擇
更確切地說,我想知道:
feature_importances_
,與XGBClassifier
利用,這我可以用迴歸。XGBRegressor()
最後我已經解決了這個問題XGBoost的方法plot_importance()
可靠:
model.booster().get_score(importance_type='weight')
這裏是我的解決方案(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