{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# DL85Classifier example to export tree as image\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score\nfrom dl85 import DL85Classifier\nimport graphviz\n\n\nprint(\"######################################################################\\n\"\n      \"#                      DL8.5 default classifier                      #\\n\"\n      \"######################################################################\")\n\n# read the dataset and split into features and targets\ndataset = np.genfromtxt(\"../datasets/anneal.txt\", delimiter=' ')\nX, y = dataset[:, 1:], dataset[:, 0]\n# split the dataset into training and test sets\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)\n\nclf = DL85Classifier(max_depth=2)\nclf.fit(X, y)\ny_pred = clf.predict(X_test)\n\n# show results\nprint(\"Model built in\", round(clf.runtime_, 4), \"seconds\")\nprint(\"Found tree:\", clf.tree_)\nprint(\"Confusion Matrix below\\n\", confusion_matrix(y_test, y_pred))\nprint(\"Accuracy on training set =\", round(clf.accuracy_, 4))\nprint(\"Accuracy on test set =\", round(accuracy_score(y_test, y_pred), 4))\n\n# print the tree\ndot = clf.export_graphviz()\ngraph = graphviz.Source(dot, format=\"png\")\ngraph.render(\"plots/anneal_odt\")"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}