TP_Regression.ipynb 57.5 KB
Newer Older
TheophilePACE's avatar
TheophilePACE committed
1 2 3 4 5 6
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Long Le's avatar
Long Le committed
7 8
    "# TP Apprentissage supervisé: Régression\n",
    "Dans ce TP, on va faire la regression. C'est pour analyser la relation d'une variable par rapport à une ou plusieurs autres."
TheophilePACE's avatar
TheophilePACE committed
9 10 11 12 13 14 15 16 17 18 19 20 21
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dataset"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Long Le's avatar
Long Le committed
22 23 24 25 26 27 28
    "On va utiliser les données Boston.\n",
    "https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html\n",
    "\n",
    "Prix des maisons à Boston (cf le site pour les variables)\n",
    "https://scikit-learn.org/stable/datasets/index.html#boston-dataset\n",
    "\n",
    "Importez les libraries de ce matin: `numpy` et `scikit datasets`.\n",
TheophilePACE's avatar
TheophilePACE committed
29
    "Consultation de la doc du dataset\n",
Long Le's avatar
Long Le committed
30
    "\n",
TheophilePACE's avatar
TheophilePACE committed
31 32 33
    "Chargement du dataset boston"
   ]
  },
Long Le's avatar
Long Le committed
34 35
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
36
   "execution_count": 1,
Long Le's avatar
Long Le committed
37 38
   "metadata": {},
   "outputs": [],
TheophilePACE's avatar
TheophilePACE committed
39 40 41 42 43 44 45
   "source": [
    "import numpy as np \n",
    "from sklearn import datasets\n",
    "boston = datasets.load_boston()\n",
    "X, y = boston.data, boston.target\n",
    "feature_names = boston.feature_names"
   ]
Long Le's avatar
Long Le committed
46
  },
TheophilePACE's avatar
TheophilePACE committed
47 48 49 50 51
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Analyse exploratoire et préparation du dataset\n",
Long Le's avatar
Long Le committed
52
    "Étudier les corrélations en utilisant `np.corrcoef`"
TheophilePACE's avatar
TheophilePACE committed
53 54 55
   ]
  },
  {
Long Le's avatar
Long Le committed
56
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a1f711e80>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWYAAAD8CAYAAABErA6HAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAHWpJREFUeJzt3XuYHFWd//H3JwkJl4S7RiBAYA2uCMolxtsKyM2gPkRUdhEv0R8QvCDgDcITxUUXJOKC+iyuGxF+QVcuIkJEFBAW1p+KJsgtCWBiwDAkJGK4bpAkM9/fH11hO8N0V/fU6Zmams+Lp56p6ar+9GmSfOfM6VOnFBGYmVl5jBjsBpiZ2aZcmM3MSsaF2cysZFyYzcxKxoXZzKxkXJjNzErGhdnMrGRcmM3MSsaF2cysZEZ1+gXWP7Es6aWF5x74xZRxAHz60FXJM3960yuS5h39ztVJ8wBm37Jj0rzP7v9Y0jyAk/+wbfLMuWdNTBu4dm3aPODZeUuS5n3y4a2T5gFcNq0neea4b92gohnt1JzNdtyz8Ot1gnvMZmYl0/Ees5nZgOrpHuwWFObCbGbV0r1hsFtQmAuzmVVKRPqx74Hmwmxm1dIzDAqzpL8HpgG7AAGsAOZFxAMdbpuZWfsq0GNuOitD0pnAlYCA3wPzs/0rJM3sfPPMzNrU0936VlJ5PeYTgNdExPr6ByVdCCw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glyA44ArioZExGPA14HlwErg6Yi4uUDkQuAgSTtI2hJ4B7Br0XZmxkfESqh1IICXJ8rtlP8D/HywG1F2ZSjM6uOxUk4VkTSW2t1cTo+IZ4rmRUR3ROxHrQcxRdI+Bdr2LmB1RNxVtF29vCUiDgCOAj4p6aCCeaOo/ar77xGxP/A/1H4FL0TSaOBo4EcJsraj1hPdA9gZ2ErSB/ubFxEPUPsV/hbgF9SG6zY0fVIFZTfa2AD852C3pezKUJi72LT3MIFivzZ2hKTNqBXl/4yIa1NmZ7/K3w5MLRDzFuBoSY9QGw46VNIPErRtRfZ1NfATakNPRXQBXXW/HVxDrVAXdRTwh4hYlSDrcODhiPhLRKwHrgXeXCQwIr4XEQdExEHUftVfkqCdAKsk7QSQfV2dKDcpSdOBdwEfiGyw2RorQ2GeD0yStEfW6zkOmDfIbdqEJFEbE30gIi5MlPmyjZ9OS9qCWjF4sL95EXFWREyIiInU/h/eFhH97uVl7dpK0riN+9Q+xCk00yUiHgcelfSq7KHDgMVFMjPvJ8EwRmY58EZJW2Z/9odR+1yh3yS9PPu6G/Ae0rV1HjA9258OXJ8oNxlJU4EzgaMjYu1gt2dIGOxPH7Mfnu+gNtPhT8CsBHlXUBsbXE+th3ZCwbx/oDa8ch9wT7a9o2Dma4G7s8yFwNkJ/38eQoJZGdTGg+/NtkUp/myy3P2ABdl7vw7YrmDelsBfgW0S/j88h9oPyoXA94ExBfN+Re0H0L3AYf3MeMnfa2AH4FZqPfBbge0TZB6T7b9AbYXJmwrmLaX2OdLGfzvfSfXnVNXNV/6ZmZVMGYYyzMysjguzmVnJuDCbmZWMC7OZWcm4MJuZlYwLs5lZybgwm5mVjAuzmVnJ/H8Lf17IM1e0EgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "sns.heatmap(np.corrcoef(X.T))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD',\n",
       "       'TAX', 'PTRATIO', 'B', 'LSTAT'], dtype='<U7')"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_names"
   ]
