408 lines
83 KiB
Text
408 lines
83 KiB
Text
|
{
|
||
|
"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",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import load_datasets as ld\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"import NeuralNet"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Iris Dataset\n",
|
||
|
"\n",
|
||
|
"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, seul les résultats et la discussion seront détaillés.\n",
|
||
|
"\n",
|
||
|
"- Chargement du jeu de données"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"train1, train_labels1, test1, test_labels1 = ld.load_iris_dataset(train_ratio = 0.7)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Choix du nombre de neurones dans la couche cachée\n",
|
||
|
"\n",
|
||
|
"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 et 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",
|
||
|
"execution_count": 3,
|
||
|
"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",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"k_cv = 5\n",
|
||
|
"all_indices = range(len(train_labels1))\n",
|
||
|
"np.random.seed(12345)\n",
|
||
|
"indices_cv_test = np.sort(np.array_split(np.random.permutation(all_indices),k_cv))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[ 4, 9, 13, 19, 20, 25, 33, 37, 39, 40, 44, 47, 48,\n",
|
||
|
" 54, 58, 62, 72, 76, 78, 87, 89],\n",
|
||
|
" [ 2, 6, 8, 26, 28, 30, 35, 42, 45, 50, 51, 52, 57,\n",
|
||
|
" 60, 63, 69, 74, 79, 90, 92, 96],\n",
|
||
|
" [ 0, 16, 17, 18, 21, 22, 24, 27, 32, 46, 49, 65, 66,\n",
|
||
|
" 68, 75, 83, 84, 85, 86, 88, 99],\n",
|
||
|
" [ 3, 5, 12, 15, 23, 31, 43, 53, 55, 56, 61, 64, 67,\n",
|
||
|
" 70, 71, 93, 94, 95, 97, 100, 104],\n",
|
||
|
" [ 1, 7, 10, 11, 14, 29, 34, 36, 38, 41, 59, 73, 77,\n",
|
||
|
" 80, 81, 82, 91, 98, 101, 102, 103]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"indices_cv_test"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"indices_cv_train = [np.setdiff1d(all_indices,indices_cv_test[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",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"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": [
|
||
|
"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",
|
||
|
" nn1.train(train1[indices_cv_train[cv_set]], train_labels1[indices_cv_train[cv_set]], 0.1, 1, verbose=False)\n",
|
||
|
" _,accuracy,_,_,_ = nn1.test(train1[indices_cv_test[cv_set]], train_labels1[indices_cv_test[cv_set]], verbose=False)\n",
|
||
|
" accuracy_cv.append(accuracy)\n",
|
||
|
" accuracy_cum.append(np.mean(np.array(accuracy_cv)))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"[<matplotlib.lines.Line2D at 0x7f054f634ac8>]"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 8,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl0W9d16P/vxkCCE0BKHDQPlDXQoyzJiuOptuUkztA4vw6u3TTxFPu9tmmaNm1e0iFJ09dprffS9teXtHESx85LE9d1k8ZN3bqRbEd2EtsaPEqkLImaOY8AJxDDeX8AFwRJgLggQYAC9mctLZEXF9T1NbFxsM8++4gxBqWUUqXBUegLUEoplT8a9JVSqoRo0FdKqRKiQV8ppUqIBn2llCohGvSVUqqEaNBXSqkSokFfKaVKiAZ9pZQqIa5CX8BM9fX1ZsOGDYW+DKWUuqgcOnSozxjTkOm8JRf0N2zYwMGDBwt9GUopdVERkTN2ztP0jlJKlRAN+kopVUI06CulVAnRoK+UUiVEg75SSpUQW0FfRG4XkWMickJEPpPi8XUi8pyIvCoib4jI+5Ie+2z8ecdE5D25vHillFLZyViyKSJO4MvAu4DzwAERecoYczTptD8CnjDG/L2IXAo8DWyIf30XcBmwCtgrIluMMZFc/4copZTKzM5IfzdwwhjTboyZBB4H7phxj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bmO9FXOtMcncefaF3cmr9V0LY8VPBr01aLyT4QZnYykbMFgSXTbnJHXP9rh54Xjfdx7/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": [
|
||
|
"Le nombre de neurones qui maximise l'accuracy est de:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"49"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 9,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"n_neurones_optimal1 = 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",
|
||
|
"On choisit un nombre de 1 à 5 couches cachées. Le nombre de couche ayany 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",
|
||
|
"execution_count": 27,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"choix_n_couches = range(1,6)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 21,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"accuracy_cum = []\n",
|
||
|
"lc_cum = []\n",
|
||
|
"for n_couches in choix_n_couches:\n",
|
||
|
" accuracy_cv=[]\n",
|
||
|
" nn1 = NeuralNet.NeuralNet(np.hstack((4,np.repeat(n_neurones_optimal1,n_couches),3)),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": "code",
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"[<matplotlib.lines.Line2D at 0x7f054f4e1588>]"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XlcVXX+x/HXh0UQRRTEDXDB3DdANPeyJjMrtXJtpmVarEmbZppmpqb51Yz92maqaUqrsX5NqwpqmZnTMqnlUsYFcd8QzQu4oCi4Idv398e9zhChXJR7z10+z8eDR5d7vofz4RhvDt9zzueIMQallFKBIcjqApRSSnmOhr5SSgUQDX2llAogGvpKKRVANPSVUiqAaOgrpVQA0dBXSqkAoqGv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xrMk5wuurcvlqZyHhoUFM7B/PncM6uWWqML5FBH+d0Jdp72by9LLt/Glsrwbfhjo//0yJALJ0QwGnyyst7ZvvCSLC9JGX0KNtJA/My2bsrDXMvjmFwZ1jrC7NJ5VVVLFkQwFvrMpl+4HjtGwaxm+u6spPB3Ugukkjt257VK823DG0E2+u2cPgzjFc3auNW7enfkifnOXjbnxlDSWlFXzx6xEBM9e9u/AE096xsffIKf7n2h7cNqRjwHzvF+vYqTLeX7ePt9fu5dDxM3RrHcmdwzsxLqkdYSHBHqujrKKKCa+tZe/hk3zyy+EuXQWkzk+fnBUAcg4dJ2vfMSanem9zNXfoHNuUxdOHMrJbLH/6eCu/W7hRr/+uw97DJ3nso80Mfno5f/1sB93aRPLOHQP59Ff
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(choix_n_couches,accuracy_cum)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Le nombre de couches cachées qui maximise l'accurary est de:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 32,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"4"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 32,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"n_couches_optimal1 = choix_n_couches[np.where(accuracy_cum==max(accuracy_cum))[0][0]]\n",
|
||
|
"n_couches_optimal1"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"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",
|
||
|
"execution_count": 31,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzsnXl8VNXd/99nlkz2PQRCyMJqIASVzVYpCj6Ktg/W9REFxd1Wulgfq2392QpP1dYu+nTRakWEutTaVn1UXBHc2UlIAmHLShaSTJbJ7DP3/P6YmRggyySZJZPc9+uVFzP3nnvumWHu937u93zP9yuklKioqKiojA004R6AioqKikroUI2+ioqKyhhCNfoqKioqYwjV6KuoqKiMIVSjr6KiojKGUI2+ioqKyhhCNfoqKioqYwjV6KuoqKiMIVSjr6KiojKG0IV7AKeSnp4u8/Lywj0MFRUVlYhi9+7dLVLKjIHaDWj0hRDrgW8BJ6SUhb3sF8ATwKWABVgtpdzj3Xcj8IC36f9IKZ8f6Hx5eXns2rVroGYqKioqKj0QQlT7084f984GYFk/+y8Bpnn/bgee9A4gFfg5sBBYAPxcCJHiz6BUVFRUVILDgEZfSvkxYOynyWXARunhSyBZCDEBuBh4X0pplFK2Ae/T/81DRUVFRSXIBGIidyJQ2+N9nXdbX9tVVFRUVMJEICZyRS/bZD/bT+9AiNvxuIbIyck5bb/b7cZoNOJ0OocxTBUVFZXIR6/Xk5qailarHdLxgTD6dcCkHu+zgXrv9vNP2b61tw6klE8DTwPMmzfvtBuD0WgkOjqa9PR0pJS4XC7UOgAqKipjDSklFouFpqYmJkyYgCeOZnAEwui/AawRQ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DDezdu5fZs2fzyCOP8MQTT5Camso777zDH/7wB9auXcv69evZvHkzUVFRdHZ2DvvzqagMB81zGxBVVQHtU+blody0ut82v/71r/nRj36E2WzG4VLYf7wDAZwxPoHkWE/kS2/X3Keffkp7QzUvvvwK1fXN3P2dm8iaOosTjV2YbE7q262kxH0VOeN0Orn33nt57LHHKCwspKurC4PBAMDBgwd55ZVX0AvB8ssu4/KZM4mOj2fDhx/yzMaNxMbGsn79ejZu3MiKFSv48MMPeeONNxBCBPzajTijP5LZsWMHv/zlLwHQarUkJCSwZ88eli5d2j0BvXTpUvbs2cP555/fax9ms5kTJ06wdOlSgO4fDUBhYSHjx48HYMaMGdTX15OQkMCRI0e44447AI/vMsM7ETRt2jTuv/9+lixZwpIlS4LymSMCKVEsFqSioImJQejUn/1YYdu2baSmplJQUMBbWz7F7HARo9cyLTMeg84zadvXNbd3714uveQSUuOjSZ0+ia8vXADGWtITopASaowWaowWWrrstHbZKas4QkZGBoWFnryU8fHx3eNYuHAhMTYbjtpa8jIzaQYsLheVNTXceOONgOemMWfOHOLi4jAYDPziF79g0aJFLF68OKDfScT9+gOhyENJXxMtWq32pH0Oh6Pf9sBJ8bharRa3242UkilTpvC3v/3ttPZ/+tOf2L17N1u3buUvf/kL//73v9GNEYMnFQWlsxN3ezvu9nako8fToU6HJjoaER2DJiba+9rzb7D9qWOZgRR5MNi3bx9bt25ly9aPcTjs2KwW/vaHR3j00Ue72/R1zfW23aDXkJQUR7xBy1k5ybSZnbhdTtotTo6cMGG2uznW3EVKbBRJsXo0QqDY7Wi7unBUVqJJSECflIRISwOzmXPOOadXt+uLL77I9u3b2bx5My+99BLPPvtswL4TdSI3gCxcuJC///3vgEdxd3V1MXfuXLZs2YLVasVisfDhhx9y9tlnk5aWhtFopL29HYfDwbZt2wCPOsjMzGTLli2A52ZgtVr7PGd+fj5tbW0UFxcDHrVw5MiRbpfQggULuPvuuzGZTFgsliB/A+FFuly4WlqwHzmCde9e7IcO4WptRRMXR9TkyRimT0efk4MuJRWEwN3RjrO2Fvvhw9j278eyaxfWkhLshw7jqK3F1dyM22RCulzh/mgqQ+Sm27/Lr579B48+8zK/+J9HOGfhwpMMPvR9zc2dO5d33323Ow3M7t27mT17NllZWRw7dgyhuInTOKko2UNeehznnjWTjrZWdu0roaLJxGfltdSXVeA8fhzpdhM1eTLRBQUIb/qEoqIi9u3bR01NDQBWq5WqqiosFgsmk4lFixZx3333UVFREdDvZGzIvgDw4x//mF27dtHe3s6FF17Id7/7Xa644oqT2tx333089NBD/Pvf/0ar1fLAAw8wZ84cLrvsMq677jrAM5FbUFAAwB133MH111/PxIkTT4osePjhh1m7di1/+tOf0Ol03RO5vaHX6/ntb3/Lo48+SldXF263m+uvv57c3Fx++tOfYjKZkFKyatWqfucRIhXFbsfd1oa7rR2ly+QJd9Pr0aWmoU1JRpOYiNB8pW1OjcKWLhfSZkOx2VCsNqTNimKzITs6QCpfNVSfDiIKKaGhw0qt0UK0XkvBhETKWvR9tu/tmlu6dCnFxcVcddVVCCG4++67SU9PB+Ciiy7iyiuvJDc3l4KCArQawYSUeB7/3W945JFHsJjNGBD88Ud306WPwRgVT4VDT0q7FbfieYJITU1l3bp13Hfffd1P+mvWrCEuLo4f/OAH2O12pJTce++9Af1uxEjLYTNv3jx5ahGV+vp6MjMz2blzJ3FxcWEamcqIwOufd3kNvbR6nl5ETAzalBR0yclo4uKGb4ilRLHbu28I0mpD8d4Q6JkGRAiEwYAmOgbR82agzh2EDZfbE47ZZnGQFhfF5Ix4tJrQ3JgVux1ndTXu9nZEbCxRubnYomJoszhoMzsxOzxPjTF6LSlxUaTE6ok36Af9c+3o6KC8vJz09PRu8SmE2C2lnDfQseqvMghIlwsUZeCGwUajGRW
|
||
|
"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."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"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",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
}
|
||
|
],
|
||
|
"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
|
||
|
}
|