【问题标题】:Feature Importance for Random Forest Regressor in PythonPython 中随机森林回归器的特征重要性
【发布时间】:2017-01-06 01:01:18
【问题描述】:

我正在尝试找出哪些特征对我的预测模型最重要。

目前我正在使用 sklearn 的内置属性

Model = Model.fit(Train_Features, Labels_Train)
print(Model.feature_importances_)

只是它更像是一种黑盒类型的方法,我不明白它使用什么方法来衡量对功能的重要性。有没有更好的方法来做到这一点?

【问题讨论】:

  • 或许您可以澄清一下:您发现这种方法的不足之处是什么?
  • 只是它更像是一种黑盒类型的方法,我不明白它使用什么方法来衡量对特征的重要性。我很抱歉,应该在问题中说明这一点
  • 在您的问题中添加说明,我可以回答
  • 完成!很抱歉!

标签: python regression random-forest feature-selection


【解决方案1】:

就决策树而言,特征重要性并不是一个黑箱。来自DecisionTreeRegressor 的文档:

一个特征的重要性被计算为(归一化的)总和 降低该特征带来的标准。这也是众所周知的 作为基尼系数。

对于森林,它只是您森林中不同树木的平均值。查看source code

def feature_importances_(self):
    """Return the feature importances (the higher, the more important the
       feature).
    Returns
    -------
    feature_importances_ : array, shape = [n_features]
    """
    if self.estimators_ is None or len(self.estimators_) == 0:
        raise NotFittedError("Estimator not fitted, "
                             "call `fit` before `feature_importances_`.")

    all_importances = Parallel(n_jobs=self.n_jobs,
                               backend="threading")(
        delayed(getattr)(tree, 'feature_importances_')
        for tree in self.estimators_)

    return sum(all_importances) / len(self.estimators_)

【讨论】:

  • @kage77 这回答了你的问题吗?
  • 一个老问题,但我正在寻找一个答案。我的印象是基尼杂质是用于分类任务,而不是回归?
猜你喜欢
  • 2021-08-29
  • 2021-05-09
  • 1970-01-01
  • 2020-05-26
  • 2018-06-17
  • 2017-10-21
  • 2021-05-13
  • 2015-05-12
  • 2019-01-28
相关资源
最近更新 更多