TheophilePACE's avatar
TheophilePACE committed
106 107 108 109 110
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Long Le's avatar
Long Le committed
111 112 113
    "Split du dataset boston\n",
    "\n",
    "Pour cela, utilisez la fonction scikit-learn `sklearn.model_selection.train_test_split`. Importez cette méthode, "
TheophilePACE's avatar
TheophilePACE committed
114 115
   ]
  },
Long Le's avatar
Long Le committed
116 117
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
118
   "execution_count": 7,
Long Le's avatar
Long Le committed
119 120
   "metadata": {},
   "outputs": [],
TheophilePACE's avatar
TheophilePACE committed
121 122 123 124 125
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "X_tv,X_test,y_tv,y_test = train_test_split(X,y,test_size=.2)\n",
    "X_train,X_validation,y_train,y_validation = train_test_split(X_tv,y_tv,test_size=.25)"
   ]
Long Le's avatar
Long Le committed
126
  },
TheophilePACE's avatar
TheophilePACE committed
127 128 129 130 131 132
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Linear regression\n",
    "Modèle classique, assez peu puissant et interprétable. Basée sur la Mean Square Error. Très sensible au outliers.\n",
TheophilePACE's avatar
TheophilePACE committed
133 134 135
    "\n",
    "![](https://upload.wikimedia.org/wikipedia/commons/3/3a/Linear_regression.svg)\n",
    "\n",
TheophilePACE's avatar
TheophilePACE committed
136 137 138
    "Trouver le modèle sur scikit learn."
   ]
  },
Long Le's avatar
Long Le committed
139 140
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
141
   "execution_count": 10,
Long Le's avatar
Long Le committed
142 143
   "metadata": {},
   "outputs": [],
TheophilePACE's avatar
TheophilePACE committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "from sklearn.metrics import mean_squared_error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "linreg = LinearRegression()\n",
    "linreg.fit(X_train,y_train)\n",
    "pred = linreg.predict(X_validation)\n",
    "mse = mean_squared_error(y_pred=pred,y_true=y_validation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD',\n",
       "       'TAX', 'PTRATIO', 'B', 'LSTAT'], dtype='<U7')"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39.481226596127605"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linreg.intercept_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method RegressorMixin.score of LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None,\n",
       "         normalize=False)>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linreg.score"
   ]
Long Le's avatar
Long Le committed
222
  },
TheophilePACE's avatar
TheophilePACE committed
223 224 225 226 227 228 229
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run sur boston. afficher les coef de chaque features. Quelles features sont significative?"
   ]
  },
Long Le's avatar
Long Le committed
230 231
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1.14234728e-01,  5.55923762e-02,  2.55592631e-02,  2.86592242e+00,\n",
       "       -1.71089986e+01,  3.53718449e+00, -2.04686250e-03, -1.74720480e+00,\n",
       "        3.56702414e-01, -1.39014036e-02, -9.66897760e-01,  1.20770497e-02,\n",
       "       -5.98533043e-01])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linreg.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23.984703524807863"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17.305306709963975"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pred = linreg.predict(X_test)\n",
    "mse_linreg = mean_squared_error(y_pred=pred,y_true=y_test)\n",
    "mse_linreg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Expected 2D array, got scalar array instead:\narray=0.007248.\nReshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m----------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                           Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-55-f30ba0c6c93c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mmlxtend\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplotting\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mplot_linear_regression\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mintercept\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mslope\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcorr_coeff\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplot_linear_regression\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my_train\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0my_train\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/lib/python3.6/site-packages/mlxtend/plotting/plot_linear_regression.py\u001b[0m in \u001b[0;36mplot_linear_regression\u001b[0;34m(X, y, model, corr_func, scattercolor, fit_style, legend, xlim)\u001b[0m\n\u001b[1;32m     75\u001b[0m         \u001b[0mx_min\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx_max\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mxlim\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     76\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 77\u001b[0;31m     \u001b[0my_min\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_min\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     78\u001b[0m     \u001b[0my_max\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_max\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     79\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/lib/python3.6/site-packages/sklearn/linear_model/base.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, X)\u001b[0m\n\u001b[1;32m    211\u001b[0m             \u001b[0mReturns\u001b[0m \u001b[0mpredicted\u001b[0m \u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    212\u001b[0m         \"\"\"\n\u001b[0;32m--> 213\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_decision_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    214\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    215\u001b[0m     \u001b[0m_preprocess_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstaticmethod\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_preprocess_data\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/miniconda3/lib/python3.6/site-packages/sklearn/linear_model/base.py\u001b[0m in \u001b[0;36m_decision_function\u001b[0;34m(self, X)\u001b[0m\n\u001b[1;32m    194\u001b[0m         \u001b[0mcheck_is_fitted\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"coef_\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    195\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 196\u001b[0;31m         \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcheck_array\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maccept_sparse\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'csr'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'csc'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'coo'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    197\u001b[0m         return safe_sparse_dot(X, self.coef_.T,\n\u001b[1;32m    198\u001b[0m                                dense_output=True) + self.intercept_\n",
      "\u001b[0;32m~/miniconda3/lib/python3.6/site-packages/sklearn/utils/validation.py\u001b[0m in \u001b[0;36mcheck_array\u001b[0;34m(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)\u001b[0m\n\u001b[1;32m    543\u001b[0m                     \u001b[0;34m\"Reshape your data either using array.reshape(-1, 1) if \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    544\u001b[0m                     \u001b[0;34m\"your data has a single feature or array.reshape(1, -1) \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 545\u001b[0;31m                     \"if it contains a single sample.\".format(array))\n\u001b[0m\u001b[1;32m    546\u001b[0m             \u001b[0;31m# If input is 1D raise error\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    547\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0marray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: Expected 2D array, got scalar array instead:\narray=0.007248.\nReshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample."
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAGj1JREFUeJzt3W1sZNddx/Hff71rgpOiZL1OtST1uJWi0hSJPlhVQlEVJQVBqKAv2gIaolUJWshWYnkSDewrXliiCFH2BaWymkSrrnmoQlGiKkJES4oKQgEvLbRpiFLKOoQu3V1vFpJGYhPvnxfnDp4Z36cZX9859873I43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wu1+eSCEnxMzukvTr7v4BM3uLQo39oKQvS/pZd//fSZavTmb2DoVO4llJ35T0UYVK21TeI2b225J+SiFL7MuSfl6hzby190gjAjoAoFgTmlwAACUQ0AGgJQjoANASBHQAaAkCOgC0BAEdAFqCgA4ALUFAB4CW+D9jFloMo/hZqAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from mlxtend.plotting import plot_linear_regression\n",
    "intercept, slope, corr_coeff = plot_linear_regression(X_train[:,0], np.array(y_train))\n",
    "plt.show()\n",
    "y_train"
   ]
Long Le's avatar
Long Le committed
332
  },
TheophilePACE's avatar
TheophilePACE committed
333 334 335 336 337
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Arbre de régression\n",
TheophilePACE's avatar
TheophilePACE committed
338 339 340
    "![](https://i0.wp.com/freakonometrics.hypotheses.org/files/2015/06/boosting-algo-3.gif?zoom=2&w=456&ssl=1)\n",
    "\n",
    "Les arbres de régression sont des modèles très puissants, qui divisent l'espace en zone où tout les points ont le même output. On trouvera dans scikit: https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeRegressor.html"
TheophilePACE's avatar
TheophilePACE committed
341 342
   ]
  },
Long Le's avatar
Long Le committed
343 344
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
345
   "execution_count": 25,
Long Le's avatar
Long Le committed
346 347
   "metadata": {},
   "outputs": [],
TheophilePACE's avatar
TheophilePACE committed
348 349 350 351
   "source": [
    "import matplotlib.gridspec as gridspec\n",
    "from matplotlib import pyplot as plt"
   ]
Long Le's avatar
Long Le committed
352
  },
TheophilePACE's avatar
TheophilePACE committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "from graphviz import Source\n",
    "from sklearn.tree import export_graphviz\n",
    "from IPython.display import SVG\n",
    "\n",
    "\n",
    "def visualize_tree(clf):\n",
    "    dotefile_string = export_graphviz(clf, out_file=None,feature_names=feature_names)\n",
    "    graph = Source(dotefile_string)\n",
    "    return SVG(graph.pipe('svg'))"
   ]
  },
TheophilePACE's avatar
TheophilePACE committed
370 371 372 373 374 375 376
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec une profondeur max de 3"
   ]
  },
Long Le's avatar
Long Le committed
377 378
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23.16271238111014"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeRegressor\n",
    "tree_3 = DecisionTreeRegressor(max_depth=3)\n",
    "tree_3.fit(X_train,y_train)\n",
    "pred = tree_3.predict(X_validation)\n",
    "mse_tree = mean_squared_error(y_pred=pred,y_true=y_validation)\n",
    "mse_tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg height=\"373pt\" viewBox=\"0.00 0.00 913.50 373.00\" width=\"914pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g class=\"graph\" id=\"graph0\" transform=\"scale(1 1) rotate(0) translate(4 369)\">\n",
       "<title>Tree</title>\n",
       "<polygon fill=\"#ffffff\" points=\"-4,4 -4,-369 909.5,-369 909.5,4 -4,4\" stroke=\"transparent\"/>\n",
       "<!-- 0 -->\n",
       "<g class=\"node\" id=\"node1\">\n",
       "<title>0</title>\n",
       "<polygon fill=\"none\" points=\"477.5,-365 363.5,-365 363.5,-297 477.5,-297 477.5,-365\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"420.5\" y=\"-349.8\">LSTAT &lt;= 5.155</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"420.5\" y=\"-334.8\">mse = 91.669</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"420.5\" y=\"-319.8\">samples = 303</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"420.5\" y=\"-304.8\">value = 23.227</text>\n",
       "</g>\n",
       "<!-- 1 -->\n",
       "<g class=\"node\" id=\"node2\">\n",
       "<title>1</title>\n",
       "<polygon fill=\"none\" points=\"405.5,-261 305.5,-261 305.5,-193 405.5,-193 405.5,-261\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-245.8\">RM &lt;= 7.406</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-230.8\">mse = 77.549</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-215.8\">samples = 42</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-200.8\">value = 39.755</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;1 -->\n",
       "<g class=\"edge\" id=\"edge1\">\n",
       "<title>0-&gt;1</title>\n",
       "<path d=\"M399.2166,-296.9465C393.7733,-288.2373 387.8516,-278.7626 382.175,-269.6801\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"385.0993,-267.755 376.8312,-261.13 379.1633,-271.465 385.0993,-267.755\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"371.2098\" y=\"-281.7898\">True</text>\n",
       "</g>\n",
       "<!-- 8 -->\n",
       "<g class=\"node\" id=\"node9\">\n",
       "<title>8</title>\n",
       "<polygon fill=\"none\" points=\"589,-261 468,-261 468,-193 589,-193 589,-261\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-245.8\">LSTAT &lt;= 14.885</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-230.8\">mse = 42.908</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-215.8\">samples = 261</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-200.8\">value = 20.567</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;8 -->\n",
       "<g class=\"edge\" id=\"edge8\">\n",
       "<title>0-&gt;8</title>\n",
       "<path d=\"M455.8632,-296.9465C465.3736,-287.7884 475.763,-277.7838 485.6335,-268.2788\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"488.2818,-270.5876 493.0573,-261.13 483.4263,-265.5453 488.2818,-270.5876\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"492.5857\" y=\"-282.4255\">False</text>\n",
       "</g>\n",
       "<!-- 2 -->\n",
       "<g class=\"node\" id=\"node3\">\n",
       "<title>2</title>\n",
       "<polygon fill=\"none\" points=\"204.5,-157 104.5,-157 104.5,-89 204.5,-89 204.5,-157\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"154.5\" y=\"-141.8\">TAX &lt;= 534.0</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"154.5\" y=\"-126.8\">mse = 55.674</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"154.5\" y=\"-111.8\">samples = 23</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"154.5\" y=\"-96.8\">value = 33.904</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;2 -->\n",
       "<g class=\"edge\" id=\"edge2\">\n",
       "<title>1-&gt;2</title>\n",
       "<path d=\"M305.2977,-201.0247C277.5979,-186.6924 243.0297,-168.8064 213.9808,-153.7761\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"215.2489,-150.4916 204.7589,-149.0046 212.0321,-156.7087 215.2489,-150.4916\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 5 -->\n",
       "<g class=\"node\" id=\"node6\">\n",
       "<title>5</title>\n",
       "<polygon fill=\"none\" points=\"417,-157 294,-157 294,-89 417,-89 417,-157\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-141.8\">PTRATIO &lt;= 17.9</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-126.8\">mse = 12.439</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-111.8\">samples = 19</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"355.5\" y=\"-96.8\">value = 46.837</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;5 -->\n",
       "<g class=\"edge\" id=\"edge5\">\n",
       "<title>1-&gt;5</title>\n",
       "<path d=\"M355.5,-192.9465C355.5,-184.776 355.5,-175.9318 355.5,-167.3697\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"359.0001,-167.13 355.5,-157.13 352.0001,-167.13 359.0001,-167.13\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 3 -->\n",
       "<g class=\"node\" id=\"node4\">\n",
       "<title>3</title>\n",
       "<polygon fill=\"none\" points=\"93,-53 0,-53 0,0 93,0 93,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"46.5\" y=\"-37.8\">mse = 19.336</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"46.5\" y=\"-22.8\">samples = 20</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"46.5\" y=\"-7.8\">value = 31.49</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;3 -->\n",
       "<g class=\"edge\" id=\"edge3\">\n",
       "<title>2-&gt;3</title>\n",
       "<path d=\"M116.4232,-88.9777C105.8676,-79.546 94.4204,-69.3178 83.9036,-59.9208\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"86.2251,-57.3015 76.4361,-53.2485 81.561,-62.5213 86.2251,-57.3015\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 4 -->\n",
       "<g class=\"node\" id=\"node5\">\n",
       "<title>4</title>\n",
       "<polygon fill=\"none\" points=\"197.5,-53 111.5,-53 111.5,0 197.5,0 197.5,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"154.5\" y=\"-37.8\">mse = 0.0</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"154.5\" y=\"-22.8\">samples = 3</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"154.5\" y=\"-7.8\">value = 50.0</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;4 -->\n",
       "<g class=\"edge\" id=\"edge4\">\n",
       "<title>2-&gt;4</title>\n",
       "<path d=\"M154.5,-88.9777C154.5,-80.7364 154.5,-71.887 154.5,-63.5153\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"158.0001,-63.2484 154.5,-53.2485 151.0001,-63.2485 158.0001,-63.2484\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 6 -->\n",
       "<g class=\"node\" id=\"node7\">\n",
       "<title>6</title>\n",
       "<polygon fill=\"none\" points=\"315.5,-53 215.5,-53 215.5,0 315.5,0 315.5,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"265.5\" y=\"-37.8\">mse = 8.135</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"265.5\" y=\"-22.8\">samples = 16</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"265.5\" y=\"-7.8\">value = 47.788</text>\n",
       "</g>\n",
       "<!-- 5&#45;&gt;6 -->\n",
       "<g class=\"edge\" id=\"edge6\">\n",
       "<title>5-&gt;6</title>\n",
       "<path d=\"M323.7694,-88.9777C315.2292,-79.8207 305.9887,-69.9129 297.4374,-60.744\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"299.8269,-58.1744 290.4468,-53.2485 294.7077,-62.9488 299.8269,-58.1744\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 7 -->\n",
       "<g class=\"node\" id=\"node8\">\n",
       "<title>7</title>\n",
       "<polygon fill=\"none\" points=\"433.5,-53 333.5,-53 333.5,0 433.5,0 433.5,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"383.5\" y=\"-37.8\">mse = 4.869</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"383.5\" y=\"-22.8\">samples = 3</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"383.5\" y=\"-7.8\">value = 41.767</text>\n",
       "</g>\n",
       "<!-- 5&#45;&gt;7 -->\n",
       "<g class=\"edge\" id=\"edge7\">\n",
       "<title>5-&gt;7</title>\n",
       "<path d=\"M365.3718,-88.9777C367.8161,-80.5533 370.4449,-71.4934 372.9215,-62.9579\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"376.3135,-63.8277 375.7388,-53.2485 369.5907,-61.877 376.3135,-63.8277\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 9 -->\n",
       "<g class=\"node\" id=\"node10\">\n",
       "<title>9</title>\n",
       "<polygon fill=\"none\" points=\"578.5,-157 478.5,-157 478.5,-89 578.5,-89 578.5,-157\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-141.8\">RM &lt;= 6.978</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-126.8\">mse = 29.74</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-111.8\">samples = 167</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"528.5\" y=\"-96.8\">value = 23.676</text>\n",
       "</g>\n",
       "<!-- 8&#45;&gt;9 -->\n",
       "<g class=\"edge\" id=\"edge9\">\n",
       "<title>8-&gt;9</title>\n",
       "<path d=\"M528.5,-192.9465C528.5,-184.776 528.5,-175.9318 528.5,-167.3697\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"532.0001,-167.13 528.5,-157.13 525.0001,-167.13 532.0001,-167.13\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 12 -->\n",
       "<g class=\"node\" id=\"node13\">\n",
       "<title>12</title>\n",
       "<polygon fill=\"none\" points=\"788,-157 687,-157 687,-89 788,-89 788,-157\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"737.5\" y=\"-141.8\">NOX &lt;= 0.661</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"737.5\" y=\"-126.8\">mse = 18.621</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"737.5\" y=\"-111.8\">samples = 94</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"737.5\" y=\"-96.8\">value = 15.044</text>\n",
       "</g>\n",
       "<!-- 8&#45;&gt;12 -->\n",
       "<g class=\"edge\" id=\"edge12\">\n",
       "<title>8-&gt;12</title>\n",
       "<path d=\"M589.2322,-196.7792C617.0608,-182.9315 649.9437,-166.5687 677.6626,-152.7756\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"679.4566,-155.7923 686.8502,-148.2037 676.3381,-149.5253 679.4566,-155.7923\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 10 -->\n",
       "<g class=\"node\" id=\"node11\">\n",
       "<title>10</title>\n",
       "<polygon fill=\"none\" points=\"551.5,-53 451.5,-53 451.5,0 551.5,0 551.5,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"501.5\" y=\"-37.8\">mse = 17.651</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"501.5\" y=\"-22.8\">samples = 149</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"501.5\" y=\"-7.8\">value = 22.638</text>\n",
       "</g>\n",
       "<!-- 9&#45;&gt;10 -->\n",
       "<g class=\"edge\" id=\"edge10\">\n",
       "<title>9-&gt;10</title>\n",
       "<path d=\"M518.9808,-88.9777C516.6237,-80.5533 514.0888,-71.4934 511.7007,-62.9579\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"515.0491,-61.9356 508.984,-53.2485 508.308,-63.8217 515.0491,-61.9356\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 11 -->\n",
       "<g class=\"node\" id=\"node12\">\n",
       "<title>11</title>\n",
       "<polygon fill=\"none\" points=\"669.5,-53 569.5,-53 569.5,0 669.5,0 669.5,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"619.5\" y=\"-37.8\">mse = 47.093</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"619.5\" y=\"-22.8\">samples = 18</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"619.5\" y=\"-7.8\">value = 32.267</text>\n",
       "</g>\n",
       "<!-- 9&#45;&gt;11 -->\n",
       "<g class=\"edge\" id=\"edge11\">\n",
       "<title>9-&gt;11</title>\n",
       "<path d=\"M560.5832,-88.9777C569.2183,-79.8207 578.5614,-69.9129 587.2078,-60.744\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"589.9617,-62.9251 594.276,-53.2485 584.8689,-58.1226 589.9617,-62.9251\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 13 -->\n",
       "<g class=\"node\" id=\"node14\">\n",
       "<title>13</title>\n",
       "<polygon fill=\"none\" points=\"787.5,-53 687.5,-53 687.5,0 787.5,0 787.5,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"737.5\" y=\"-37.8\">mse = 14.941</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"737.5\" y=\"-22.8\">samples = 46</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"737.5\" y=\"-7.8\">value = 17.474</text>\n",
       "</g>\n",
       "<!-- 12&#45;&gt;13 -->\n",
       "<g class=\"edge\" id=\"edge13\">\n",
       "<title>12-&gt;13</title>\n",
       "<path d=\"M737.5,-88.9777C737.5,-80.7364 737.5,-71.887 737.5,-63.5153\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"741.0001,-63.2484 737.5,-53.2485 734.0001,-63.2485 741.0001,-63.2484\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "<!-- 14 -->\n",
       "<g class=\"node\" id=\"node15\">\n",
       "<title>14</title>\n",
       "<polygon fill=\"none\" points=\"905.5,-53 805.5,-53 805.5,0 905.5,0 905.5,-53\" stroke=\"#000000\"/>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"855.5\" y=\"-37.8\">mse = 11.063</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"855.5\" y=\"-22.8\">samples = 48</text>\n",
       "<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"855.5\" y=\"-7.8\">value = 12.715</text>\n",
       "</g>\n",
       "<!-- 12&#45;&gt;14 -->\n",
       "<g class=\"edge\" id=\"edge14\">\n",
       "<title>12-&gt;14</title>\n",
       "<path d=\"M779.1024,-88.9777C790.7474,-79.4545 803.3854,-69.1191 814.9675,-59.6473\" fill=\"none\" stroke=\"#000000\"/>\n",
       "<polygon fill=\"#000000\" points=\"817.2667,-62.2885 822.792,-53.2485 812.8352,-56.8697 817.2667,-62.2885\" stroke=\"#000000\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "visualize_tree(tree_3)"
   ]
