日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

决策树如何可视化

發布時間:2024/10/8 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 决策树如何可视化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如果不能將一棵決策樹可視化,我覺的很難學好決策樹這一部分

安裝好Graphviz

為什么要安裝呢

因為要使用sklearn自帶的 export_graphviz

http://www.graphviz.org/

設置環境變量

pip install pydotplus

測試一下

# -*- coding:utf-8 -*- # time :2019/4/18 13:33 # author: 毛利 from sklearn.model_selection import train_test_split import pandas as pd from sklearn.tree import DecisionTreeClassifier from sklearn import datasets from sklearn import tree from sklearn.metrics import accuracy_score import pydotplus iris = datasets.load_iris() iris_feature = '花萼長度', '花萼寬度', '花瓣長度', '花瓣寬度' iris_feature_E = 'sepal length', 'sepal width', 'petal length', 'petal width' iris_class = 'Iris-setosa', 'Iris-versicolor', 'Iris-virginica' x = pd.DataFrame(iris['data'])[[0,1]] y = pd.Series(iris[ 'target']) x_train,x_test,y_train,y_test = train_test_split(x,y) model = DecisionTreeClassifier() model.fit(x_train,y_train) y_train_pred = model.predict(x_train) print('訓練集正確率:', accuracy_score(y_train, y_train_pred)) data = tree.export_graphviz(model, out_file='iris.dot', feature_names= iris_feature_E[0:2], class_names=iris_class,filled=True, rounded=True, special_characters=True) graph = pydotplus.graph_from_dot_data(data) graph.write_pdf('iris.pdf') with open('iris.png', 'wb') as f:f.write(graph.create_png())、import numpy as np from sklearn.tree import DecisionTreeClassifier import pydotplus from sklearn import treeX = np.array([[2, 2],[2, 1],[2, 3],[1, 2],[1, 1],[3, 3]])y = np.array([0, 1, 1, 1, 0, 1])plt.style.use('fivethirtyeight') plt.rcParams['font.size'] = 18 plt.figure(figsize=(8, 8))# Plot each point as the label for x1, x2, label in zip(X[:, 0], X[:, 1], y):plt.text(x1, x2, str(label), fontsize=40, color='g',ha='center', va='center')plt.grid(None) plt.xlim((0, 3.5)) plt.ylim((0, 3.5)) plt.xlabel('x1', size=20) plt.ylabel('x2', size=20) plt.title('Data', size=24) # plt.show()dec_tree = DecisionTreeClassifier() print(dec_tree) dec_tree.fit(X, y) print(dec_tree.score(X,y)) # Export as dot dot_data = tree.export_graphviz(dec_tree, out_file=None,feature_names=['x1', 'x2'],class_names=['0', '1'],filled=True, rounded=True,special_characters=True) graph = pydotplus.graph_from_dot_data(dot_data) with open('1.png', 'wb') as f:f.write(graph.create_png())




這是export_graphviz源代碼加快理解

