2017-07-07 56 views
1

我已經訓練了gradient boost classifier,我想使用graphviz_exporter工具將其顯示爲here如何可視化Sklearn GradientBoostingClassifier?

當我嘗試它,我得到:

AttributeError: 'GradientBoostingClassifier' object has no attribute 'tree_' 

這是因爲graphviz_exporter是爲decision trees,但我想還是有辦法對其進行可視化,因爲梯度升壓分類必須有一個基本的決策樹。

有人知道該怎麼做嗎?

+1

你試過使用XGBoost嗎? – sera

+0

感謝您向我介紹XGBoost庫。我會給它一張支票,但我發現如何使用sklearn –

回答

3

屬性估計器包含基礎決策樹。以下代碼顯示受過訓練的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()) 
+2

是的,但在這種情況下,您有200個估算器。所以打印出200棵樹來理解它是不實際或有用的。 [見此](https://arogozhnikov.github.io/2016/06/24/gradient_boosting_explained.html)以獲得更好的理解。 –

+0

謝謝,該頁面對我更好地理解整個概念非常有用 –