機器學習入門-決策樹的可視化展示


from sklearn import tree
from sklearn.datasets.california_housing import fetch_california_housing
housing = fetch_california_housing()


dtr = tree.DecisionTreeRegressor(max_depth=2)
dtr.fit(housing.data[:, [6, 7]], housing.target)

dot_data = \
          tree.export_graphviz(
              dtr, 
              out_file = None, 
              feature_names=housing.feature_name[6:8],
              filled = True, 
              impurity = False,
              rounded = True
          )

import pydotplus
graph = pydotplus.graph_from_dot_data(dot_data)
graph.get_nodes()[7].set_fillcolor('#FFF2DD')
from IPython.display import Image 
Image(graph.create_png())


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM