ift7025-projet/Code/Rapport-Final.ipynb

2462 lines
549 KiB
Text
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction\n",
"\n",
"- Projet final présenté par: **François Pelletier**\n",
"- Matricule: **908144032**\n",
"- Dans le cadre du cours: **IFT-7025**\n",
"\n",
"# Librairies utilisées"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import load_datasets as ld\n",
"import matplotlib.pyplot as plt\n",
"import DecisionTree\n",
2019-05-03 16:52:25 +00:00
"import NeuralNet\n",
"import time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Iris Dataset\n",
"\n",
2019-05-03 16:52:25 +00:00
"La présentation des résultats liés à ce jeu de données servira aussi à expliquer les concepts et répondre aux questions. Pour les autres jeux de données, seuls les résultats et la discussion seront détaillés.\n",
"\n",
"- Chargement du jeu de données"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
2019-05-03 04:36:22 +00:00
"train1, train_labels1, test1, test_labels1 = (\n",
" ld.load_iris_dataset(train_ratio = 0.7))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entrainement de l'arbre de décision\n",
"\n",
"Dans cette section, on entraine un arbre de décision basé sur la mesure d'entropie."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"dt1 = DecisionTree.DecisionTree(attribute_type=\"continuous\")\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
"_ = dt1.train(train1, train_labels1,verbose=False)\n",
"dt1_compute_time = time.time() - start_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Courbe d'apprentissage\n",
"\n",
2019-05-03 16:52:25 +00:00
"Je trace une courbe d'apprentissage qui effectue une validation croisée sur 10 sous-ensembles de l'ensemble d'entrainement. Je fais la moyenne de l'accuracy pour chaque sous-ensemble de test, puis j'itère en ajoutant un exemple à la fois à l'ensemble d'entrainement.\n",
"\n",
2019-05-03 16:52:25 +00:00
"- Bogue connu: J'ai débuté la courbe d'apprentissage avec 30 données, car j'ai de la difficulté à exécuter la validation croisée avec moins sans que ça plante vu que je crée les sous-groupes à l'avance."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def courbe_apprentissage_dt(dt,train,train_labels,nb_cv_split=10):\n",
" accuracy_cum = []\n",
" range_lc = range(30,len(train_labels))\n",
" for i in range_lc:\n",
" range_lc_split_test = np.array_split(range(i),nb_cv_split)\n",
" range_lc_split_train = (\n",
" [np.setdiff1d(range(i),t) for t in range_lc_split_test])\n",
" accuracy_cv = []\n",
" for r_i in range(nb_cv_split):\n",
" try:\n",
" training = dt.train(train[range_lc_split_train[r_i]], \n",
" train_labels[range_lc_split_train[r_i]],\n",
" verbose=False)\n",
" testres = dt.test(train[range_lc_split_test[r_i]], \n",
" train_labels[range_lc_split_test[r_i]],\n",
" verbose=False)\n",
" accuracy_cv.append(testres[1])\n",
" except:\n",
" pass\n",
" accuracy_cum.append(np.mean(accuracy_cv))\n",
" return range_lc,accuracy_cum"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 5,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/francois/ift7025-projet/Code/metrics.py:40: RuntimeWarning: invalid value encountered in double_scalars\n",
" myPrecision = cm[label_num,label_num] / sum(cm[:,label_num])\n"
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"dt_range_lc1,dt_accuracy_cum1 = courbe_apprentissage_dt(dt1,train1,train_labels1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Voici le graphique de la courbe d'apprentissage"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 6,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac6442e8>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 6,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl823d9+PHXW5IlH/J95XBiO1eTNEmTJk1LL0rPlEILbLCWMbqN0Y1xw2DdY5yFMrbx49gGjA4Kg0FLaRnt2kBbaEtbeuRo7qRJnNtx4tuO5UOypM/vD32/sizLtmTLlhy/n4+HH7G/+kr62LHf+uj9fX/eHzHGoJRSanZwZHoASimlpo8GfaWUmkU06Cul1CyiQV8ppWYRDfpKKTWLaNBXSqlZRIO+UkrNIhr0lVJqFtGgr5RSs4gr0wOIV1FRYerq6jI9DKWUmlG2b9/eZoypHO+8rAv6dXV1bNu2LdPDUEqpGUVETiRznqZ3lFJqFtGgr5RSs4gGfaWUmkU06Cul1CyiQV8ppWYRDfpKKTWLaNBXSqlZRIO+UkpNg817znC8rTfTw9Cgr5RSU+33h1r525++xr/97nCmh6JBfyyb95zhvfdvIV2bx58bGORd33uZR3eeTsvjKaWy37mBQe5+ZDcA2050Zng0GvTH9NS+szx/qJWWHv+kHyscNnzswZ1sOdbB9iz4j1czW3f/II/vbuLuR3bz+0OtmR6OGsOXH99P87kB3nrRPE529NHSM5DR8STVe0dENgHfApzA940xX427vRa4H6gEOoD3GGMardtCwB7r1JPGmFvTNPYp19Dqi/zb4qO6KHdSj/WN3x7imddbEIH+QCgdw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MKZvtMh1FXka61+lmho8bGkyotjjDiwvjaS18/EbF+DfpyegUHOnhtgccxbs7ryApwOib5t23Pavog7+ox+NHbQ1/RO5oTCJprWmSnpnUSrcWMtqvBytE3TO9ngcLNvxKKseKvmF+F2Odiegby+Bv049mwpNh/ndjmoLcuPXszd09hNZaFnQu2W83IiGTXtv5M5bT4/wbBhXnEuPQPBGfF/kajvTqxFlQWcbO9jMKSN1zLpnDVpHK1yx+ZxObmopjgjzdc06Mex2ynEv1IvrvJGr8rvOd3NmjHy9mPJ15x+xjV1RfL56xZGlsTPhLLN9nFm+osrvQS18VrGxVf+jWVDXRl7M9B8TYN+nIZWH26ng4Vlw2vsl1R5Od7WS3f/IA3WBd2JyNP0TsbZNfprF0S6H86EFE9b7/gzfUAv5mZYQ/PQGp/xbKgtZTA0/c3XNOjHOdLio64iH5dz+I9miTWT+vWeMxgzsXw+DJVs6kw/c+yZ/tqFMyjoW1t2luWPFvSHFxuosf3X80f59rMNaX/cwy09uF0OFpSNXJgZL1PN17RkM05Di4+V84pGHLcreH65I7Kp+VhlmWPR6p3MO9M9QG6OgwvmRPKuM6Fss73XT2l+zojJiK04L4cKr1sXaCVh56kuvvLrAxgDl9aXRVfIpsPhFh+LK71jVvDZSvLdLK3yTnsrEA36MQYGQ5zs6OPWtfF7xAytetxyrIPqIg9VE9wzN99tX8jVoJ8pZ7r7mVecR6HHRb7bOSPKNiMtGMau515U6R03vdPQ0sND2xoxZqgNSHVRLu+7sj5hc7DzTShs+Nyje6nweshxCJ/51V4e//CVo76Ypupwsy86g0/GhroyHt/dRDhsxizxTCdN78Q43t5L2CTOxxV4XMyzVuhOdJYPkJvjsDZHz/6KkfPV6a4B5pXkISJUF+XOiPROuy8waj7ftriyYNz0zneeO8J/vXCUn756kp++epL/fvkEX37iQFpr/I0xw15UsskDW06yu7Gbz9yygs+
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2019-05-03 16:52:25 +00:00
"plt.plot(dt_range_lc1,dt_accuracy_cum1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test et évaluation de la performance de l'arbre de décision"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 7,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[15. 0. 0.]\n",
" [ 0. 16. 1.]\n",
" [ 0. 0. 13.]]\n",
"\n",
"Exactitude:\n",
"0.9777777777777777\n",
"\n",
"Précision:\n",
"[1.0, 1.0, 0.9285714285714286]\n",
"\n",
"Rappel:\n",
"[1.0, 0.9411764705882353, 1.0]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.0002942085266113281s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"dt1_testres = dt1.test(test1, test_labels1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Réseaux de neurones: Choix du nombre de neurones dans la couche cachée\n",
"\n",
2019-05-03 16:52:25 +00:00
"On doit identifier le nombre optimal de neurones dans la couche cachée dans l'intervalle $[4,50]$ pour chacun des 5 jeux de données. On itère sur chacun des jeux de validation croisée, pour chaque dimension, puis on calcule l'*accuracy* moyenne. La dimension qui a la meilleure *accuracy* moyenne est choisie pour construire le réseau de neurones."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"choix_n_neurones = range(4,51)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Pour faire la séparation du jeu de données en $k_{cv}=5$ jeux de validation croisée, on génère une permutation sur les indices du jeu d'entrainement, puis, on sépare cet ensemble en 5 groupes."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"k_cv = 5\n",
"all_indices = range(len(train_labels1))\n",
"np.random.seed(12345)\n",
2019-05-03 04:36:22 +00:00
"indices_cv_test = (\n",
" np.sort(np.array_split(np.random.permutation(all_indices),\n",
" k_cv)))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
2019-05-03 04:36:22 +00:00
"indices_cv_train = (\n",
" [np.setdiff1d(all_indices,indices_cv_test[i]) for i in range(k_cv)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Ce jeu de données a trois classes possibles comme variable de sortie. On utilisera donc un réseau de neurones avec 3 neurones dans la couche de sortie, une pour chacune des valeurs possibles. Les valeurs de sortie du jeu de données sont transformées à l'aide d'un encodage binaire où la valeur de sortie est convertie en rang dans un vecteur (on commence à 0), prenant la valeur 1. Par exemple, la valeur 2 devient $[0,0,1]$."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"accuracy_cum = []\n",
"for n_neurones in choix_n_neurones:\n",
" accuracy_cv=[]\n",
" for cv_set in range(k_cv):\n",
" nn1 = NeuralNet.NeuralNet(np.array([4,n_neurones,3]),range(3))\n",
2019-05-03 04:36:22 +00:00
" nn1.train(train1[indices_cv_train[cv_set]], \n",
" train_labels1[indices_cv_train[cv_set]], 0.1, 1, \n",
" verbose=False)\n",
" _,accuracy,_,_,_ = nn1.test(train1[indices_cv_test[cv_set]], \n",
" train_labels1[indices_cv_test[cv_set]], \n",
" verbose=False)\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum.append(np.mean(np.array(accuracy_cv)))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 12,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac57c630>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 12,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl0W9d16P/vxkCCE0BKHDQPlDXQoyzJiuOptuUkztA4vw6u3TTxFPu9tmmaNm1e0iFJ09dprffS9teXtHESx85LE9d1k8ZN3bqRbEd2EtsaPEqkLImaOY8AJxDDeX8AFwRJgLggQYAC9mctLZEXF9T1NbFxsM8++4gxBqWUUqXBUegLUEoplT8a9JVSqoRo0FdKqRKiQV8ppUqIBn2llCohGvSVUqqEaNBXSqkSokFfKaVKiAZ9pZQqIa5CX8BM9fX1ZsOGDYW+DKWUuqgcOnSozxjTkOm8JRf0N2zYwMGDBwt9GUopdVERkTN2ztP0jlJKlRAN+kopVUI06CulVAnRoK+UUiVEg75SSpUQW0FfRG4XkWMickJEPpPi8XUi8pyIvCoib4jI+5Ie+2z8ecdE5D25vHillFLZyViyKSJO4MvAu4DzwAERecoYczTptD8CnjDG/L2IXAo8DWyIf30XcBmwCtgrIluMMZFc/4copZTKzM5IfzdwwhjTboyZBB4H7phxjgG88a99QEf86zuAx40xQWPMKeBE/OcppVTJGZ+M8MTBcxRym1o7QX81cC7p+/PxY8m+APyaiJwnNsr/rSyei4g8JCIHReRgb2+vzUtXSqmLy7+93sGnn3yDY92Bgl2DnaAvKY7NfJu6G3jUGLMGeB/wf0XEYfO5GGMeNsbsMsbsamjIuIpYKaUuSif7RgAYGgsV7BrstGE4D6xN+n4NU+kbywPA7QDGmJ+JiAeot/lcpZQqCe29owAMjxcu6NsZ6R8ANovIRhEpIzYx+9SMc84CewBEpAXwAL3x8+4SkXIR2QhsBl7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GE+WaltrKMpZVleW98dq5gTFu+V/P859HuvL676riNzwWon90Mm13zWSa01dFrXN4glW1s5ekNxegbPPNC8NEDZzo0TUCKresAYyd9I7H7aTc5dCgr4pTR4qRPsReHPneTKW10w9MzTMolSvtNss1LYVor6xBXy260WAY/0Q40YIhWXNDNb2BIIE8LlBp7QwAU/39lcqV9r4RXA5h7bLZ++Km4qvIf9M1Dfpq0U310U890of8Tua2dcVH+kMa9FVuneobZd2yStxOe6HV63HpSF8VH2tEnVyuadnUkN+g758IcX5wHKdDEgvGlMoVu+WalthGKlqyqYqMNaJeVTt7pL9ueSUOmVq6vtiOdcVSOzvX1xGYCDMSzH+XQ1WcolEz52boqWhOXxWljuFxRKApxYYS5S4na+oq5+y2ORmO8sv/8FP+9dULC76Wtvgk7q3bGoFYKalSudAxPE4wHM3YaC2Z5vRVUeocmqC+upwyV+pft0z75T71egcHTg/ynZfPLvhaWrsC+Crc7FhXB8QWjSmVC9bvcDbpHa8ntk9uPhcKatBXi65jeHxao7WZrG6bqfbLNcbw9RfaATh4ZoDB0ckFXUtbp59tK2oS8ws60le5km25JsRG+lEDo5P5SzNq0FeLrnN4ghVzBP3mhmrGJiN0+2fvl/vC8T7augJ85Nr1RA08/3bPvK8jGjW0dQVoWellhc+DiI70Ve60945QXe6iobrc9nMK0V5Zg75aVMaYlC0YkjUn9sudndf/2gvtNNaU84fvb6Ghppy9rfMP+ucGxxibjNCysga300FDdbmO9FXOtMcncefaF3cmr9V0LY8VPBr01aLyT4QZnYykbMFgSXTbnJHXP9rh54Xjfdx7/QY8bie3bm1k/7H
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(choix_n_neurones,accuracy_cum)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Le nombre de neurones qui maximise l'*accuracy* est de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 13,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"49"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 13,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2019-05-03 04:36:22 +00:00
"n_neurones_optimal1 = (\n",
" choix_n_neurones[np.where(accuracy_cum==max(accuracy_cum))[0][0]])\n",
"n_neurones_optimal1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Choix du nombre de couches cachées\n",
"\n",
2019-05-03 16:52:25 +00:00
"On choisit un nombre de 1 à 5 couches cachées. Le nombre de couches ayant l'*accuracy* maximale sera sélectionné pour la construction du réseau. On effectue 10 époques étant donné la taille des réseaux à entrainer."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"choix_n_couches = range(1,6)"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"accuracy_cum = []\n",
"lc_cum = []\n",
"for n_couches in choix_n_couches:\n",
" accuracy_cv=[]\n",
2019-05-03 04:36:22 +00:00
" nn1 = NeuralNet.NeuralNet(\n",
" np.hstack((4,\n",
" np.repeat(n_neurones_optimal1,n_couches),\n",
" 3)),\n",
" range(3))\n",
" lc = nn1.train(train1, train_labels1, 0.1, 10, verbose=False)\n",
" lc_cum.append(lc)\n",
" _,accuracy,_,_,_ = nn1.test(train1, train_labels1, verbose=False)\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum.append(np.mean(np.array(accuracy_cv)))\n",
"lc_cum = np.array(lc_cum)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"L'*accuracy* pour les différentes profondeur est de :"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 16,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"array([[1. , 2. , 3. , 4. , 5. ],\n",
" [0.6952381 , 0.97142857, 0.88571429, 0.93333333, 0.79047619]])"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 16,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.vstack((choix_n_couches,accuracy_cum))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Le nombre de couches cachées qui maximise l'*accuracy* est de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 17,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 17,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2019-05-03 17:14:26 +00:00
"n_couches_optimal1 = (\n",
" choix_n_couches[np.where(accuracy_cum==max(accuracy_cum))[0][0]])\n",
"n_couches_optimal1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Un problème rencontré avec un nombre de couches élevées est appelé le *Vanishing gradient problem*. Dans ces situations, le nombre de multiplications nécessaires ainsi que le fait que les valeurs $\\Delta$ sont suffisamment petites pour que le gradient tende vers 0 et ainsi ne permette pas de mettre les poids à jour. Dans ces situations, l'entrainement va stagner."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Courbes d'apprentissage\n",
"\n",
"Ce graphique présente les courbes d'apprentissage pour chacun des niveaux de profondeur du réseau"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 18,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB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7PMDxiOK/seYXHtz5ObGgsz/R4Bj8nv3qNo0kozICE76DrdHCx7MnIWphj9M8Blz9TBwPqyxtIkqQGxgEIIZyBOyVJKrpsH5IkpQohtgGdgdNXHb8MWAbQrVu3m7TCxo3Lr0fUSBL1itqpDTsbJR9P6cJTq4/w9qYTlFbqeXpI62YV2nfsfDGfbjvNr0fU2CgUTOgaSK/jGSiix4O/aSYvhOD1MdHc/v52Xjuk4gMwuXia0OhfL+JmYOhAuvl3s+pi6qLNp8jIr+CHWb3oEe5Jj3BPFselML5rMI6q6k1SB58OfD/ie1Ymr+TTw58yeu1oHuvyGBNbTUSpsDw8uMnYtcj0t+/jTTYEc4z+fqClECIc0wz+LmDK5Q2EEN5AviRJRuAZTJE8CCE8gHJJkiqr2twCvGXF8cs0A9YmqOkY7Ea4d8NmFNooFbw7oSOOKiWfbjtNeaWel0a2R2GFheP6cPBsPh9vPc2W49k4qZTMvDWCGX3D8dVlwpHiS5E6mGbS2BQzo78Ln2xL5T/ugTic2wPFYxt1zOX6cv7K/Ist6VtIzDUF11kacVMXkjKLWL4zjck9QugZYYry+r+hrbnz0z18vuvMdZ/gbBW2zIiZweAWg3n171d5Y+8b/Jr6Ky/1folWHq2sPlarU5IFh1ZCpyngFlx7+waiVqMvSZJeCPEwsAlTyOYKSZKShRCvAgckSVoH9AcWCCEkTO6di0vSbYGlQggjJsm
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"for i in choix_n_couches:\n",
" plt.plot(range(10),lc_cum[i-1], label=\"%d couches\"%(i,))\n",
"leg = plt.legend(loc='best', ncol=2, mode=\"expand\", shadow=True, fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Choix des poids initiaux\n",
"Les poids initiaux ont été choisis à partir d'une distribution uniforme sur $[-1,1]$. On compare ici les courbes d'apprentissage en initialisant les poids à 0 et en initialisant les poids aléatoirement, pour le réseau de dimension et de profondeur optimale sélectionnées précédemment.\n",
"\n",
"- Réseau initialisé avec les poids à 0 $RN_{0}$"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
2019-05-03 04:36:22 +00:00
"nn1_poidszero = NeuralNet.NeuralNet(\n",
" np.hstack((4,\n",
" np.repeat(n_neurones_optimal1,n_couches_optimal1),\n",
" 3)),\n",
" range(3),\n",
" input_weights=0)\n",
"lc_nn1_poidszero = (\n",
" nn1_poidszero.train(train1, train_labels1, 0.1, 10, verbose=False))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Réseau initialisé avec les poids uniformes $RN_{\\neg{0}}$"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
2019-05-03 04:36:22 +00:00
"nn1_poidsunif = NeuralNet.NeuralNet(\n",
" np.hstack((4,\n",
" np.repeat(n_neurones_optimal1,n_couches_optimal1),\n",
" 3)),\n",
" range(3))\n",
"np.random.seed(12345)\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
2019-05-03 04:36:22 +00:00
"lc_nn1_poidsunif = (\n",
2019-05-03 16:52:25 +00:00
" nn1_poidsunif.train(train1, train_labels1, 0.1, 10, verbose=False))\n",
"nn1_compute_time = time.time() - start_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"### Graphique des courbes d'apprentissage"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 21,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9u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PM45p0EHGR5VnT13d5/u7r3cPcPd+7r7I+7+UGWw48H33H2wu49y92Y9p0Dr1q159tlneeGFFzjppJNYvHhx1WNdu3blqaeeSupQzfT0dJ599tmq2wMPPEDr1q2ZOXNm0rWUlZU16GcQaepS9Tk7KC0tjRdeeKExSqVnz541Psu33XYbHTp04Jprrqn7yWXFsPUdyrd/CO26Qe+xNYId4KqrrmLBggUprzuyuWXq8nDOTjbsLEnpNgd1yWRGokvdDSuNHj2a9evXVy136dKFsWPH8tJLLzFlypSkt+Pu3HzzzVx//fUMGTIEgDVr1nDnnXeyb98+unTpwty5c8nKyuKGG25g9OjRrFixgvPPP5+LL76YW265hZ07d1a169WrV/I/tMgx9Fp5H212vZ/SbRZ3HsIno3+YdPtUfM6uueYannzySa644ooa692de+65hzfffBMzY+bMmUyYMIHs7GwefPBBOnfuTF5eHsOHD+eOO+6o8+i8AwcO8JOf/ISf/vSnVTs4//KXv/DAAw9QUlJCv379mDt3Lu3atWPCly7msgvP5q8r1jDt69MYOKwHc2dfT3FxMf369ePWW2+lU6dO9O7dm127drF9+3a6d++e9PtWF+21PIry8nLeeustzj///Brrb7jhBh5//PF6HYP/xBNPkJ6eXvU1s7S0lDvuuIO7776bp59+mssuu4xf/OIXVe2Liop49NFHue6667j99tu59NJLef755/nKV77CvHnzUvLziTQFqfqc9ezZk7Fjx/LKK6/UWP+73/2OdevW8dxzz/Hwww9zzz33UFhYCMB7773Hj3/8Y1588UXy8/NZvnx5na9z7733MmbMGC644AIAdu7cyfz585k/fz7PPPMMI0aM4PHHHoWCtVBRSma79ix8cjETv/Z1brrpJmbPns3zzz/PkCFDePDBB6u2O2zYsKRevz6abM+9Pj3sVDpw4ABTp05ly5YtDBs2jM997nM1Hu/bty8jR45k6dKlSW1v3bp1PPnkkyxatKiqV7Bx40by8vL4zne+A4Rf8OqHOU2YMKHq/qpVq7j33nsB+OpXv1p1XyQV6tPDTqVUf84Avv3tb/ODH/yA8847r2rd8uXLmThxIunp6XTr1o1EI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RVthx4bQccgaGsL9OJSXl3PttdemqLhD9JucArfddhsrVqyose7qq6/msssui6iiFqj4sxDm3U4NH7rWHcKtuvLSysDfFwK/ZB/s3Q4VWw+1Sc881Ls/OLST0S5sUyJ1Ij5nP/rRj9i8efMR684991woL4HteWHqgDadofuQlHwD/NKXvnTc26hNkwv35ji3zE033RR1CVL0CaSlH7sXlZ4B6SdBm5Nqri87cKiXX7I33C/eFU4bB8Ago021wD84tNNG4/kn0In4nP385z+v/YF9n4Zg93LoOgg69mr0/3t3P648bFLhnpGRQXFxcdRlSHNTXgr7tkOHniHg66tV63Crflq4O5Ttrwz8akM8+z491MbSah/aSc888jWkeaooD0Mwe7aF/9vuQ8P/cyNzdyoqKti/f3+Dt9Gkwr1r166sX7+eoqIizasiydtbCMUOHTrC7t0p3ngmpGVC687QmjBla9mBMGdIWTGUFMO+HVB+2Hh+qzbhD0ZGm8r7bTS009yU7oPdm6CsFDpkQfuTYX8p7E/179iR3J39+/ezY8cOzKxBl9prUuGenp5Onz59+OMf/0hZWVnKD+qXGHKHlU9BZkc
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"plt.plot(range(10),lc_nn1_poidszero, label=\"RN_Zero\")\n",
"plt.plot(range(10),lc_nn1_poidsunif, label=\"RN_Non_Zero)\")\n",
2019-05-03 04:36:22 +00:00
"leg = plt.legend(loc='best', \n",
" ncol=2, \n",
" mode=\"expand\", \n",
" shadow=True, \n",
" fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On remarque clairement que l'initialisation des poids à 0 ne permet pas de démarrer l'entrainement du réseau. Il est donc nécessaire d'initialiser les poids aléatoirement pour permettre l'apprentissage et éviter que les différentes fonctions pour calculer la rétropropagation des erreurs aient toutes des valeurs de 0."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entrainement et tests\n",
"On reprend les résultats du dernier entrainement, puisqu'il utilise les poids aléatoires et les hyperparamètres optimaux."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 22,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[15. 0. 0.]\n",
" [ 0. 16. 1.]\n",
" [ 0. 3. 10.]]\n",
"\n",
"Exactitude:\n",
"0.9111111111111111\n",
"\n",
"Précision:\n",
"[1.0, 0.8421052631578947, 0.9090909090909091]\n",
"\n",
"Rappel:\n",
"[1.0, 0.9411764705882353, 0.7692307692307693]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.040042877197265625s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"res_test1 = nn1_poidsunif.test(test1, test_labels1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## MONKS Dataset\n",
"\n",
"- Chargement des jeux de données"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"train2, train_labels2, test2, test_labels2 = (\n",
" ld.load_monks_dataset(1))\n",
"train3, train_labels3, test3, test_labels3 = (\n",
" ld.load_monks_dataset(2))\n",
"train4, train_labels4, test4, test_labels4 = (\n",
" ld.load_monks_dataset(3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entrainement de l'arbre de décision\n",
"\n",
"Dans cette section, on entraine un arbre de décision basé sur la mesure d'entropie."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"dt2 = DecisionTree.DecisionTree(attribute_type=\"discrete\")\n",
"dt3 = DecisionTree.DecisionTree(attribute_type=\"discrete\")\n",
"dt4 = DecisionTree.DecisionTree(attribute_type=\"discrete\")\n",
"\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
"_ = dt2.train(train2, train_labels2,verbose=False)\n",
2019-05-03 16:52:25 +00:00
"dt2_compute_time = time.time() - start_time\n",
"start_time = time.time()\n",
"_ = dt3.train(train3, train_labels3,verbose=False)\n",
2019-05-03 16:52:25 +00:00
"dt3_compute_time = time.time() - start_time\n",
"start_time = time.time()\n",
"_ = dt4.train(train4, train_labels4,verbose=False)\n",
"dt4_compute_time = time.time() - start_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"### Courbe d'apprentissage\n"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
2019-05-03 17:14:26 +00:00
"dt_range_lc2,dt_accuracy_cum2 = (\n",
" courbe_apprentissage_dt(dt2,train2,train_labels2))\n",
"dt_range_lc3,dt_accuracy_cum3 = (\n",
" courbe_apprentissage_dt(dt3,train3,train_labels3))\n",
"dt_range_lc4,dt_accuracy_cum4 = (\n",
" courbe_apprentissage_dt(dt4,train4,train_labels4))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Voici les graphiques de la courbe d'apprentissage pour les 3 jeux de données\n",
"- 1er jeu de données"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 26,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac406710>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 26,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpY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+zmE186Jo1HGno5YXq6Ttx2/sndqca1hRkYLOYeG6G2b5hZMzDYwcaZkz5CLHcSHBfhNquwYjm2w0XlWSRl2Hl6VOJEdwP1vrOgN05R3AHeOuOYlZk2vjOs9XTZu/tfSPkO1In3ZaemsJbLi7h14eb6BqYuSXyA3+p4VP/c5SXzidu+wYhIkmC+wK5x7009QxHrAwymMmkuG59IX8+0457fOmfrfrKhW7Kc9MCbQNmk5pi5u+vWc2B2h721Uw+GLytb3RSvt3wvisrcI97+dkMDchcQ2M89GINANVtsuFJCJDgvmBNvcN4NVFJy4AvNdM/Ms6B2u65L44jrTUH63rYWZ4T9ve885JS8h2pfOfZ6km3t/ePBFoPBFtT4OCatfn8eF9dyBe7771QQ//IOKkpJqrbJbgLARLcF6zWKIOMwswd4Ko1eaSmmJb8btWazkG6B93sqpw7JWOwWczc85pVvHS+i0N1vhcvY3dqqJk7wPuuqqSjf5THj04+BKxrYJTv773ArVtXsLUkk/MS3IUAJLgvWF2nEdyjM3O3W828piqPp062hawsWSoC+faK8GfuAO+6rIzcdCtfeeIMWmu6BifvTp3q6qo81hRk8PCLFyY9Hw8
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2019-05-03 16:52:25 +00:00
"plt.plot(dt_range_lc2,dt_accuracy_cum2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- 2e jeu de données"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 27,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac3dadd8>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 27,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8C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dOAFtE5AGl1B5rH6XUZxz7fwK4yLzdCHwB2AgoYJt5bF9R/wocq2Z5s7N3rEjfyN7xeYwFVnTKpkajqUQKifQ3AQeUUoeUUnHgfuC2cfZ/H3CfeftG4FGlVK8p9I8Cm6cz4HzUB7089tmrece6Nnub3+HdJ5KZ9o6eyNVoNJVIIaI/HzjuuH/C3DYGEVkELAGemOyx08XjdrF8bg0NVT57W8DrdkT6oxO5AUcq50Qopfjsj15j29He4g9ao9FozjKFiL7k2Kby7Hs78BOllKWoBR0rIneKyFYR2drV1VXAkAoj6BD9eNZEbqGe/lAsyU9fPckLB3qKNi6NRqM5VxQi+ieAhY77C4COPPvezqi1U/CxSql7lVIblVIbm5ubCxhSYVT53YzEszx9twu/x11w9s5QNAlkLqqu0Wg0s5VCRH8LsEJEloiID0PYH8jeSUTOAxqAFx2bHwFuEJEGEWkAbjC3nRVCPg+R+NiUzYC38Eh/WIu+RqMpIybM3lFKJUXk4xhi7Qa+rZTaLSL3AFuVUtYXwPuA+5VSynFsr4j8JcYXB8A9SqmzZo5X+dyMxJMopeyKXK9b8HvcBU/kDscSwGjvHo1Go5nNTCj6AEqph4CHsrZ9Puv+F/Mc+23g21Mc37QI+jwoZbRRtiN9jwu/11Vw751BM9JP6Ehfo9GUAWVTkZuLKr9RqDUST9r2jM/tIjCZSN+yd3Qxl0ajKQPKWvRDPuNCJhxL2faM121E+oWmbA7HdKSv0WjKh7IW/SrfaKSfSKVxCbhdktF
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2019-05-03 16:52:25 +00:00
"plt.plot(dt_range_lc3,dt_accuracy_cum3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- 3e jeu de données"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 28,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac33d898>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 28,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsvXmYXHd55/t5a+/q6n2V1N3qltSykbzJFsILNjaLbYbEBsLkMSQBJxnIRsg+gZtcMnFu5uaSeTLkzjhhCDjJzB1wgLA4xNgY8ILt2JaE5UWyZa1Wt6RW71vty+/+cepUV1XX1l171e/zPP1IdeqcqtPVVd96z/f3LqKUQqPRaDTNgaXaJ6DRaDSayqFFX6PRaJoILfoajUbTRGjR12g0miZCi75Go9E0EVr0NRqNponQoq/RaDRNhBZ9jUajaSK06Gs0Gk0TYav2CaTT29urRkdHq30aGo1GU1ccPnx4VinVl2+/mhP90dFRDh06VO3T0Gg0mrpCRN4sZD9t72g0Gk0ToUVfo9Fomggt+hqNRtNEaNHXaDSaJkKLvkaj0TQRWvQ1Go2midCir9FoNE2EFv0aIByN8eAL54hEY9U+FY1G0+Bo0a8Bnj01x6e/+QpPnZip9qloNJoGpyDRF5E7ReS4iJwUkU9n2ednReSYiBwVka8kbY+KyJH4z0OlOvFG4tJyAIATl1arfCYajabRyduGQUSswP3Ae4BJ4KCIPKSUOpa0zzjwGeAmpdSCiPQnPYRfKXVNic+7oZhdDQJwYlqLvkajKS+FRPoHgJNKqdNKqRDwIHB32j4fB+5XSi0AKKWmS3uajc3MihZ9jUZTGQoR/W3ARNLtyfi2ZHYDu0XkGRF5TkTuTLrPJSKH4tvfX+T5NiSm6J+8tIJSqspno9FoGplCumxKhm3pymQ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P7w0aNTOG0W3nFZ7i+4wXYXbodVD1TRaDQlI6/oK6UiwCcxxPo14GtKqaMicp+I3BXf7VFgTkSOAY8Df6CUmlNKzQN/hvHFcRC4L76tYfCHsnv6AO/ZM4CIIfQASikeO3aJm8f71lXxpiMiOoNHo9GUlIJm5CqlHgYeTtv22aT/K+B34z/pxz4APFDcadYu2VI2TfrbXFw70sWjR6f41LvGefX8MucX/fz2u8cLevxd/R6eOz1XqtPVaDRNjq7ILRJ/OLe9A4bFc/TCMhPzPh49OoVF4N1vye3nm+zq93BxKcCqHp1YEyilePrEbNaeShpNraNFv0gMeyf3BdPtewYB+P6xS3z/2BQHxrrpypGfn8x4fDH3xKWV4k5UUxIOvbnAz3/5eR48OJF/Z42mBtGiXwRKKXyh7Nk7JqO9rVw20MY/PnuWNy6tcsfewYKfY3ygDYATejG3Jjgza6TPPvDMGV00p6lLtOgXQTASI6bWd9jMxB17BxJtkm/fgOiPdLtx2iw60q8RJhf8AJycXuXJN+qrpkSjAS36RWEOUMmVvWNiCv2V2zrY1tlS8HNYLUYGj470a4PJeR99bU4G2p18+ekz1T4djWbDaNEvgkzzcbOxd2s777q8n3tvHN3w84wPeDhxSYt+LTC54Gesp5WP3jDKj0/McnxKX4Fp6gst+kVgin4h9o6I8OV738rPXDe04efZPdDG+UW/zuCpASYXfAx1tfCRAyO47BYe0NG+ps7Qol8E2QaolJpEOwZt8VSVUCTGxeUAQ91uulodfPDaIb515HxiII5GUw9o0S8Cc1RivsraYtkdz+B5Qy/mVpWLS36UgqEuY03ml24aIxSJ8dXnz1X5zDSawtGiXwT+cOH2TjGMdLtx2Cw60q8yZuaOKfq7+j3sG+nk8ePTuQ7TaGoKLfpF4N/AQm4xmBk8OtKvLhPxlNvhLndi29vGenh5cinxXtBoap2GEX2lFKFIjHA0VrHn3Ej2TrHs1hk
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2019-05-03 16:52:25 +00:00
"plt.plot(dt_range_lc4,dt_accuracy_cum4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On peut facilement observer que dans les trois cas, il y a très peu d'apprentissage de réalisé par l'algorithme avec les exemples fournis."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test et évaluation de la performance de l'arbre de décision"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 29,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[144. 74.]\n",
" [131. 85.]]\n",
"\n",
"Exactitude:\n",
"0.5254629629629629\n",
"\n",
"Précision:\n",
"[0.5236363636363637, 0.5345911949685535]\n",
"\n",
"Rappel:\n",
"[0.6605504587155964, 0.39351851851851855]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.0011060237884521484s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"dt2_testres = dt2.test(test2, test_labels2)"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 30,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[219. 72.]\n",
" [ 88. 56.]]\n",
"\n",
"Exactitude:\n",
"0.6296296296296297\n",
"\n",
"Précision:\n",
"[0.7133550488599348, 0.4375]\n",
"\n",
"Rappel:\n",
"[0.7525773195876289, 0.3888888888888889]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.0016949176788330078s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"dt3_testres = dt3.test(test3, test_labels3)"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 31,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[ 30. 175.]\n",
" [ 25. 207.]]\n",
"\n",
"Exactitude:\n",
"0.5370370370370371\n",
"\n",
"Précision:\n",
"[0.5454545454545454, 0.5418848167539267]\n",
"\n",
"Rappel:\n",
"[0.14634146341463414, 0.8922413793103449]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.001772165298461914s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"dt4_testres = dt4.test(test4, test_labels4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Réseaux de neurones: choix du nombre de neurones dans la couche cachée"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Pour faire la séparation du jeu de données en $k_{cv}=5$ jeux de validation croisée, on génère une permutation sur les indices du jeu d'entrainement, puis, on sépare cet ensemble en 5 groupes."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"all_indices2 = range(len(train_labels2))\n",
"all_indices3 = range(len(train_labels3))\n",
"all_indices4 = range(len(train_labels4))\n",
"np.random.seed(12345)\n",
"indices_cv_test2 = (\n",
" [np.sort(x) for x in np.array_split(np.random.permutation(all_indices2),k_cv)])\n",
"np.random.seed(12345)\n",
"indices_cv_test3 = (\n",
" [np.sort(x) for x in np.array_split(np.random.permutation(all_indices3),k_cv)])\n",
"np.random.seed(12345)\n",
"indices_cv_test4 = (\n",
" [np.sort(x) for x in np.array_split(np.random.permutation(all_indices4),k_cv)])"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"indices_cv_train2 = (\n",
" [np.setdiff1d(all_indices,indices_cv_test2[i]) for i in range(k_cv)])\n",
"indices_cv_train3 = (\n",
" [np.setdiff1d(all_indices,indices_cv_test3[i]) for i in range(k_cv)])\n",
"indices_cv_train4 = (\n",
" [np.setdiff1d(all_indices,indices_cv_test4[i]) for i in range(k_cv)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ces jeux de données ont deux classes possibles comme variable de sortie. On utilisera donc un réseau de neurones avec deux neurone dans la couche de sortie, une pour chacune des valeurs possibles. Les valeurs de sortie du jeu de données sont transformées à l'aide d'un encodage binaire où la valeur de sortie est convertie en rang dans un vecteur (on commence à 0), prenant la valeur 1. Par exemple, la valeur 1 devient $[0,1]$."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"accuracy_cum2 = []\n",
"for n_neurones in choix_n_neurones:\n",
" accuracy_cv=[]\n",
" for cv_set in range(k_cv):\n",
" nn2 = NeuralNet.NeuralNet(np.array([6,n_neurones,2]),range(2))\n",
" nn2.train(train2[indices_cv_train2[cv_set]], \n",
" train_labels2[indices_cv_train2[cv_set]], 0.1, 1, \n",
" verbose=False)\n",
" _,accuracy,_,_,_ = nn2.test(train2[indices_cv_test2[cv_set]], \n",
" train_labels2[indices_cv_test2[cv_set]], \n",
" verbose=False)\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum2.append(np.mean(np.array(accuracy_cv)))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 35,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac32d5c0>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 35,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurow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UnJNrqBfZ5w2y47BQPJ9t7bOxzt2tdPjn+KVMq7iOdad3MTd3dGQPlZT6eHDb+/iX14b4btnBkq1tLLBBP0ikEgoI5MRGqoqCEUTDKQ+iE5hLGgv6E/LO6sz04/FE477ws6F9V5rravk7beso8ItZV3Fc+yan0qPi5vaZjYRvud1G7mhpYZPPXuWWLw8h/N965UenjraU/D3mAn6RWA8FCWWUG7rTF6S2tX1w7E4/+lbJwve1GVl+jmrd1bI9KxQNPm6do8uTmp74H/9hL/+7sUCraowTGf6lTRUVfBLW1s4dKJ8JZ7j3X52rK+f009S4Xbx0ftu4sLABF9/ubtEq1s6/eMhPv7USb78L1cp9P8aE/SLgKXn376pCbBfwXPs2hhffOEKf/fClYKtDZKVO2BH3lkZG7k/Oj/IF1+4wjdf7rF9n17/FGf7Ao4tuZ2PgUCYCrek/99aEo8lk5QTsXiCkz3j3LqxMevvD+xsY29nI//jufMMjIfwByNzfkLReJFXnRtV5T988ySRWIJPvXs3rizW5vnElsumYXlYev6ujkY8LrEdOM71J/1wDp/q448O3IRIYd4MdjV9j9tFjddd9pn+c6f7AXhpEdUeVmXIZLi8vvAGA2FaaivTgeTeW9r4Y/cJDp24nq6
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(choix_n_neurones,accuracy_cum2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Le nombre de neurones qui maximise l'accuracy est de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 36,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"17"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 36,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n_neurones_optimal2 = (\n",
" choix_n_neurones[np.where(accuracy_cum2==max(accuracy_cum2))[0][0]])\n",
"n_neurones_optimal2"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"accuracy_cum3 = []\n",
"for n_neurones in choix_n_neurones:\n",
" accuracy_cv=[]\n",
" for cv_set in range(k_cv):\n",
" nn3 = NeuralNet.NeuralNet(np.array([6,n_neurones,2]),range(2))\n",
" nn3.train(train3[indices_cv_train3[cv_set]], \n",
" train_labels3[indices_cv_train3[cv_set]], 0.1, 1, \n",
" verbose=False)\n",
" _,accuracy,_,_,_ = nn3.test(train3[indices_cv_test3[cv_set]], \n",
" train_labels3[indices_cv_test3[cv_set]], \n",
" verbose=False)\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum3.append(np.mean(np.array(accuracy_cv)))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 38,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac2962b0>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 38,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsvXmUJHd15/u9ua+1r129VG9C6gW3rFarxSJ2aAGWOGOMxZNZDIwMYz3ws2eeYY7Bz2DODPZ5g5+PGQyyWWQkZAaPjSxaEgIjEKClS1ZL6kVSV+9VXVvXlkvlnvf9EfGLjMyKzIjMyszIqvx9zqnTlZGRUb/Mzogbd/teYmZIJBKJROKwewESiUQiaQ2kQZBIJBIJAGkQJBKJRKIiDYJEIpFI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H18Z1EdFz3kyeiA+pzj6vHFM8N1OctSaySyoppaXoPQRqEdqZgEApDtbf1KqWnzBuz9DSiVvhMLtnnBcWSWYS8bnT63a0dMiIiJ4CvALgVwB4A7yeiPQb7hQF8EsDTYhsz38fMB5j5AIAPALjAzMd1L7tTPM/Ms2t8L5IqEaEhoXYKqEll2anctohZyr06gzDaF0Aik8NcNGXXshpKJKlcgK8s2VdaG0tlEfa50BVwt3xS+RCAcWY+x8xpAA8AuN1gvy8A+AsA5T7V9wP4bk2rlDSEgoegKzuVIaO2ZiGehoOATr9b27ZNKz3dmHmEqOYh2CfzHUtlEfQ6W99DADAC4LLu8YS6TYOIrgewhZkfqnCc38Zqg/BNNVz0WSIiKwuW1A/hIRQZBJlUbmsWVtLoDig6RoJRtfR0o+YRIuoFeCGexkr
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(choix_n_neurones,accuracy_cum3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Le nombre de neurones qui maximise l'accuracy est de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 39,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"15"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 39,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n_neurones_optimal3 = (\n",
" choix_n_neurones[np.where(accuracy_cum3==max(accuracy_cum3))[0][0]])\n",
"n_neurones_optimal3"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"accuracy_cum4 = []\n",
"for n_neurones in choix_n_neurones:\n",
" accuracy_cv=[]\n",
" for cv_set in range(k_cv):\n",
" nn4 = NeuralNet.NeuralNet(np.array([6,n_neurones,2]),range(2))\n",
" nn4.train(train4[indices_cv_train4[cv_set]], \n",
" train_labels4[indices_cv_train4[cv_set]], 0.1, 1, \n",
" verbose=False)\n",
" _,accuracy,_,_,_ = nn4.test(train4[indices_cv_test4[cv_set]], \n",
" train_labels4[indices_cv_test4[cv_set]], \n",
" verbose=False)\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum4.append(np.mean(np.array(accuracy_cv)))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 41,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac274e80>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 41,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJztvXl8W3ed9/v5arcleZG32M5ix3GapEmTtGmSbnRhaQolpTAzt+0wtMxAmZnLLTPMcuF58cBzO8M8w+U+bM+UGTqlwDDQsgzQAIVQuoc2K0mapGkSx3Zix6sWL5Ks/Xf/OOfIx7KWI1u7vu/Xyy9LR0fSz8fS53zPdyUhBBiGYZjqQFfsBTAMwzCFg0WfYRimimDRZxiGqSJY9BmGYaoIFn2GYZgqgkWfYRimimDRZxiGqSJY9BmGYaoIFn2GYZgqwlDsBSTS3Nwsurq6ir0MhmGYsuLYsWNOIURLpv1KTvS7urpw9OjRYi+DYRimrCCiS1r2Y/cOwzBMFcGizzAMU0Ww6DMMw1QRLPoMwzBVBIs+wzBMFcGizzAMU0Ww6DMMw1QRLPoMU2K4fSHsOzlS7GWUNL5gBG5fqNjLKEt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bTHD6QpquqhgW/YLg8oXQLFuELXbzsrJ3lIHojVYTrCY9dMSB3GIwOh1Y0F0zkWzSNidnU7dgUFPKjdcU1847N7ZhU3td/H6uSWbpN9lMCEVi8ap3Jj0s+gXA5Q3FKwdb7GY4l2np63WEOos0OaiuhlsxFIPR6bkF3TUTabWbUacxg2d+Nm56905Xcy3
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(choix_n_neurones,accuracy_cum4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Le nombre de neurones qui maximise l'*accuracy* est de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 42,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"31"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 42,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n_neurones_optimal4 = (\n",
" choix_n_neurones[np.where(accuracy_cum4==max(accuracy_cum4))[0][0]])\n",
"n_neurones_optimal4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"### Choix du nombre de couches cachées"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
"def accuracy_couches(train,train_labels,n_neurones_optimal):\n",
" accuracy_cum = []\n",
" lc_cum = []\n",
" for n_couches in choix_n_couches:\n",
" accuracy_cv=[]\n",
" nn = NeuralNet.NeuralNet(\n",
" np.hstack((6,\n",
" np.repeat(n_neurones_optimal,n_couches),\n",
" 2)),\n",
" range(2))\n",
" lc = nn.train(train, train_labels, 0.1, 10, verbose=False)\n",
" lc_cum.append(lc)\n",
" _,accuracy,_,_,_ = nn.test(train, train_labels, verbose=False)\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum.append(np.mean(np.array(accuracy_cv)))\n",
" lc_cum = np.array(lc_cum)\n",
" return accuracy_cum, lc_cum"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
2019-05-03 17:14:26 +00:00
"accuracy_cum2, lc_cum2 = (\n",
" accuracy_couches(train2,train_labels2,n_neurones_optimal2))\n",
"accuracy_cum3, lc_cum3 = (\n",
" accuracy_couches(train3,train_labels3,n_neurones_optimal3))\n",
"accuracy_cum4, lc_cum4 = (\n",
" accuracy_couches(train4,train_labels4,n_neurones_optimal4))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"L'*accuracy* pour les différentes profondeur est respectivement (un jeu de données par ligne) de :"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 45,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"array([[1. , 2. , 3. , 4. , 5. ],\n",
" [0.54032258, 0.5 , 0.48387097, 0.58064516, 0.5 ],\n",
" [0.62130178, 0.62130178, 0.62130178, 0.62130178, 0.62130178],\n",
" [0.62295082, 0.69672131, 0.87704918, 0.51639344, 0.50819672]])"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 45,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.vstack((choix_n_couches,accuracy_cum2,accuracy_cum3,accuracy_cum4))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Le nombre de couches cachées qui maximise l'*accuracy* est, pour chacun des 3 jeux de données, respectivement de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 46,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"(4, 1, 3)"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 46,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2019-05-03 17:14:26 +00:00
"n_couches_optimal2 = (\n",
" choix_n_couches[np.where(accuracy_cum2==max(accuracy_cum2))[0][0]])\n",
"n_couches_optimal3 = (\n",
" choix_n_couches[np.where(accuracy_cum3==max(accuracy_cum3))[0][0]])\n",
"n_couches_optimal4 = (\n",
" choix_n_couches[np.where(accuracy_cum4==max(accuracy_cum4))[0][0]])\n",
"(n_couches_optimal2,n_couches_optimal3,n_couches_optimal4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Courbes d'apprentissage\n",
"\n",
2019-05-03 16:52:25 +00:00
"Ce graphique présente les courbes d'apprentissage pour chacun des niveaux de profondeur du réseau\n",
"\n",
"- MONKS1"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 47,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzs3Xtc1FX6wPHPYYDhjnJTQUUsJAXvpLWtyWqZ7baWaaZWattF2+y+pbVt21Za230v1WbqqmXZPd02ddfK6qdlXlBEFDFE5Sb34TIw1/P7YwYWcdABBmYGzvv14iV853s5g8w88z3nOc8RUkoURVEUxcfdDVAURVE8gwoIiqIoCqACgqIoimKnAoKiKIoCqICgKIqi2KmAoCiKogAqICiKoih2KiAoiqIogAoIiqIoip2vuxvQFlFRUXLQoEHuboaiKIpX2bt3b5mUMvp8+3lVQBg0aBB79uxxdzMURVG8ihDihDP7qS4jRVEUBVABQVEURbFTAUFRFEUBvGwMwRGLxUJFRQUmk8ndTVEURXErPz8/IiIi0Gg07Tre6wNCRUUFAQEBREZGYrFYsFqt7m6SoihKl5NSotfrKSsro0+fPu06h9cHBJPJREREBD/99BPl5eUIIdzdJEVRFLdoDApSSvr27dvm470+IACcPn2asrIygoODVUBQFKVHa2hoYOPGjdx+++1t7jrqFoPK9fX1+Pr6qmCgKN2A2SopqW7AYFbdv+3h6+tLQ0MD9fX1bT62WwQEd68L/cQTTzBx4kSmT5/uluvv3r2bxYsXu+XaiuIqRouVkxV60k9WkltWR2FV29/Q2spisTBr1iy3vH42btzI8uXLO+Xc7f1w3C0CgrtNmzaNN954w93NUBSv1GCykFtWx/6TVRRW1RMe6EeQv4Y6g7nTr71+/XoSEhI6/TreQgUEF0hNTSU8PPyc+5SXl3P//fczc+ZMZs6cyf79+wFYt24d06dPZ/r06bz99tsAFBQUnHG3sWbNGl5//XUATp48yR133MHMmTOZNWsWp06dAkCv1/Pggw8ybdo0li5d2nTXlJWVxa233sqNN97IokWLKC0tBWwvhOuuu44ZM2bwyCOPuPYXoihOqDOYyTldw4FTVZTVGIgK8WfkgF4M6RNKeKAfeqOlU+/+i4uL+fbbb7n++utb3cfR601KyUsvvcT06dO5/vrr2bJlC3D2nfry5cvZuHEjAJmZmdxyyy3MnDmTuXPnUldXB0BpaSmLFi3immuu4eWXX246dufOndx8883MmjWLhx56CL1eD8Crr77a9Lp98cUXXf476RaDyo3e2lNJbqXRpecc3NufO1J7d/g8zz33HGPHjuXVV1/FYrGg1+vJysris88+Y/369QDcdNNNpKamEhYW1up5li5dym233cbkyZMxGAxYrVaKi4s5cuQIn3zyCTExMcybN4/09HSGDx/Os88+y1/+8hciIiLYsmULf/vb33jqqadYvXo1mzdvxt/fn+rq6g4/P0Vxlq7eRGFVPbp6ExofQcrWTwgpysenWTdHf4uVKJMFofVF047uDzloENZbF5xzn+eff54HH3yw6c3ZEUevt23btpGdnc1HH31EVVUVc+bMYezYsa2ew2Qy8fDDD/PCCy+QkpJCbW0tWq0WgCNHjvDBBx/g7+/PtGnTmDt3LlqtlhUrVrBixQqCgoJYvXo169atY86cOXz55Zds2rQJIUSnvG67VUDwZD/++CPLli0DQKPREBoayr59+5g8eTJBQUEATJ48mX379pGWlubwHHV1dZSUlDB58mSApj8qgJSUlKY0s6SkJAoLCwkNDeXYsWMsXLgQsPWXRkfbCh4mJiaydOlSJk2axKRJkzrlOStKIymhUm+ksKqeWoMZP40PAyKC6BMWgH+A31l93hof288Wq0SjcX2yyDfffENERATDhg1j9+7dDvdp7fWWnp7O1VdfjUajITIyktTUVDIzMwkJCXF4nuPHjxMdHU1KSgrAGfuNHz+e0NBQAAYPHkxhYSE1NTXk5uYyf/58wBZQRo4cSXBwMFqtlieffJIJEyYwceJE1/wymulWAcEVn+S7Umu3wxqN5ozHjEbjOfcH8Pf3P+N4i8V2u33BBRfwzjvvnLX/a6+9xt69e9m+fTtvvvkmn376Kb6+3erPQfEAVikpqzVSVFVPvclCgK+GhKhgokO1TXcEjj7JSyk5lFdJnzAt8ZHBLm/X/v372b59O//3f/+HwWCgrq6ORx99lGefffaMNjhyrtdt84mxBoOh6fvWBnlbe91ecsklPP/882ft/+6777Jr1y42b97Me++9x6pVq879RNtIjSF0kfHjx/P+++8Dtk/qtbW1jB07lq+++or6+nr0ej1ffvklY8aMITIykoqKCqqqqjAajXzzzTeA7ZNFnz59+OqrrwBboDhXallCQgKVlZUcOHAAsH3SOHbsWFM307hx43jggQeoqalp6qNUFFewWCVFVfXsP1lFbmktPkJwYUwIIweE0ycs4IzuIUeEEPaBZUuntO++++5j27ZtbNmyheeff55x48adEQyg9dfb2LFj2bp1a1PZnL179zJ8+HBiY2PJzc3FaDRSU1PDrl27ANvrsKSkhMzMTMB252E2tz5gPmLECPbv38/JkycBW1p9Xl4eer2empoaJkyYwJIlS8jOznb578Wpj4RCiKnAXwANsFJK+ZyDfWYBTwISOCClnCuE+AXwSrPdLgJmSyk/E0KsASYCOvtjC6SU+9v7RNzpkUceYc+ePVRVVXHFFVfw29/+9qyBqiVLlvCnP/2JTz/9FI1Gw+OPP87IkSO59tprmTt3LgDXX389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TwF7pJSb7I9NEUJkARbgYSllOYAQYhC2O4xvWpx6vRAiGluX1H5gkWuekqIoHWG2WCmubqBYZ0sdDQ3wIyEqmF5B/uc/2MWC/RsHls34+3b99Xsap3LCpJRfAF+
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"for i in choix_n_couches:\n",
" plt.plot(range(10),lc_cum2[i-1], label=\"%d couches\"%(i,))\n",
"leg = plt.legend(loc='best', ncol=2, mode=\"expand\", shadow=True, fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
2019-05-03 16:52:25 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- MONKS2"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 48,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzs3Xlc1VX++PHX4bIjqCxuoGyi4oYLuZRrmmkJpplTNm3TtHybpqbFpX7VlO1ZM83SLLZM40zNNNNogZmWkqbmDm6AqIAim6CAsl3g3nt+f1wkVJDtst738/HgAdx7Pp9z7tX75vM5y/sorTVCCCHsg0N7N0AIIUTbkaAvhBB2RIK+EELYEQn6QghhRyToCyGEHZGgL4QQdkSCvhBC2BEJ+kIIYUck6AshhB1xbO8GXM7X11cHBQW1dzOEEKJT2b9//1mttV9D5Tpc0A8KCmLfvn3t3QwhhOhUlFKnGlNOuneEEMKOSNAXQgg7IkFfCCHsiAR9IYSwIxL0hRDCjkjQF0IIOyJBXwgh7IgEfRsrNBby2dHPSClIae+mtLs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SfJn/Cb/b+hp2tP3pj8Btf0uaZV6hKtq8pSxZ8O/IkPD39IUPcgVk5ZyWDvwS06597cvSzftpxCYyFPjn2SO8Pv7FQD36L1pZ1Pq5kNlVOag4eTBzcE3kBUSBSRfSLbdWqxBP3LFBoLeX7H82zN3Mq0gGmsuG6FXMF1AbtydvHMtme4UHGBp695mtsH397kQG2ymPjrob+y6tAq+nv2560pbzHUZ2grtVh0BRZtYf+Z/dZU6ae+obSqlL4
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"for i in choix_n_couches:\n",
" plt.plot(range(10),lc_cum3[i-1], label=\"%d couches\"%(i,))\n",
"leg = plt.legend(loc='best', ncol=2, mode=\"expand\", shadow=True, fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
2019-05-03 16:52:25 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- MONKS3"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 49,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzs3XlcVNX/+PHXYdhkUxY3XAAR913ctUXNNM0V9y2t1MoW62tan35l9vlUn/blY5apmfuaaaVpWlnu4IKigiKLLKLIvi8z5/fHIIGADDAwg57n48EDmHvunfeg9z1nzj33fYSUEkVRFOX+YGHqABRFUZSao5K+oijKfUQlfUVRlPuISvqKoij3EZX0FUVR7iMq6SuKotxHVNJXFEW5j6ikryiKch9RSV9RFOU+YmnqAO7k5uYmPT09TR2GoihKrXLq1Klb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ekFJKIcQDwFIhRD6gBeZJKROrEnDjwM+xTb5SlUOUkF3Ph+udXzSobUxMDMHBwXTs2LHENlVaWVHKdvXvdNJvlaxFUxUObpZ4Dyi96mVRc+fORQjB+PHj8fPzK7HdWOfuwkULGThuIEMeGYK7rbtZnrsGTRiVUu5Bf4G26GNvFvn5ItCvlP12ADuqGKPZuP1u/eqrr5ZaXlWVVlYU87N27VoaNGhAQkICc+fOxdPTE1/f4tUKjHHuJqQkEHcjjv4P98fDyaNY5UxzOndrXcE1Q3vkxpaXl8fLL7/M8OHDGTx4sMH7qdLKiqJnSI+8OjRo0AA
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"for i in choix_n_couches:\n",
" plt.plot(range(10),lc_cum4[i-1], label=\"%d couches\"%(i,))\n",
"leg = plt.legend(loc='best', ncol=2, mode=\"expand\", shadow=True, fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Choix des poids initiaux\n",
"Les poids initiaux ont été choisis à partir d'une distribution uniforme sur $[-1,1]$. On compare ici les courbes d'apprentissage en initialisant les poids à 0 et en initialisant les poids aléatoirement, pour le réseau de dimension et de profondeur optimale sélectionnées précédemment.\n",
"\n",
"- Réseau initialisé avec les poids à 0 $RN_{0}$"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"nn2_poidszero = NeuralNet.NeuralNet(\n",
" np.hstack((6,\n",
" np.repeat(n_neurones_optimal2,n_couches_optimal2),\n",
" 2)),\n",
" range(2),\n",
" input_weights=0)\n",
"lc_nn2_poidszero = (\n",
" nn2_poidszero.train(train2, train_labels2, 0.1, 10, verbose=False))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"nn3_poidszero = NeuralNet.NeuralNet(\n",
" np.hstack((6,\n",
" np.repeat(n_neurones_optimal3,n_couches_optimal3),\n",
" 2)),\n",
" range(2),\n",
" input_weights=0)\n",
"lc_nn3_poidszero = (\n",
" nn3_poidszero.train(train3, train_labels3, 0.1, 10, verbose=False))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
"nn4_poidszero = NeuralNet.NeuralNet(\n",
" np.hstack((6,\n",
" np.repeat(n_neurones_optimal4,n_couches_optimal4),\n",
" 2)),\n",
" range(2),\n",
" input_weights=0)\n",
"lc_nn4_poidszero = (\n",
" nn4_poidszero.train(train4, train_labels4, 0.1, 10, verbose=False))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Réseau initialisé avec les poids uniformes $RN_{\\neg{0}}$"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
"nn2_poidsunif = NeuralNet.NeuralNet(\n",
" np.hstack((6,\n",
" np.repeat(n_neurones_optimal2,n_couches_optimal2),\n",
" 2)),\n",
" range(2))\n",
"np.random.seed(12345)\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
"lc_nn2_poidsunif = (\n",
2019-05-03 16:52:25 +00:00
" nn2_poidsunif.train(train2, train_labels2, 0.1, 10, verbose=False))\n",
"nn2_compute_time = time.time() - start_time"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 54,
"metadata": {},
"outputs": [],
"source": [
"nn3_poidsunif = NeuralNet.NeuralNet(\n",
" np.hstack((6,\n",
" np.repeat(n_neurones_optimal3,n_couches_optimal3),\n",
" 2)),\n",
" range(2))\n",
"np.random.seed(12345)\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
"lc_nn3_poidsunif = (\n",
2019-05-03 16:52:25 +00:00
" nn3_poidsunif.train(train3, train_labels3, 0.1, 10, verbose=False))\n",
"nn3_compute_time = time.time() - start_time"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"nn4_poidsunif = NeuralNet.NeuralNet(\n",
" np.hstack((6,\n",
" np.repeat(n_neurones_optimal4,n_couches_optimal4),\n",
" 2)),\n",
" range(2))\n",
"np.random.seed(12345)\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
"lc_nn4_poidsunif = (\n",
2019-05-03 16:52:25 +00:00
" nn4_poidsunif.train(train4, train_labels4, 0.1, 10, verbose=False))\n",
"nn4_compute_time = time.time() - start_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"### Graphique des courbes d'apprentissage"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- MONKS1"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 56,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl4FGW2+PHvyUbY1wikwyayCAohYRiBUXFj4KqooIAsigs410FcrjM/9OLogOM6ZtRxmSG4IHgRRNxBkHFhRoMsQtCAEUQJEJZAFJAlIcn7+6O622ykO0knVdV9Ps+TJ+nq6uqTfrpP3px66z1ijEEppVRkiLI7AKWUUvVHk75SSkUQTfpKKRVBNOkrpVQE0aSvlFIRRJO+UkpFEE36SikVQTTpK6VUBNGkr5RSESTG7gDKa9OmjencubPdYSillKusX7/+gDEmIdB+jkv6nTt3Zt26dXaHoZRSriIiO4LZT8s7SikVQTTpK6VUBNGkr5RSEcRxNf3KFBcXk5+fz8mTJ+0ORS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MiRxMTEMGvWLP9/GmvXrq32xIpAxGkLl/Xv39+U75yVm5tL27ZtWbt2rf/fI6UCMiWwIwOae6BlZ2vbzjUQ3xwSetgamlKBFBYWcsMNNzB37twK0zoPHTrE5s2badOmDSNHjgRARNYbY/oHOq6Wd1T4KjgCmLKj+gZNrZG+Ug6
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"plt.plot(range(10),lc_nn2_poidszero, label=\"MONKS1: RN_Zero\")\n",
"plt.plot(range(10),lc_nn2_poidsunif, label=\"MONKS1: RN_Non_Zero)\")\n",
"leg = plt.legend(loc='best', \n",
" ncol=2, \n",
" mode=\"expand\", \n",
" shadow=True, \n",
" fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- MONKS2"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 57,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl4VOXZ+PHvnZ19DYsZlqiAgghIQBYJoNbCz1e0oii+WFewVapiW1+12FpU3Kna4gK4tSpudUUQa0WCCAqoiSIiSFhCJhAIe/bk+f3xzIQkBDIJM3NmuT/XlSuZM2fOuZPM3HPmfjYxxqCUUio6xDgdgFJKqeDRpK+UUlFEk75SSkURTfpKKRVFNOkrpVQU0aSvlFJRRJO+UkpFEU36SikVRTTpK6VUFIlzOoDa2rdvb7p37+50GEopFVbWrFmzyxiTXN9+IZf0u3fvzurVq50OQymlwoqI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mDRjTFpycrKvD4suo++C0oO2zONvZUWQ8Sh0GQInneP/49fHlWa/a4lHRZO8rKBf5YNvST8H6FLttguoPQl6DvCeMabMGJMNrMe+CSh/6XCq7UL55bNwcGf9+zfE6hfggNs2Ggf7Kh/sqmFN2+vkayp6lBbadXGD3HMHfEv6q4AeIpIqIgnA5cD7tfZ5FxgNICLtseWeTf4MVGEHS5UXw+eP+++YpYfg81mQmg6pI/x33IYQsV039UpfRYsda8FUBr3nDviQ9I0x5cBUYDGwDnjDGLNWRGaIyDjPbouB3SLyA7AE+KMxZjeAiCwD3gTOEZEcEfllIH6
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"plt.plot(range(10),lc_nn3_poidszero, label=\"MONKS2: RN_Zero\")\n",
"plt.plot(range(10),lc_nn3_poidsunif, label=\"MONKS2: RN_Non_Zero)\")\n",
"leg = plt.legend(loc='best', \n",
" ncol=2, \n",
" mode=\"expand\", \n",
" shadow=True, \n",
" fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- MONKS3"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 58,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl8VNX5+PHPk50dIoEgkUKVRRBEiai1Ku5xKaKIgBvuy0+k2upXaHEpuNFWba2oZVHcUXBDhYJbtVWxBEGRhGAEhMgykQRECEuS5/fHvRMmIclM1jvL83698srMuefee2YY8sw959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8mYpuHLcVJmxjXC/ZeBuRG6/7rhxzMmDNmdyiZ6+VY1fPzAz3IjmBhgAcFEp11F8PPmxhk/AGjdGVqlWUAwUc0CgolOvnomxamJiA0sm6hnAcFEJ/8Mo7qmzayN5UYwUc4CgolOvlxIbgdtD268Y6YPsNwIJqpZQDDRqXCV010k1d0UX082sGyinAUEE31UnS6jxho/8DvoMDc3wjeNe1xjwoQFBBN9ft4CJcWNN+XULy4eOve1gWUTtSwgmOhTsWRFPfMo1ya9v9NlZLkRTBSygGCiT0OzpNUmvT/s3gbbCxr/2MZ4zAKCiT6+XOcmslYdG//YlhvBRDELCCb6NEZSnJpYbgQTxSwgmOhSXu5OOW2C7iIIyI1gA8sm+lhAMNFl+wbY+zOkNcGAsp9/YNmYKGMBwUSXphxQ9kvvD9u+t9wIJupYQDDRpdAfEJryCsGfG2Fl053DGA9YQDDRxZcLbTMgpV3TncOWsDBRKqSAICJZIpI
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"plt.plot(range(10),lc_nn4_poidszero, label=\"MONKS3: RN_Zero\")\n",
"plt.plot(range(10),lc_nn4_poidsunif, label=\"MONKS3: RN_Non_Zero)\")\n",
"leg = plt.legend(loc='best', \n",
" ncol=2, \n",
" mode=\"expand\", \n",
" shadow=True, \n",
" fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On remarque ici aussi que l'initialisation des poids à 0 ne permet pas de démarrer l'entrainement du réseau. Dans le second jeu de données, cependant, l'initialisation aléatoire ne permet pas non plus de démarrer l'apprentissage."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entrainement et tests\n",
"On reprend les résultats du dernier entrainement, puisqu'il utilise les poids aléatoires et les hyperparamètres optimaux."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 59,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[ 0. 216.]\n",
" [ 1. 215.]]\n",
"\n",
"Exactitude:\n",
"0.4976851851851852\n",
"\n",
"Précision:\n",
"[0.0, 0.4988399071925754]\n",
"\n",
"Rappel:\n",
"[0.0, 0.9953703703703703]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.20888018608093262s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"res_test2 = nn2_poidsunif.test(test2, test_labels2)"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 60,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[255. 35.]\n",
" [126. 16.]]\n",
"\n",
"Exactitude:\n",
"0.6273148148148148\n",
"\n",
"Précision:\n",
"[0.6692913385826772, 0.3137254901960784]\n",
"\n",
"Rappel:\n",
"[0.8793103448275862, 0.11267605633802817]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.049660444259643555s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"res_test3 = nn3_poidsunif.test(test3, test_labels3)"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 61,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[203. 1.]\n",
" [199. 29.]]\n",
"\n",
"Exactitude:\n",
"0.5370370370370371\n",
"\n",
"Précision:\n",
"[0.5049751243781094, 0.9666666666666667]\n",
"\n",
"Rappel:\n",
"[0.9950980392156863, 0.12719298245614036]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.30426526069641113s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"res_test4 = nn4_poidsunif.test(test4, test_labels4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Congressionnal Dataset\n",
"\n",
"- Chargement du jeu de données"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"train5, train_labels5, test5, test_labels5 = (\n",
" ld.load_congressional_dataset(train_ratio = 0.7))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entrainement de l'arbre de décision\n",
"\n",
"Dans cette section, on entraine un arbre de décision basé sur la mesure d'entropie."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"dt5 = DecisionTree.DecisionTree(attribute_type=\"discrete\")\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
"_ = dt5.train(train5, train_labels5, verbose=False)\n",
"dt5_compute_time = time.time() - start_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Courbe d'apprentissage"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 64,
"metadata": {},
"outputs": [],
"source": [
2019-05-03 17:14:26 +00:00
"dt_range_lc5,dt_accuracy_cum5 = (\n",
" courbe_apprentissage_dt(dt5,train5,train_labels5))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Voici le graphique de la courbe d'apprentissage"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 65,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdac0306d8>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 65,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSY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bxhQ5Gyn7zZfwElAlkpeOeu5XT346m934e1nTsPfXbsYACB5vFaBQFAZCNH3CRdo95JNd4FNDeSq7o/po3pHM9zjnfAElGweHzJbL3zjPefZi8FLRKJOXyCoYITo+8R2+h4zct1MdWog18vpW3X6OcRZNxgUN9HPV7IpSyUvlzgUM09WfPAYmLiWEwKB4PQgRN8ncdXb6csSuTp9NU/JJr8SyBXDmE7fkenX+a3eKb1kc3hcRUNIQcAxW1iShNMXCCoZIfo+yRXveLnffNU7drxjOX3dYLjl2y/h6e0n7X1KcfrlEP1mh8sHeLxT0sMKBIJJRIi+T1IDudkO26sNAz9RjHlW76Rn+kOxJLYfH8HOEyP2PpmZftMEZvrD42patAN4D1oLBILKQIi+T2yn7+KwJYlcc3ke3/RFE1j55Wfxu20n0263Z+Ry0R83M3QeJQGAphseTj9fnX454p0kmiPpPfkkkekLBBWNEH2fJHJk+opHzs1LNg/2RdEzmsC+ntH0x+RO3xJnPnDKV8YCclTv5K3TL0+80xJJ7+Ypi+odgaCiEaLvk1zxjlfDNe70uUaOZmT7yYx4Z3g8aT1XSqx1g6UNpHa1RHDF4g5cOK815/EGZAkGKy2K8c70hegLBJWKr376gnx1+rkHcjmZA7qZk7O400/kcPrhgIwff/hteY+XT+hSdQOylDsK8mJ4XLWrhThmvFPUwwkEgimAcPo+yZXp56ve4TgHdDXdsO+jZsQ76U4/PdP3S9C6OkgWqdBxVUdcNbKcviyJ5RIFgkpGiL5PuPv2WhjdVfQzBNc5SSszwgG
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2019-05-03 16:52:25 +00:00
"plt.plot(dt_range_lc5,dt_accuracy_cum5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test et évaluation de la performance de l'arbre de décision"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 66,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[26. 36.]\n",
" [ 8. 67.]]\n",
"\n",
"Exactitude:\n",
"0.6641221374045801\n",
"\n",
"Précision:\n",
"[0.7647058823529411, 0.6504854368932039]\n",
"\n",
"Rappel:\n",
"[0.41935483870967744, 0.8933333333333333]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.0005347728729248047s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"dt5_testres = dt5.test(test5, test_labels5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Réseaux de neurones: Choix du nombre de neurones dans la couche cachée"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Pour faire la séparation du jeu de données en $k_{cv}=5$ jeux de validation croisée, on génère une permutation sur les indices du jeu d'entrainement, puis, on sépare cet ensemble en 5 groupes."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"all_indices5 = range(len(train_labels5))\n",
"np.random.seed(12345)\n",
"indices_cv_test5 = (\n",
" [np.sort(x) for x in (np.array_split(np.random.permutation(all_indices5),\n",
" k_cv))])"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
"indices_cv_train5 = (\n",
" [np.setdiff1d(all_indices5,indices_cv_test5[i]) for i in range(k_cv)])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ce jeux de données a trois classes possibles comme variable de sortie. On utilisera donc un réseau de neurones avec 3 neurones dans la couche de sortie, une pour chacune des valeurs possibles. Les valeurs de sortie du jeu de données sont transformées à l'aide d'un encodage binaire où la valeur de sortie est convertie en rang dans un vecteur (on commence à 0), prenant la valeur 1. Par exemple, la valeur 2 devient $[0,0,1]$."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 69,
"metadata": {},
"outputs": [],
"source": [
"accuracy_cum5 = []\n",
"for n_neurones in choix_n_neurones:\n",
" accuracy_cv=[]\n",
" for cv_set in range(k_cv):\n",
" accuracy=0\n",
" try:\n",
" nn5 = NeuralNet.NeuralNet(np.array([16,n_neurones,3]),range(3))\n",
" nn5.train(train5[indices_cv_train5[cv_set]], \n",
" train_labels5[indices_cv_train5[cv_set]], 0.1, 1, \n",
" verbose=False)\n",
" _,accuracy,_,_,_ = nn5.test(train5[indices_cv_test5[cv_set]], \n",
" train_labels5[indices_cv_test5[cv_set]], \n",
" verbose=False)\n",
" except:\n",
" pass\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum5.append(np.mean(np.array(accuracy_cv)))"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 70,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"[<matplotlib.lines.Line2D at 0x7fcdabf9aeb8>]"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 70,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJztnXmYW3d577+v9m0041k8i+3xeI/XxMFJnI2sTkziJEBbSCiF3hJyoYRCE9ZethvK0962F7ht05bQpqUsCSEEMCYQnAVIiJPYjnc7ju3JzHg8+6bRjHbpd/8450gajZYj6Ug6I72f5/HjmaMj6WdZ59Wr7/v+vi8JIcAwDMPUBoZKL4BhGIYpHxz0GYZhaggO+gzDMDUEB32GYZgagoM+wzBMDcFBn2EYpobgoM8wDFNDcNBnGIapITj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8pVTXCY88v0o/JGLrvFOKeDh4N+DXL4vGT7e4mKYmMxCCFwtN+jqqhZDRzqm4LLasKaxXUFP4bJaMC1a1pw7ZoW/PU7N+Plc2N45sQQ9p4cxp6jg7CYDLh2dTNu29yOd25dolkGO+QJ4K2xWfzxFZ1533fTEjeee2MYs8FIWoM5hedODUMIYM/Hr8H6djdiQkAIQEDg5MA03vUvL6NnbFZ10O8emwUAfP09F2NbV+O822/d2IaNHW5889kz2LWlo6LzfZ882I/Xeibwt+/ejEY56F6zugVumwl7jg5mDvrd42hz29DV5EBILvqqDfrKNwKnrOkDUtAv9/XIhVwd8NDPT+A9/7av5La4z5wYxl0P/16XVgOl4JXucVyyrEGzQGwxGXD9usX4m3dvwat
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(choix_n_neurones,accuracy_cum5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Le nombre de neurones qui maximise l'*accuracy* est de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 71,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 71,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n_neurones_optimal5 = (\n",
" choix_n_neurones[np.where(accuracy_cum5==max(accuracy_cum5))[0][0]])\n",
"n_neurones_optimal5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"### Choix du nombre de couches cachées"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"accuracy_cum5 = []\n",
"lc_cum5 = []\n",
"for n_couches in choix_n_couches:\n",
" accuracy_cv=[]\n",
" nn5 = NeuralNet.NeuralNet(\n",
" np.hstack((16,\n",
" np.repeat(n_neurones_optimal5,n_couches),\n",
" 3)),\n",
" range(3))\n",
" lc = nn5.train(train5, train_labels5, 0.1, 10, verbose=False)\n",
" lc_cum5.append(lc)\n",
" _,accuracy,_,_,_ = nn5.test(train5, train_labels5, verbose=False)\n",
" accuracy_cv.append(accuracy)\n",
" accuracy_cum5.append(np.mean(np.array(accuracy_cv)))\n",
"lc_cum5 = np.array(lc_cum5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"L'*accuracy* pour les différentes profondeur est de :"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 73,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"array([[1. , 2. , 3. , 4. , 5. ],\n",
" [0.94736842, 0.92105263, 0.92763158, 0.90460526, 0.8125 ]])"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 73,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.vstack((choix_n_couches,accuracy_cum5))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"Le nombre de couches cachées qui maximise l'*accuracy* est de:"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 74,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 74,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2019-05-03 17:14:26 +00:00
"n_couches_optimal5 = (\n",
" choix_n_couches[np.where(accuracy_cum5==max(accuracy_cum5))[0][0]])\n",
"n_couches_optimal5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Courbes d'apprentissage\n",
"\n",
"Ce graphique présente les courbes d'apprentissage pour chacun des niveaux de profondeur du réseau"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 75,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsnXd4VMX3h9+7yaZveiEhhE4CBBISiki3oQiogAVExa+KHfBnQWxgo1iwowgiFiyIhaaAqPRO6AmEUNJ7202y2Tq/P24ICQTSNgVy3+fZZ8udO3PuZvOZuWfOzJGEECgoKCgotAxUTW2AgoKCgkLjoYi+goKCQgtCEX0FBQWFFoQi+goKCgotCEX0FRQUFFoQiugrKCgotCAU0VdQUFBoQSiir6CgoNCCUERfQUFBoQVh39QGXIivr69o165dU5uhoKCgcEWxf//+HCGEX3Xlmp3ot2vXjn379jW1GQoKCgpXFJIkJdaknOLeUVBQUGhBKKKvoKCg0IJQRF9BQUGhBVEj0Zck6WZJkk5IkpQgSdKLVRxvK0nSP5IkHZYkaZMkScEVjlkkSTpY9lhlS+MVFBQUFGpHtRO5kiTZAZ8BNwIpwF5JklYJIWIrFHsP+FYI8Y0kSdcBc4D7yo7phRCRNrZbQUFBQaEO1GSk3xdIEEKcFkIYgZ+A2y4o0w34p+z1f1UcV1BQUFBoBtRE9FsDyRXep5R9VpFDwNiy13cAGkmSfMreO0mStE+SpF2SJN1eL2sVFBQUFOpFTeL0pSo+uzDH4nPAp5IkTQK2AKmAuexYiBAiTZKkDsC/kiQdEUKcqtSAJE0GJgOEhITUwnwFBQWFulFsMBOfqeN4ho70An1TmwNAKw9nJvRrWA2sieinAG0qvA8G0ioWEEKkAWMAJElyA8YKIQorHEMIcVqSpE1AL+DUBed/CXwJ0Lt3byVpr4KCgs2wWgVJeSUcz9ASl67jeIaW4xk6kvJKqJgiX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Flp7OnNbZBBju9jRMelX2L8UdOng2Rb6PASdboD0w5C0A5G4Eyn3pNyecCDRuSu+3Yfi220oBPcFx4sFQQjBWe3Z8h/1/sz9pBalAuBi70Kkf2T5CKeHb496+Xevag7+CH88BhN/g07Xn//cWAxLboa8M/DQBgjodtlqrMLK6YLT533PWTHlLj6NWiP/PQJkke/u0x0Hu+YjqGdyinn8+/2cyNTxzA1deGpYJ1SmIjj+Jzh5gGcb8AiWX1+BWIWVhIKE8k5gf9Z+skqyANA4aCoNmLr7dEfdAHM5iug3czKKM9icLPvm92TswWAx4Kp25dqgaxnaZigDWw/Ey9GLwymF/HEwldWH0sgpMuLuZM+tPYO4IzKI3sSi2rcYjq8Bq0UW+b6PyM9V+WKLsjCc3s7x3etRp+4iVJzFThIIyQ4psCe0HSD7m0P6g6vPxeeX2X0g60C56JzMlzsSe5U94T7h5aIT6R+Ju4N7Q36FVwZCwMJBYDHDEzsv9t8XpsKi68DeAR75D1zPu1xMVhNxuXHlInIg6wCFhkIAfJ19yzvc3gG96eTZqdmGGq4/lsFzyw9hbyfx0T29GNzFD0q18P0YSNlbubCjhyz+nm3Ao80Fr9uAWwComn8aECEEqUWplVxtZ7VnATlaqYdvj3J3UIR/BK5q13q3qYh+M8MqrBzNOcqm5E1sSdnCifwTAAS7BTO0zVCGtBlCtH80ajs1ibnF/HEgjZUHUzmdU4yDvYrrw/y5vVdrhrZzwjF2BexZDNlx4OQJvSbKI3vvDjW2J7/YyOJ/DhG39x96S8e51f0MIfo4JItBLuAbCm37Q8i18rNn1UvDCw2FHMg6UC5MsTmxmIUZCYnOXp2J8o/ipnY30adVn3p/h1ckZ7bCNyNh1McQ/UDVZVL3w9c
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"for i in choix_n_couches:\n",
" plt.plot(range(10),lc_cum5[i-1], label=\"%d couches\"%(i,))\n",
"leg = plt.legend(loc='best', ncol=2, mode=\"expand\", shadow=True, fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Choix des poids initiaux\n",
"Les poids initiaux ont été choisis à partir d'une distribution uniforme sur $[-1,1]$. On compare ici les courbes d'apprentissage en initialisant les poids à 0 et en initialisant les poids aléatoirement, pour le réseau de dimension et de profondeur optimale sélectionnées précédemment.\n",
"\n",
"- Réseau initialisé avec les poids à 0 $RN_{0}$"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 76,
"metadata": {},
"outputs": [],
"source": [
"nn5_poidszero = NeuralNet.NeuralNet(\n",
" np.hstack((16,\n",
" np.repeat(n_neurones_optimal5,n_couches_optimal5),\n",
" 3)),\n",
" range(3),\n",
" input_weights=0)\n",
"lc_nn5_poidszero = (\n",
" nn5_poidszero.train(train5, train_labels5, 0.1, 10, verbose=False))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Réseau initialisé avec les poids uniformes $RN_{\\neg{0}}$"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 77,
"metadata": {},
"outputs": [],
"source": [
"nn5_poidsunif = NeuralNet.NeuralNet(\n",
" np.hstack((16,\n",
" np.repeat(n_neurones_optimal5,n_couches_optimal5),\n",
" 3)),\n",
" range(3))\n",
"np.random.seed(12345)\n",
2019-05-03 16:52:25 +00:00
"start_time = time.time()\n",
"lc_nn5_poidsunif = (\n",
2019-05-03 16:52:25 +00:00
" nn5_poidsunif.train(train5, train_labels5, 0.1, 10, verbose=False))\n",
"nn5_compute_time = time.time() - start_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2019-05-03 16:52:25 +00:00
"### Graphique des courbes d'apprentissage"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 78,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX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x/PV3L7/Hfv/f8OEd4eLu3f6tv+MkVMC/IAHC3t2wzuGPeu/ecMEnqZ0g6sirwp7RpHvDWZZS8biHoYe/LQhdedvXj7qi4lWtHgYTWJVwoLm8jhdNvC3suOx3OpxwZ8X8QKyA9CpVNPlrwtfVh7uEvfF+z8CpD6X+DW8W9oz27g1v/TOM/ZaKZfKD8PU4OOaf0OzAqKvZsrrN4ZQHw5DSCdeU/eN99N8wD9A+p8HJ9yjwS0HdOxXJgqnw0oXhep37nR6GxW1Xr+wer0oV6PkArF4azvDcrh6061F2jxeVxd+Fuebz10DmudD25LB3WpHlTIU3/g5tjg8HJ9NBm+5w6EXw8T3Q4rBwzkhZ+OTBcOC4/Snh77c8pqCoRPTxWBGsXR32th85JgTw6WOg5/1lG/jrVK0exvg3PQCePw/mvFf2j1mevngWHjw8hOhvuWF64Lv2hndvht9+iLq64q1cHLpJdtgl/B2kUz91l3+EC6qPvRgWZad++1Mehdevgr1ODOcqpPLaATGh0I/a/CnhJKsP7wx79xd+EoZWlqfq20P/Z6DBHjD69PCNI92tWQYvnA8vDICd28FfPoSLPoPTnw8nFb3/7xD+z50DcydVnFFM7vDSBWFYbp/Hy+eDP5UyqoXzCDKqhwu7rF2Vum1/9mT4xrZnN+j9WHgsKTWFflTWrgpji4cfG658dMbz0OPeMGtiFLarB2e8EEYJjewdpmdOVwumhr37L58NB6zPHh/6nKtUCdeOPf1ZuPgzOOj/4Nu34bFuof3UEeHqSlH6+J4wK+SxN0DTTtHWsrV2bAqnDoO
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.subplot(111)\n",
"plt.plot(range(10),lc_nn5_poidszero, label=\"RN_Zero\")\n",
"plt.plot(range(10),lc_nn5_poidsunif, label=\"RN_Non_Zero)\")\n",
"leg = plt.legend(loc='best', \n",
" ncol=2, \n",
" mode=\"expand\", \n",
" shadow=True, \n",
" fancybox=True)\n",
"leg.get_frame().set_alpha(0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On remarque ici aussi que l'initialisation des poids à 0 ne permet pas de démarrer l'entrainement du réseau."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entrainement et tests\n",
"On reprend les résultats du dernier entrainement, puisqu'il utilise les poids aléatoires et les hyperparamètres optimaux."
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 79,
"metadata": {},
2019-05-03 16:52:25 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrice de confusion:\n",
"[[57. 2.]\n",
" [ 7. 65.]]\n",
"\n",
"Exactitude:\n",
"0.9312977099236641\n",
"\n",
"Précision:\n",
"[0.890625, 0.9701492537313433]\n",
"\n",
"Rappel:\n",
"[0.9661016949152542, 0.9027777777777778]\n",
"\n",
"Calculé en:\n",
2019-05-03 17:14:26 +00:00
"0.021606922149658203s\n"
2019-05-03 16:52:25 +00:00
]
}
],
"source": [
2019-05-03 16:52:25 +00:00
"res_test5 = nn5_poidsunif.test(test5, test_labels5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Comparaison entre arbre de décision et réseau de neurones"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Taux d'erreur sur l'ensemble de test. Sur la première ligne, les erreurs pour les arbres de décision, sur la seconde, pour les réseaux de neurones"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 80,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.97777778, 0.52546296, 0.62962963, 0.53703704, 0.66412214],\n",
" [0.91111111, 0.49768519, 0.62731481, 0.53703704, 0.93129771]])"
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 80,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array([[dt1_testres[1],\n",
" dt2_testres[1],\n",
" dt3_testres[1],\n",
" dt4_testres[1],\n",
" dt5_testres[1]],\n",
" [res_test1[1],\n",
" res_test2[1],\n",
" res_test3[1],\n",
" res_test4[1],\n",
" res_test5[1]]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Temps de prédiction dun seul exemple. Sur la première ligne, les temps de prédiction moyens pour un exemple de l'ensemble de test pour les arbres de décision, sur la seconde, pour les réseaux de neurones"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 81,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"array([[6.53796726e-06, 2.56024025e-06, 3.92342055e-06, 4.10223449e-06,\n",
" 4.08223567e-06],\n",
" [8.89841715e-04, 4.83518949e-04, 1.14954732e-04, 7.04317733e-04,\n",
" 1.64938337e-04]])"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 81,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array([[dt1_testres[4]/len(test_labels1),\n",
" dt2_testres[4]/len(test_labels2),\n",
" dt3_testres[4]/len(test_labels3),\n",
" dt4_testres[4]/len(test_labels4),\n",
" dt5_testres[4]/len(test_labels5)],\n",
" [res_test1[4]/len(test_labels1),\n",
" res_test2[4]/len(test_labels2),\n",
" res_test3[4]/len(test_labels3),\n",
" res_test4[4]/len(test_labels4),\n",
" res_test5[4]/len(test_labels5)]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Temps dapprentissage du modèle. Sur la première ligne, les temps d'entrainement pour les arbres de décision, sur la seconde, pour les réseaux de neurones"
]
},
{
"cell_type": "code",
2019-05-03 17:14:26 +00:00
"execution_count": 82,
2019-05-03 16:52:25 +00:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2019-05-03 17:14:26 +00:00
"array([[9.11688805e-03, 2.06351280e-03, 2.00963020e-03, 1.85656548e-03,\n",
" 1.11479759e-02],\n",
" [4.42183232e+00, 2.92573667e+00, 7.95306206e-01, 4.50003695e+00,\n",
" 2.64667988e+00]])"
2019-05-03 16:52:25 +00:00
]
},
2019-05-03 17:14:26 +00:00
"execution_count": 82,
2019-05-03 16:52:25 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array([\n",
" [dt1_compute_time,\n",
" dt2_compute_time,\n",
" dt3_compute_time,\n",
" dt4_compute_time,\n",
" dt5_compute_time],\n",
" [nn1_compute_time,\n",
" nn2_compute_time,\n",
" nn3_compute_time,\n",
" nn4_compute_time,\n",
" nn5_compute_time]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conclusion"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Les arbres de décisions sont des algorithmes simples à mettre en oeuvre et démontrent une exactitude supérieure et comparable aux arbres de décisions lorsque le nombre d'attributs est limité. Cependant, lorsque le nombre d'attributs croît, les réseaux de neurones sont beaucoup plus performants. Ceci est démontré entre autres par la performance sur le jeu de données Congressionnal où le réseau de neurones est beaucoup plus performant. Pour les jeux de données plus difficiles tels que MONKS, on ne remarque pas une grande différence entre les deux algorithmes au niveau du taux d'erreur.\n",
"\n",
"Le temps de prédiction est deux ordres de magnitude plus élevé pour les réseaux de neurones que pour les arbres de décisions, car il faut effectuer toutes les multiplications des valeurs par les poids pour chacune des couches, ce qui est une opération $O(d^2)$ pour une dimension $d$. Pour l'arbre de décision, la prédiction est une recherche dans un arbre binaire, de complexité $O(log_2(d))$ pour une profondeur $d$.\n",
"\n",
"Les réseaux de neurones nécessitent beaucoup plus de temps d'entrainement que les arbres de décisions, et il faut aussi considérer que ce temps est multiplié lorsque l'on effectue une recherche des hyperparamètres optimaux. Ce besoin de capacités physique explique pourquoi il a fallu attendre l'apparition des processeurs graphiques très performants pour que la recherche avec les réseaux de neurones explose. La complexité est d'autant plus élevée, car le nombre de connexions croit de façon exponentielle avec l'ajout de nouvelles couches cachées."
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}