[英]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.