科学の箱

科学・IT・登山の話題

Python

graphvizによる決定木の表示

投稿日:

graphvizの実行ファイルをインストール

https://graphviz.gitlab.io/_pages/Download/Download_windows.html

pythonにgraphvizをインストール

pip install graphviz

pythonからサンプルコード実行

from sklearn.datasets import load_breast_cancer
from sklearn.tree import DecisionTreeClassifier

cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target, stratify=cancer.target, random_state=42)
tree = DecisionTreeClassifier(random_state=0)
tree.fit(X_train, y_train)

from sklearn.tree import export_graphviz
export_graphviz(tree, out_file=”tree.dot”, class_names=[“malignant”, “benign”],feature_names=cancer.feature_names, impurity=False, filled=True)

import graphviz
with open(“tree.dot”) as f:
dot_graph = f.read()
display(graphviz.Source(dot_graph))

メタ情報

inarticle



メタ情報

inarticle



-Python

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

pythonでpostgresqlを使うときに必要なモジュール

pip install psycopg2-binary Related posts:グリッドサーチUnionFindのfindについて処理を考える。蟻本 P42 硬貨の問題

no image

automated the boring – day 2

今日は簡単なUser認証のプロトタイプといえば恰好はよいが、 パスワードの入力 パスワードの突き合せ パスワードつきあわせの結果によりメッセージを変える name = ‘Mary’ password …

no image

pipインストールでエラーが出る場合

pipインストールでエラーが出る場合 Collecting tensorflow WARNING: Retrying (Retry(total=4, connect=None, read=None, …

no image

複数のグラフを表示する方法

ここでは以下を説明する。 複数のグラフを表示する2つの方法 サブプロットのグラフを整形 複数のグラフを表示する 複数のグラフを表示するためには二通りの方法がある。 subplots()を使ってあらかじ …

no image

dataframe形式で便利なのはいろいろなメソッドが用意されているから

dataframeにすることのメリットは何かといわれると、dataframeにしたとたんに様々な処理をメソッドで実行できるからである。 例えば値がNaNになっていると、処理を進めるうえでいろいろな問題 …

2018年11月
« 10月   12月 »
 1234
567891011
12131415161718
19202122232425
2627282930  

side bar top



アーカイブ

カテゴリー