![](/img/trans.png)
[英]Get the default number of elements per leaf in a Decision Tree of Spark MLlib
[英]Finding Importance Value from Spark's Decision Tree using MLlib
我们正在使用MLlib为决策树运行Spark 1.0或1.1。
当我使用示例数据运行示例SCALA代码时,它没有任何错误,但是我从结果中找不到功能的重要性。
有人知道如何获取这些值吗?
在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
当您最终训练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])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.