【问题标题】:Finding Importance Value from Spark's Decision Tree using MLlib使用 MLlib 从 Spark 的决策树中查找重要性值
【发布时间】:2015-02-02 00:39:59
【问题描述】:

我们正在使用 MLlib 为决策树运行 Spark 1.0 或 1.1。

当我使用示例数据运行示例 SCALA 代码时,它可以正常工作,但我无法从结果中找到特征重要性。

有人知道如何获取这些值吗?

【问题讨论】:

  • 请发布您的尝试和结果。我们不是心灵感应。

标签: scala apache-spark decision-tree apache-spark-mllib


【解决方案1】:

在 Spark 2+ 中,您可以执行以下操作:

val vectorAssembler = new VectorAssembler().setInputCols(featureArray)
val decisionTreeModel = decisionTree.fit(trainingDataset)
val featureImportances = decisionTreeModel.featureImportances // Sparse or Dense Vector

featureArray.zip(featureImportances.toArray).sortBy(_._2).reverse

【讨论】:

    【解决方案2】:

    当你最后训练 DecisionTreeModel 时,你就有了这个类

    class DecisionTreeModel(val topNode: Node, val algo: Algo) {
       ...
    }
    

    你可以从顶部开始遍历节点,你可以从中得到你需要的一切(predict + InformationGainStats)

    class Node (
        val id: Int,
        val predict: Double,
        val isLeaf: Boolean,
        val split: Option[Split],
        var leftNode: Option[Node],
        var rightNode: Option[Node],
        val stats: Option[InformationGainStats])
    

    【讨论】:

      猜你喜欢
      • 2016-10-07
      • 2015-10-25
      • 2015-12-11
      • 2016-09-11
      • 1970-01-01
      • 2016-09-04
      • 2016-11-15
      • 2017-10-18
      • 2016-07-07
      相关资源
      最近更新 更多