科学の箱

科学・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 + Slack Bot – 1

こちらのページを参考にしてslack botを作成する。 https://www.fullstackpython.com/blog/build-first-slack-bot-python.html …

no image

pythonからoffice365 smtpを利用してメールを送信

Office365の設定はこちらにある。 PythonにおけるSMTPの利用はこちらにある。 下記はサンプルコード import smtplib from email.mime.text import …

no image

flip, fliplr, flipudを使って配列要素を上下左右、左右、上下反転する

画像処理などでは要素の値を配列全体で反転したいときがある。このようなときに役に立つのがflip, fliplr, flipudである。 flipのマニュアル fliprのマニュアル flipudのマニ …

no image

kaggle Titanic Tutorial – 4

名前から取得できるタイトルを分析に利用してみる。 タイトルは末尾に”.”がついているのでこれを利用して切り出す。 def get_title(name): if ‘.’ in …

no image

python data scientist bootcamp

pythonでdata分析をしたいと思ったが学校に通う時間もお金もない。udemyで検索したところ英語版であるが1400円!でコースが見つかったのでこちらを受けることにした。 https://www. …

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

side bar top



アーカイブ

カテゴリー