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
3
当你训练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中,您可以执行以下操作:
当你训练DecisionTreeModel结束时,你有这个类
您可以从顶部开始遍历节点,您可以从中获得所需的一切(预测InformationGainStats)