2017-06-22 753 views
0

我想通過XGBRegressor()執行功能選擇(用於迴歸任務)。XGBoost - 使用XGBRegressor的功能選擇

更確切地說,我想知道:

  • 如果有類似的方法 feature_importances_,與XGBClassifier利用,這我可以用迴歸。
  • 如果當它被用來與XGBRegressor()

回答

1

最後我已經解決了這個問題XGBoost的方法plot_importance()可靠:

model.booster().get_score(importance_type='weight')

0

這裏是我的解決方案(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