.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_classifier_export_tree.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_classifier_export_tree.py: ================================== Default DL85Classifier export tree ================================== .. GENERATED FROM PYTHON SOURCE LINES 7-43 .. rst-class:: sphx-glr-script-out .. code-block:: none ###################################################################### # DL8.5 default classifier # ###################################################################### Model built in 0.002 seconds Confusion Matrix below [[ 9 25] [ 0 129]] Accuracy on training set = 0.8243 Accuracy on test set = 0.8466 Serialized json tree: {'feat': 5, 'left': {'feat': 32, 'left': {'value': 1, 'error': 44}, 'right': {'value': 0, 'error': 2}}, 'right': {'feat': 46, 'left': {'value': 1, 'error': 68}, 'right': {'value': 0, 'error': 0}}, 'proba': [0.2357473035439137, 0.7642526964560863]} | .. code-block:: default import graphviz import numpy as np from sklearn.metrics import confusion_matrix from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score from pydl85 import DL85Classifier print("######################################################################\n" "# DL8.5 default classifier #\n" "######################################################################") # read the dataset and split into features and targets dataset = np.genfromtxt("../datasets/anneal.txt", delimiter=' ') X, y = dataset[:, 1:], dataset[:, 0] # split the dataset into training and test sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) clf = DL85Classifier(max_depth=2, min_sup=1) clf.fit(X_train, y_train) y_pred = clf.predict(X_test) # show results print("Model built in", round(clf.runtime_, 4), "seconds") print("Confusion Matrix below\n", confusion_matrix(y_test, y_pred)) print("Accuracy on training set =", round(clf.accuracy_, 4)) print("Accuracy on test set =", round(accuracy_score(y_test, y_pred), 4)) # print the tree print("Serialized json tree:", clf.tree_) dot = clf.export_graphviz() # uncomment the following lines to save the tree as a png file # graph = graphviz.Source(dot, format="png") # graph.render("plots/anneal_odt") .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.057 seconds) .. _sphx_glr_download_auto_examples_plot_classifier_export_tree.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_classifier_export_tree.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_classifier_export_tree.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_