科学の箱

科学・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

配列を利用した四則演算とuniversal関数

四則演算 import numpy as np arr = np.arange(1,11) arr arr + arr arr * arr arr – 100 arr – arr [/cde] np. …

no image

matplotlibでfigureを利用する

matplotlibでfigureオブジェクトを利用するとグラフを表示する位置を細かく指定できる。 まずはfigureを使ってグラフを一つ表示してみる。 >>> import mat …

no image

python coding styleのツール

Pythonで使えるコーディングツール pep8 flake8 pylint   Related posts:python data scientist bootcampautomated …

no image

pythonでjanomeを使う

PythonでMecabを利用して形態要素解析に挑戦したところMecabが原因不明のエラーを引き起こしいったん断念。 代わりにJanomeを導入してみた。 Janomeは下記からインストーラを取得する …

no image

pythonでsha3をつかう

pip install sha3だと何かがダウンロードされるが下記のエラーが表示される。 c:\users\usera\appdata\local\temp\pip-install-1v_qtdxo\ …

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

side bar top



アーカイブ

カテゴリー