0

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

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

有人有关于如何获取值的信息吗?

4

2 回答 2

3

在 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
于 2017-05-18T19:57:02.187 回答
1

当您最后训练 DecisionTreeModel 时,您将拥有此类

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

您可以从顶部开始遍历节点,并且可以从中获取所需的一切(预测+ 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])
于 2014-12-04T13:36:56.637 回答