如何可视化sklearn GradientBoostingClassifier?

Car*_*zón 3 graphviz decision-tree scikit-learn

我已经训练了一个渐变增强分类器,我想使用此处显示的graphviz_exporter工具对其进行可视化.

当我尝试它时,我得到:

AttributeError: 'GradientBoostingClassifier' object has no attribute 'tree_'
Run Code Online (Sandbox Code Playgroud)

这是因为graphviz_exporter用于决策树,但我想还有一种可视化方法,因为渐变提升分类器必须有一个基础决策树.

有谁知道怎么做?

Car*_*zón 9

属性估计器包含基础决策树.以下代码显示受过训练的GradientBoostingClassifier的树之一.

clf = GradientBoostingClassifier(
    n_estimators=200,
    learning_rate=1.0,
    max_depth=3,
    random_state=42
)
clf = clf.fit(X[:600], Y[:600])


# Get the tree number 42
sub_tree_42 = clf.estimators_[42, 0]

dot_data = tree.export_graphviz(
    sub_tree_42,
    out_file=None, filled=True,
    rounded=True,  
    special_characters=True,
    proportion=True,
)
graph = pydotplus.graph_from_dot_data(dot_data)  
Image(graph.create_png()) 
Run Code Online (Sandbox Code Playgroud)

  • 是的,但在这种情况下,您有200个估算器.因此,打印200棵树来理解它是不实际或有用的.[见这个](https://arogozhnikov.github.io/2016/06/24/gradient_boosting_explained.html)以便更好地理解. (4认同)