【问题标题】:XGBoost - Feature selection using XGBRegressorXGBoost - 使用 XGBRegressor 进行特征选择
【发布时间】:2017-12-19 22:30:36
【问题描述】:

我正在尝试通过XGBRegressor() 执行特征选择(用于回归任务)。

更准确地说,我想知道:

  • 如果有类似的方法 feature_importances_,与 XGBClassifier 一起使用,我可以将其用于回归。
  • 如果XGBoost的方法plot_importance()XGBRegressor()一起使用时是可靠的

【问题讨论】:

    标签: python xgboost


    【解决方案1】:

    最后我通过以下方式解决了这个问题:

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

    【讨论】:

      【解决方案2】:

      这是我的解决方案(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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-05-23
        • 2013-08-15
        • 2016-03-16
        • 1970-01-01
        • 2022-07-27
        • 2022-01-19
        • 2014-11-05
        相关资源
        最近更新 更多