回答

1

首先,你需要使用model.toDebugString得到您的隨機森林模型這樣的輸出:

"RandomForestClassificationModel (uid=rfc_6c4ceb92ba78) with 20 trees 
    Tree 0 (weight 1.0): 
    If (feature 0 <= 3="" 10="" 1.0)="" if="" (feature="" <="0.0)" predict:="" 0.0="" else=""> 6.0) 
     Predict: 0.0 
    Else (feature 10 > 0.0) 
     If (feature 12 <= 12="" 63.0)="" predict:="" 0.0="" else="" (feature=""> 63.0) 
     Predict: 0.0 
    Else (feature 0 > 1.0) 
    If (feature 13 <= 3="" 1.0)="" if="" (feature="" <="3.0)" predict:="" 0.0="" else=""> 3.0) 
     Predict: 1.0 
    Else (feature 13 > 1.0) 
     If (feature 7 <= 7="" 1.0)="" predict:="" 0.0="" else="" (feature=""> 1.0) 
     Predict: 0.0 
    Tree 1 (weight 1.0): 
    If (feature 2 <= 11="" 15="" 1.0)="" if="" (feature="" <="0.0)" predict:="" 0.0="" else=""> 0.0) 
     Predict: 1.0 
    Else (feature 15 > 0.0) 
     If (feature 11 <= 11="" 0.0)="" predict:="" 0.0="" else="" (feature=""> 0.0) 
     Predict: 1.0 
    Else (feature 2 > 1.0) 
    If (feature 12 <= 5="" 31.0)="" if="" (feature="" <="0.0)" predict:="" 0.0="" else=""> 0.0) 
     Predict: 0.0 
    Else (feature 12 > 31.0) 
     If (feature 3 <= 3="" 4.0)="" predict:="" 0.0="" else="" (feature=""> 4.0) 
     Predict: 0.0 
    Tree 2 (weight 1.0): 
    If (feature 8 <= 4="" 6="" 1.0)="" if="" (feature="" <="2.0)" predict:="" 0.0="" else=""> 10875.0) 
     Predict: 1.0 
    Else (feature 6 > 2.0) 
     If (feature 1 <= 1="" 36.0)="" predict:="" 0.0="" else="" (feature=""> 36.0) 
     Predict: 1.0 
    Else (feature 8 > 1.0) 
    If (feature 5 <= 4="" 0.0)="" if="" (feature="" <="4113.0)" predict:="" 0.0="" else=""> 4113.0) 
     Predict: 1.0 
    Else (feature 5 > 0.0) 
     If (feature 11 <= 11="" 2.0)="" predict:="" 0.0="" else="" (feature=""> 2.0) 
     Predict: 0.0 
    Tree 3 ... 

保存下一些.txt文件,然後使用:https://github.com/tristaneljed/Decision-Tree-Visualization-Spark

+0

我們在pyspark中只有一些東西,而不是使用d3.js.另外model.toDebugString不會給出每個節點進入數據的百分比。 – Neo