TP_Regression.ipynb 5.69 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 36 37 38 39 40
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
41 42 43 44 45
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Analyse exploratoire et préparation du dataset\n",
Long Le's avatar
Long Le committed
46
    "Étudier les corrélations en utilisant `np.corrcoef`"
TheophilePACE's avatar
TheophilePACE committed
47 48 49
   ]
  },
  {
Long Le's avatar
Long Le committed
50 51
   "cell_type": "code",
   "execution_count": null,
TheophilePACE's avatar
TheophilePACE committed
52
   "metadata": {},
Long Le's avatar
Long Le committed
53 54
   "outputs": [],
   "source": []
TheophilePACE's avatar
TheophilePACE committed
55 56 57 58 59
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
Long Le's avatar
Long Le committed
60 61 62
    "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
63 64
   ]
  },
Long Le's avatar
Long Le committed
65 66 67 68 69 70 71
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
72 73 74 75 76 77 78 79 80
  {
   "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",
    "Trouver le modèle sur scikit learn."
   ]
  },
Long Le's avatar
Long Le committed
81 82 83 84 85 86 87
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
88 89 90 91 92 93 94
  {
   "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
95 96 97 98 99 100 101
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
102 103 104 105 106
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Arbre de régression\n",
Long Le's avatar
Long Le committed
107
    "![](https://fr.wikipedia.org/wiki/Arbre_de_d%C3%A9cision#/media/File:Arbre_de_decision.jpg)"
TheophilePACE's avatar
TheophilePACE committed
108 109
   ]
  },
Long Le's avatar
Long Le committed
110 111 112 113 114 115 116
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
117 118 119 120 121 122 123
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec une profondeur max de 3"
   ]
  },
Long Le's avatar
Long Le committed
124 125 126 127 128 129 130
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
131 132 133 134 135 136 137
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec une profondeur max de 5"
   ]
  },
Long Le's avatar
Long Le committed
138 139 140 141 142 143 144
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
145 146 147 148 149 150 151
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec une profondeur max de 10"
   ]
  },
Long Le's avatar
Long Le committed
152 153 154 155 156 157 158
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
159 160 161 162 163 164 165
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparer les résultats"
   ]
  },
Long Le's avatar
Long Le committed
166 167 168 169 170 171 172
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
173 174 175 176 177 178 179 180 181 182
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Random forest\n",
    "Trouver sur scikit\n",
    "image\n",
    "modèle"
   ]
  },
Long Le's avatar
Long Le committed
183 184 185 186 187 188 189
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
190 191 192 193 194 195 196
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec 3 arbres"
   ]
  },
Long Le's avatar
Long Le committed
197 198 199 200 201 202 203
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
204 205 206 207 208 209 210
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Essayer avec 10 arbres"
   ]
  },
Long Le's avatar
Long Le committed
211 212 213 214 215 216 217
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
218 219 220 221 222 223 224
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "100 arbres"
   ]
  },
Long Le's avatar
Long Le committed
225 226 227 228 229 230 231
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
232 233 234 235 236 237 238
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparer avec les arbres de régression. Quels sont les avantages?"
   ]
  },
Long Le's avatar
Long Le committed
239 240 241 242 243 244 245
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
246 247 248 249 250 251 252
  {
   "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
253 254 255 256 257 258 259
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
TheophilePACE's avatar
TheophilePACE committed
260 261 262 263 264 265 266 267 268
  {
   "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
269 270 271 272 273 274 275
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
TheophilePACE's avatar
TheophilePACE committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
  }
 ],
 "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
294
   "version": "3.6.6"
TheophilePACE's avatar
TheophilePACE committed
295 296 297 298 299
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}