Long Le's avatar
Long Le committed
642
  },
TheophilePACE's avatar
TheophilePACE committed
643 644 645 646 647 648 649
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec une profondeur max de 5"
   ]
  },
Long Le's avatar
Long Le committed
650 651
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15.383911132931058"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tree = DecisionTreeRegressor(max_depth=5)\n",
    "tree.fit(X_train,y_train)\n",
    "pred = tree.predict(X_validation)\n",
    "mse_tree = mean_squared_error(y_pred=pred,y_true=y_validation)\n",
    "mse_tree"
   ]
Long Le's avatar
Long Le committed
673
  },
TheophilePACE's avatar
TheophilePACE committed
674 675 676 677 678 679 680
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec une profondeur max de 10"
   ]
  },
Long Le's avatar
Long Le committed
681 682
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15.935984288699112"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tree = DecisionTreeRegressor(max_depth=10)\n",
    "tree.fit(X_train,y_train)\n",
    "pred = tree.predict(X_validation)\n",
    "mse_tree = mean_squared_error(y_pred=pred,y_true=y_validation)\n",
    "mse_tree\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16.040198019801984"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tree = DecisionTreeRegressor(max_depth=50)\n",
    "tree.fit(X_train,y_train)\n",
    "pred = tree.predict(X_validation)\n",
    "mse_tree = mean_squared_error(y_pred=pred,y_true=y_validation)\n",
    "mse_tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.09 ms ± 52.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n",
      "2.22 ms ± 113 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
      "2.15 ms ± 15.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit tree = DecisionTreeRegressor(max_depth=5).fit(X_train,y_train)\n",
    "%timeit tree = DecisionTreeRegressor(max_depth=50).fit(X_train,y_train)\n",
    "%timeit tree = DecisionTreeRegressor(max_depth=100).fit(X_train,y_train)"
   ]
