1 Star 0 Fork 1

Strings_li/spark-random-forest-parse-plot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Spark-Random-Forest-Parse

该工程可以线上部署spark-random-forest模型,并且实现了spark画图功能,分别基于python和scala实现。

  1. 基于SparkMLTree,把随机森林中的决策树模型生成每一个json文件模型,如下所示,保存在resource下的json_model 文件夹下: { "featureIndex":0, "gain":0.4591836734693877, "impurity":0.4591836734693877, "threshold":1.9, "nodeType":"internal", "impurityStats":[ 54.0, 30.0 ], "splitType":"continuous", "prediction":0.0, "leftChild":{ "impurity":0.0, "nodeType":"leaf", "impurityStats":[ 54.0, 0.0 ], "prediction":0.0 }, "rightChild":{ "impurity":0.0, "nodeType":"leaf", "impurityStats":[ 0.0, 30.0 ], "prediction":1.0 } }

  2. com.strings.algo.tree.parse 文件下有两个文件,分别基于python和scala实现了解析Json模型文件形成树,功能基本一致,python版本的增加了画图功能,能把spark的树基于dot画出来。

第0棵树:

第5棵树:

第13棵树:

当然可以通过spark中RandomForestClassificationModel的toDebugString生成的树的结构对比,

Tree 0 (weight 1.0): If (feature 0 <= 1.9) Predict: 0.0 Else (feature 0 > 1.9) Predict: 1.0

Tree 5 (weight 1.0): If (feature 2 <= 5.4) If (feature 3 <= 2.7) Predict: 1.0 Else (feature 3 > 2.7) If (feature 0 <= 1.9) Predict: 0.0 Else (feature 0 > 1.9) Predict: 1.0 Else (feature 2 > 5.4) If (feature 3 <= 3.4) Predict: 1.0 Else (feature 3 > 3.4) Predict: 0.0

Tree 13 (weight 1.0): If (feature 2 <= 5.4) If (feature 1 <= 0.6) Predict: 0.0 Else (feature 1 > 0.6) Predict: 1.0 Else (feature 2 > 5.4) If (feature 0 <= 1.7) Predict: 0.0 Else (feature 0 > 1.7) Predict: 1.0

  1. 结果对比,基于Json模型解析的树,和原来spark存储的模型进行对比,发现结果完全一致。(这里的VectorIndex没有起作用)

空文件

简介

an implementation of parsing spark random forest in scala and python,and plot trees based dot. 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Scala
1
https://gitee.com/strings_li/spark-random-forest-parse-plot.git
git@gitee.com:strings_li/spark-random-forest-parse-plot.git
strings_li
spark-random-forest-parse-plot
spark-random-forest-parse-plot
master

搜索帮助