def export_graphviz(decision_tree, out_file=SENTINEL, max_depth=None,feature_names=None, class_names=None, label='all',filled=False, leaves_parallel=False, impurity=True,node_ids=False, proportion=False, rotate=False,rounded=False, special_characters=False, precision=3):"""Export a decision tree in DOT format.This function generates a GraphViz representation of the decision tree,which is then written into `out_file`. Once exported, graphical renderingscan be generated using, for example::$ dot -Tps tree.dot -o tree.ps (PostScript format)$ dot -Tpng tree.dot -o tree.png (PNG format)The sample counts that are shown are weighted with any sample_weights thatmight be present.Read more in the :ref:`User Guide <tree>`.Parameters----------decision_tree : decision tree classifierThe decision tree to be exported to GraphViz.out_file : file object or string, optional (default='tree.dot')Handle or name of the output file. If ``None``, the result isreturned as a string. This will the default from version 0.20.max_depth : int, optional (default=None)The maximum depth of the representation. If None, the tree is fullygenerated.feature_names : list of strings, optional (default=None)Names of each of the features.class_names : list of strings, bool or None, optional (default=None)Names of each of the target classes in ascending numerical order.Only relevant for classification and not supported for multi-output.If ``True``, shows a symbolic representation of the class name.label : {'all', 'root', 'none'}, optional (default='all')Whether to show informative labels for impurity, etc.Options include 'all' to show at every node, 'root' to show only atthe top root node, or 'none' to not show at any node.filled : bool, optional (default=False)When set to ``True``, paint nodes to indicate majority class forclassification, extremity of values for regression, or purity of nodefor multi-output.leaves_parallel : bool, optional (default=False)When set to ``True``, draw all leaf nodes at the bottom of the tree.impurity : bool, optional (default=True)When set to ``True``, show the impurity at each node.node_ids : bool, optional (default=False)When set to ``True``, show the ID number on each node.proportion : bool, optional (default=False)When set to ``True``, change the display of 'values' and/or 'samples'to be proportions and percentages respectively.rotate : bool, optional (default=False)When set to ``True``, orient tree left to right rather than top-down.rounded : bool, optional (default=False)When set to ``True``, draw node boxes with rounded corners and useHelvetica fonts instead of Times-Roman.special_characters : bool, optional (default=False)When set to ``False``, ignore special characters for PostScriptcompatibility.precision : int, optional (default=3)Number of digits of precision for floating point in the values ofimpurity, threshold and value attributes of each node.Returns-------dot_data : stringString representation of the input tree in GraphViz dot format.Only returned if ``out_file`` is None... versionadded:: 0.18

總結

以上是生活随笔為你收集整理的决策树如何可视化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 九九热视频在线播放 | 黄色三级免费网站 | a免费观看 | 国产视频一区在线观看 | 黄色录像三级 | 奇米影视狠狠干 | 色婷婷久 | 已婚少妇美妙人妻系列 | 丰满岳乱妇在线观看中字无码 | 日本韩国欧美一区二区三区 | 国产精品久久久久久久免费看 | 国产黑丝在线视频 | 日韩在线观看 | 国产亚洲精品成人av在线 | 日韩 欧美 综合 | 国产伦精品一区二区三区88av | 日韩欧美高清一区 | 成人四色| 99蜜桃臀久久久欧美精品网站 | 亚洲欧美日韩电影 | 激情综合网站 | 好吊视频一区二区三区 | 久草资源福利 | 日韩和欧美的一区二区 | 俺来也av| 羞羞的软件 | 国产免费一区二区三区在线播放 | 亚洲五月网 | 天天综合网在线观看 | 精品亚洲一区二区三区四区五区高 | 国产v亚洲v天堂无码久久久 | 巨骚综合| 中国精品视频 | 日本香蕉视频 | 亚洲午夜久久久久久久久久久 | 国产成人av一区二区三区在线观看 | 青青视频免费在线观看 | 一区二区三区不卡视频在线观看 | 韩国毛片一区二区三区 | 一区二区三区精品国产 | 国产精品久久久久电影 | 国产69精品一区二区 | 免费一级淫片aaa片毛片a级 | 久久亚洲精品石原莉奈 | 成人动漫av在线 | 天天做夜夜操 | 国产福利电影在线 | 九色91popny蝌蚪新疆 | 99热8| 国产精品毛片视频 | 91欧美日韩麻豆精品 | 亚洲69视频 | 日本在线视频不卡 | 封神榜二在线高清免费观看 | 男人操女人的免费视频 | 中文字幕永久在线观看 | 天天想你在线观看完整版高清 | 一级欧美一级日韩片 | 不卡视频在线播放 | 日韩精品一区二区三区无码专区 | 嫩草天堂 | 国产99在线视频 | 欧美三个黑人玩3p | av2014天堂网 | 久久综合狠狠 | 97干干干 | 看了让人下面流水的视频 | 国产一级免费在线观看 | 91欧美一区二区三区 | 伊人网在线| 国产小视频一区 | 成人区一区二区 | 麻豆一区二区 | 女教师痴汉调教hd中字 | 不卡视频一区二区三区 | 国产精品综合久久 | 在线麻豆视频 | 日本三级生活片 | 精品国产91久久久久久久妲己 | 五月天丁香视频 | 在线不卡欧美 | 丁香婷婷网 | 精品国产传媒 | 欧美美女一区二区 | 国产精品极品白嫩 | 国产第20页 | 日本少妇久久 | 免费观看成人鲁鲁鲁鲁鲁视频 | 美女脱光内衣内裤 | 久久丝袜美腿 | 亚洲国产一区二区a毛片 | 日本免费黄色片 | 伊人开心网 | 欧美成人aa | 久久久涩 | 牛牛精品一区 | 亚洲同性gay激情无套 | 国产又粗又猛又爽又黄视频 | 我的好妈妈在线观看 |