Long Le's avatar
Long Le committed
749
  },
TheophilePACE's avatar
TheophilePACE committed
750 751 752 753 754 755 756
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparer les résultats"
   ]
  },
Long Le's avatar
Long Le committed
757 758 759 760 761
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
TheophilePACE's avatar
TheophilePACE committed
762 763 764 765 766 767 768
   "source": [
    "tree = DecisionTreeRegressor(max_depth=5)\n",
    "tree.fit(X_train,y_train)\n",
    "pred = tree.predict(X_validation)\n",
    "mse_tree = mean_squared_error(y_pred=pred,y_true=y_validation)\n",
    "mse_tree"
   ]
Long Le's avatar
Long Le committed
769
  },
TheophilePACE's avatar
TheophilePACE committed
770 771 772 773 774 775 776 777 778 779
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Random forest\n",
    "Trouver sur scikit\n",
    "image\n",
    "modèle"
   ]
  },
Long Le's avatar
Long Le committed
780 781
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
782
   "execution_count": 56,
Long Le's avatar
Long Le committed
783 784
   "metadata": {},
   "outputs": [],
TheophilePACE's avatar
TheophilePACE committed
785 786 787
   "source": [
    "from sklearn.ensemble import RandomForestRegressor"
   ]
Long Le's avatar
Long Le committed
788
  },
