TP_Regression.ipynb 5.69 KB
 TheophilePACE committed Jan 22, 2019 1 2 3 4 5 6 ``````{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ `````` Long Le committed Jan 22, 2019 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 committed Jan 22, 2019 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 committed Jan 22, 2019 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 committed Jan 22, 2019 29 `````` "Consultation de la doc du dataset\n", `````` Long Le committed Jan 22, 2019 30 `````` "\n", `````` TheophilePACE committed Jan 22, 2019 31 32 33 `````` "Chargement du dataset boston" ] }, `````` Long Le committed Jan 22, 2019 34 35 36 37 38 39 40 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 41 42 43 44 45 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "## Analyse exploratoire et préparation du dataset\n", `````` Long Le committed Jan 22, 2019 46 `````` "Étudier les corrélations en utilisant `np.corrcoef`" `````` TheophilePACE committed Jan 22, 2019 47 48 49 `````` ] }, { `````` Long Le committed Jan 22, 2019 50 51 `````` "cell_type": "code", "execution_count": null, `````` TheophilePACE committed Jan 22, 2019 52 `````` "metadata": {}, `````` Long Le committed Jan 22, 2019 53 54 `````` "outputs": [], "source": [] `````` TheophilePACE committed Jan 22, 2019 55 56 57 58 59 `````` }, { "cell_type": "markdown", "metadata": {}, "source": [ `````` Long Le committed Jan 22, 2019 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 committed Jan 22, 2019 63 64 `````` ] }, `````` Long Le committed Jan 22, 2019 65 66 67 68 69 70 71 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 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 committed Jan 22, 2019 81 82 83 84 85 86 87 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 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 committed Jan 22, 2019 95 96 97 98 99 100 101 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 102 103 104 105 106 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "## Arbre de régression\n", `````` Long Le committed Jan 22, 2019 107 `````` "![](https://fr.wikipedia.org/wiki/Arbre_de_d%C3%A9cision#/media/File:Arbre_de_decision.jpg)" `````` TheophilePACE committed Jan 22, 2019 108 109 `````` ] }, `````` Long Le committed Jan 22, 2019 110 111 112 113 114 115 116 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 117 118 119 120 121 122 123 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "Essayer avec une profondeur max de 3" ] }, `````` Long Le committed Jan 22, 2019 124 125 126 127 128 129 130 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 131 132 133 134 135 136 137 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "Essayer avec une profondeur max de 5" ] }, `````` Long Le committed Jan 22, 2019 138 139 140 141 142 143 144 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 145 146 147 148 149 150 151 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "Essayer avec une profondeur max de 10" ] }, `````` Long Le committed Jan 22, 2019 152 153 154 155 156 157 158 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 159 160 161 162 163 164 165 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "Comparer les résultats" ] }, `````` Long Le committed Jan 22, 2019 166 167 168 169 170 171 172 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 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 committed Jan 22, 2019 183 184 185 186 187 188 189 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 190 191 192 193 194 195 196 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "Essayer avec 3 arbres" ] }, `````` Long Le committed Jan 22, 2019 197 198 199 200 201 202 203 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 204 205 206 207 208 209 210 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "Essayer avec 10 arbres" ] }, `````` Long Le committed Jan 22, 2019 211 212 213 214 215 216 217 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 218 219 220 221 222 223 224 `````` { "cell_type": "markdown", "metadata": {}, "source": [ "100 arbres" ] }, `````` Long Le committed Jan 22, 2019 225 226 227 228 229 230 231 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 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 committed Jan 22, 2019 239 240 241 242 243 244 245 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 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 committed Jan 22, 2019 253 254 255 256 257 258 259 `````` { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, `````` TheophilePACE committed Jan 22, 2019 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 committed Jan 22, 2019 269 270 271 272 273 274 275 `````` }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] `````` TheophilePACE committed Jan 22, 2019 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", `````` Long Le committed Jan 22, 2019 294 `````` "version": "3.7.2" `````` TheophilePACE committed Jan 22, 2019 295 296 297 298 299 `````` } }, "nbformat": 4, "nbformat_minor": 2 }``````