{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# DL8.5 default predictive clustering\nThis example illustrates how to use the DL85Cluster class for predictive clustering.\nA second implementation of predictive clustering is provided in the plot_cluster_user.py\nexample. \n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nfrom sklearn.model_selection import train_test_split\nimport time\nfrom dl85 import DL85Cluster\n\ndataset = np.genfromtxt(\"../datasets/anneal.txt\", delimiter=' ')\nX = dataset[:, 1:]\nX_train, X_test = train_test_split(X, test_size=0.2, random_state=0)\n\n\nprint(\"####################################################################\\n\"\n      \"#                      DL8.5 default clustering                    #\\n\"\n      \"####################################################################\")\nclf = DL85Cluster(max_depth=1, time_limit=600)\nstart = time.perf_counter()\nprint(\"Model building...\")\nclf.fit(X_train)\nduration = time.perf_counter() - start\nprint(\"Model built. Duration of building =\", round(duration, 4), \"\\n\\n\\n\")\npredicted = clf.predict(X_test)\n\n\nprint(\"####################################################################\\n\"\n      \"#                DL8.5 default predictive clustering               #\\n\"\n      \"####################################################################\")\nX_train1 = X_train[:X_test.shape[0], :]\nclf = DL85Cluster(max_depth=1, time_limit=600)\nstart = time.perf_counter()\nprint(\"Model building...\")\nclf.fit(X_train1, X_test)\nduration = time.perf_counter() - start\nprint(\"Model built. Duration of building =\", round(duration, 4))\nprint(\"Xtrain1 is used to describe data while X_test is used to compute errors\")\npredicted = clf.predict(X_test)"
      ]
    }
  ],
  "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
}