TheophilePACE's avatar
TheophilePACE committed
789 790 791 792 793 794 795
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec 3 arbres"
   ]
  },
Long Le's avatar
Long Le committed
796 797
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16.73265126512651"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf = RandomForestRegressor(n_estimators=3)\n",
    "clf.fit(X_train,y_train)\n",
    "pred = clf.predict(X_validation)\n",
    "mean_squared_error(pred,y_validation)"
   ]
Long Le's avatar
Long Le committed
818
  },
TheophilePACE's avatar
TheophilePACE committed
819 820 821 822 823 824 825
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec 10 arbres"
   ]
  },
Long Le's avatar
Long Le committed
826 827
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.328624752475244"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf = RandomForestRegressor(n_estimators=10)\n",
    "clf.fit(X_train,y_train)\n",
    "pred = clf.predict(X_validation)\n",
    "mean_squared_error(pred,y_validation)"
   ]
Long Le's avatar
Long Le committed
848
  },
TheophilePACE's avatar
TheophilePACE committed
849 850 851 852 853 854 855
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "100 arbres"
   ]
  },
Long Le's avatar
Long Le committed
856 857
  {
   "cell_type": "code",
TheophilePACE's avatar
TheophilePACE committed
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.36942520792078"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf = RandomForestRegressor(n_estimators=100)\n",
    "clf.fit(X_train,y_train)\n",
    "pred = clf.predict(X_validation)\n",
    "mean_squared_error(pred,y_validation)"
   ]
Long Le's avatar
Long Le committed
878
  },
TheophilePACE's avatar
TheophilePACE committed
879 880 881 882 883 884 885
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparer avec les arbres de régression. Quels sont les avantages?"
   ]
  },
Long Le's avatar
Long Le committed
886 887 888 889 890 891 892
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
893 894 895 896 897 898 899
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "_optionel_ Tracer le résultat avec 1 arbre, 3 arbres et 100 arbres "
   ]
  },
Long Le's avatar
Long Le committed
900 901 902 903 904 905 906
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
907 908 909 910 911 912 913 914 915
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Si vous vous ennuyez\n",
    "Comparer les différents modèles, en lançant tout ça su le test\n",
    "\n",
    "Faire une régression sur le résultat d'une PCA (touchy)\n"
   ]
Long Le's avatar
Long Le committed
916 917 918 919 920 921 922
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
TheophilePACE's avatar
TheophilePACE committed
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
  }
 ],
 "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",
TheophilePACE's avatar
TheophilePACE committed
941
   "version": "3.6.6"
TheophilePACE's avatar
TheophilePACE committed
942 943 944 945 946
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}