2014-12-04 68 views
0

我们使用MLlib为决策树运行Spark 1.0或1.1。使用MLlib从Spark决策树中找到重要价值

当我使用示例数据运行示例SCALA代码时,它没有任何错误地工作,但我无法从结果中找到功能重要性。

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

+1

请发布您尝试过的内容和结果。我们不是心灵感应。 – 2014-12-04 11:19:14

回答

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]) 
2

在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