前言
当孤立森林训练后,我们想要查看森林中的子树是什么样的,节点的分割是根据什么条件判断的,那么最直观的方法就是将子树可视化出来。
一、如何可视化子树。
我们已经训练好了孤立森林,模型叫做IF,获得第一颗子树。
IF.estimators_[0]
二、使用步骤
1.引入库
代码如下(示例):
from sklearn import tree
2.可视化
在这我想让图片显示出来的时候大一些,所以用subplots
代码如下(示例):
fig,(ax1) = plt.subplots(1,1,figsize=(16,16))
tree.plot_tree(IF.estimators_[0],fontsize=10)
plt.show()
结果展示
3 Reference
https://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html#sphx-glr-auto-examples-tree-plot-unveil-tree-structure-py
https://scikit-learn.org/stable/modules/generated/sklearn.tree.plot_tree.html?highlight=_tree#sklearn.tree.plot_tree
总结
就是随手记录下,学习内容。