科学の箱

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

RoboBrowserでUser Agentが原因ではねられているとき

RoboBrowserを利用していると通常のブラウザでリクエストした時とは異なりエラーがページが返ってくることが多い。 原因はいくつかあるがまず試したいのはUser-Agentの設定。 RoboBro …

no image

pandaの基本中の基本操作

numpyとpandaのインポート import numpy as np import pandas as pd 前準備 labels = [‘a’, ‘b’, ‘c’] mydata = [10,2 …

no image

scikit-learnで適切なアルゴリズムを選択するためのチートシート

  http://scikit-learn.org/stable/tutorial/machine_learning_map/index.html Related posts:tensorf …

no image

タイタニックデータでEDA

タイタニックデータでEDAを実施する。 まずはライブラリの読み込み import pandas as pd import numpy as np import matplotlib.pyplot as …

no image

pyplotでグラフを表示

matplotlib.pyplotを利用すると、配列からお手軽にグラフを作成できる。 内容 最もシンプルなグラフ タイトル ラベル、レジェンドを追加 線の種類を変える 最もシンプルなグラフ まずはpy …

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

side bar top



アーカイブ

カテゴリー