科学の箱

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

automated the boring – day9

https://automatetheboringstuff.com/chapter17/ >>> from PIL import Image &gt …

no image

janomeで品詞を解析する

  import sys import os from glob import glob from janome.tokenizer import Tokenizer def main(): …

no image

SIGNATE お弁当の需要予測-3

Seabornを利用してデータをビジュアル化してみる。 まずは売り上げの分布図から sns.distplot(d_train[‘y’], kde=False, rug=False, bins=50) …

no image

kaggle Titanic Tutorial – 10

いろいろ試しているがうまくいかないので、とりあえずAgeを正しく補完できるか調べる。 調査は線形回帰でどれくらい相関が出るかで判断する。   import numpy as nm impor …

no image

配列の属性を確認

numpyでは生成した配列の中身を確認するための属性が用意されている。 主な属性は以下の通り 次元数を確認:ndarray.ndim 各次元の大きさを確認:ndarray.shape 全部の要素数:n …

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

side bar top



アーカイブ

カテゴリー