From b8e533fe27fb27edfb054aa9e218b4825e1a649a Mon Sep 17 00:00:00 2001 From: wassname Date: Tue, 3 Nov 2020 03:43:24 +0000 Subject: [PATCH] solver, typos --- .../Intro_to_NN_Part_1.ipynb | 173 +++++++++--------- .../Intro_to_NN_Part_1.py | 21 ++- 2 files changed, 103 insertions(+), 91 deletions(-) diff --git a/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.ipynb b/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.ipynb index 3d47965..72fb2ca 100644 --- a/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.ipynb +++ b/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.ipynb @@ -5,8 +5,8 @@ "execution_count": 1, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T03:43:21.758022Z", - "start_time": "2020-10-02T03:43:21.381209Z" + "end_time": "2020-11-03T03:15:43.717193Z", + "start_time": "2020-11-03T03:15:39.639383Z" } }, "outputs": [], @@ -52,11 +52,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:09:51.027603Z", - "start_time": "2020-10-02T04:09:51.015951Z" + "end_time": "2020-11-03T03:15:43.722821Z", + "start_time": "2020-11-03T03:15:43.718685Z" } }, "outputs": [ @@ -69,7 +69,7 @@ "" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -147,7 +147,10 @@ " \n", "There are visualisation of many of these optimisers here: https://github.com/3springs/viz_torch_optim\n", "\n", - "Notice that they sometimes get caught in local minima. Also not that this is a 3d space, but most backprop is in a higher dimensional space that has less change to get stuck.\n", + "Notice that they sometimes get caught in local minima. Also note that this example shows a 2d space + error, but most machine learning is in a higher dimensional space that has less chance to get stuck. \n", + "\n", + "\n", + "\n", "\n", "\n", " \n", @@ -178,31 +181,35 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:29:35.076666Z", - "start_time": "2020-10-02T04:29:35.070121Z" + "end_time": "2020-11-03T03:16:38.498593Z", + "start_time": "2020-11-03T03:16:38.494913Z" } }, "outputs": [ { "data": { "text/html": [ - "" + "\n", + " \"https://playground.tensorflow.org\"\n", + " " ], "text/plain": [ "" ] }, - "execution_count": 4, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HTML(\n", - " ''\n", + " '''\n", + " \"https://playground.tensorflow.org\"\n", + " '''\n", ")" ] }, @@ -223,11 +230,11 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:46:46.608184Z", - "start_time": "2020-10-02T04:46:45.713569Z" + "end_time": "2020-11-03T03:32:15.190482Z", + "start_time": "2020-11-03T03:32:15.187619Z" } }, "outputs": [], @@ -242,11 +249,11 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:47:28.355772Z", - "start_time": "2020-10-02T04:47:28.080954Z" + "end_time": "2020-11-03T03:33:37.361306Z", + "start_time": "2020-11-03T03:33:37.184711Z" } }, "outputs": [ @@ -254,12 +261,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "Target: 1\n" + "Target: 0\n" ] }, { "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAL4AAADCCAYAAAD3lHgnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAJBUlEQVR4nO3d34td5RnF8e/qqLRV20CTluAkHS8kIIUmJQSKpaaKJVZJctGLBBRbCl5ZDC2I9sr+A2IuSkFiGsHU0PqDiKTagI5WaK1JHFuTaJmGKSbYJqEkRi8qiU8vzgmOZpK8A/vd++w86w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EtJRffUko7c3v33Xc3ul6N2dOpqWavJ/RhU+u2+IhvKbn4lpKLbym5+JaSi28pufiWUslWQJdI2jHn631Jt7URzqyWkh1R3gYuA5A0BvyNwQZwZr212FOdK4E9EfHXGmHM2rLY4m8AHq4RxKxNxcUfDqFcCyz42dUeNrc+WcwR/ypge0T8Y6Hf9LC59cliir8Rn+bYaaL0IwTPBtYBj9eNY9aO0pnbfwNfqJzFrDW+c2spufiWkotvKbn4lpKLbykpIppfVDoElLyfZzlwuPEAzRr1jKOeD7rN+OWImHdHtUrxS0majoiR/mjCUc846vlgNDP6VMdScvEtpa6Lf1/Hf36JUc846vlgBDN2eo5v1pWuj/hmneik+JLWS3pb0m5J8zaS65qklZJeGG5mvVPSrV1nOhFJY8PdKJ/qOstCRnVz8NZPdYYD639h8DbnWeBVYGNEjMy+WpLOB86PiO2SzgVmgO+MUsZjJP2IwW41SyLimq7zHE/SA8DvImLzsc3BI+K9rnN1ccRfA+yOiL3DzaIfAa7rIMcJRcS7EbF9+P0HwC7ggm5TzSdpHLga2Nx1loXM2Rz8fhhsDj4KpYduin8B8M6cx7OMYKmOkTQBrAJeOfkrO3EvcDvwSddBTqBoc/AudFF8LfDcSF5aknQO8BhwW0S833WeuSRdAxyMiFH+0PuizcG70EXxZ4GVcx6PAwc6yHFSks5kUPqHImIURy7XAtdK2s/gdPEKSQ92G2mekd0cvIvivwpcLOmi4X92NgBPdpDjhCSJwXnproi4p+s8C4mIOyNiPCImGPwdPh8RN3Yc61NGeXPw1rcCioijkm4BngXGgC0RsbPtHKewFrgJ+LOkHcPnfhIRT3eYqa9GcnNw37m1lHzn1lJy8S0lF99ScvEtJRffUnLxLSUX31Jy8S2l/wKEGLL71GHc4QAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] @@ -273,7 +280,7 @@ "source": [ "# Load the digits dataset\n", "digits = datasets.load_digits()\n", - "idx = 200\n", + "idx = 0\n", "# Let's first see one of the images\n", "plt.figure(1, figsize=(3, 3))\n", "print('Target: {}'.format(digits.target[idx]))\n", @@ -283,11 +290,11 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:48:39.543564Z", - "start_time": "2020-10-02T04:48:39.532137Z" + "end_time": "2020-11-03T03:33:38.201997Z", + "start_time": "2020-11-03T03:33:38.196483Z" } }, "outputs": [ @@ -327,11 +334,11 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:48:42.832778Z", - "start_time": "2020-10-02T04:48:42.827691Z" + "end_time": "2020-11-03T03:34:21.111474Z", + "start_time": "2020-11-03T03:34:21.108186Z" } }, "outputs": [ @@ -341,7 +348,7 @@ "(1797, 8, 8)" ] }, - "execution_count": 11, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -359,11 +366,11 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:48:56.654881Z", - "start_time": "2020-10-02T04:48:56.518236Z" + "end_time": "2020-11-03T03:34:23.333821Z", + "start_time": "2020-11-03T03:34:23.216750Z" } }, "outputs": [], @@ -382,11 +389,11 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:48:59.143021Z", - "start_time": "2020-10-02T04:48:59.139191Z" + "end_time": "2020-11-03T03:34:24.429176Z", + "start_time": "2020-11-03T03:34:24.425825Z" } }, "outputs": [ @@ -413,11 +420,11 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:49:23.963782Z", - "start_time": "2020-10-02T04:49:23.958448Z" + "end_time": "2020-11-03T03:34:26.871830Z", + "start_time": "2020-11-03T03:34:26.868317Z" } }, "outputs": [], @@ -431,8 +438,8 @@ "execution_count": 16, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:49:45.925842Z", - "start_time": "2020-10-02T04:49:45.923092Z" + "end_time": "2020-11-03T03:34:27.091754Z", + "start_time": "2020-11-03T03:34:27.089181Z" } }, "outputs": [ @@ -460,8 +467,8 @@ "execution_count": 17, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:50:47.914040Z", - "start_time": "2020-10-02T04:50:47.905964Z" + "end_time": "2020-11-03T03:34:29.522204Z", + "start_time": "2020-11-03T03:34:29.518174Z" } }, "outputs": [ @@ -487,8 +494,8 @@ "execution_count": 18, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:51:10.641411Z", - "start_time": "2020-10-02T04:51:10.636857Z" + "end_time": "2020-11-03T03:34:30.392047Z", + "start_time": "2020-11-03T03:34:30.388479Z" } }, "outputs": [], @@ -507,17 +514,17 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 27, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:52:18.384672Z", - "start_time": "2020-10-02T04:52:18.379033Z" + "end_time": "2020-11-03T03:39:03.636513Z", + "start_time": "2020-11-03T03:39:03.632941Z" } }, "outputs": [], "source": [ "# Learning rate is by default 0.001, we will use the default value\n", - "def train(X_train, y_train, hidden_layers, activation):\n", + "def train(X_train, y_train, hidden_layers, activation, solver):\n", " clf = MLPClassifier(\n", " hidden_layer_sizes=hidden_layers,\n", " activation=activation,\n", @@ -530,11 +537,11 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 28, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:53:40.587883Z", - "start_time": "2020-10-02T04:53:40.254866Z" + "end_time": "2020-11-03T03:39:04.508245Z", + "start_time": "2020-11-03T03:39:04.156003Z" } }, "outputs": [ @@ -544,7 +551,7 @@ "0.2833333333333333" ] }, - "execution_count": 21, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -555,7 +562,7 @@ "solver = \"sgd\" # Stochastic Gradient Descent optimizer\n", "\n", "# Let's train the model using our custom hyperparameters\n", - "clf = train(X_train, y_train, hidden_layers, activation)\n", + "clf = train(X_train, y_train, hidden_layers, activation, solver)\n", "# Let's evaluate the accuracy of the model using the test data\n", "clf.score(X_test, y_test)" ] @@ -569,11 +576,11 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 29, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T04:55:30.082067Z", - "start_time": "2020-10-02T04:55:29.732071Z" + "end_time": "2020-11-03T03:39:15.060053Z", + "start_time": "2020-11-03T03:39:14.655024Z" } }, "outputs": [ @@ -583,7 +590,7 @@ "0.7148148148148148" ] }, - "execution_count": 23, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -592,7 +599,7 @@ "hidden_layers = 10\n", "\n", "# Let's train the model using our custom hyperparameters\n", - "clf = train(X_train, y_train, hidden_layers, activation)\n", + "clf = train(X_train, y_train, hidden_layers, activation, solver)\n", "# Let's evaluate the accuracy of the model using the test data\n", "clf.score(X_test, y_test)" ] @@ -685,11 +692,11 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 22, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T05:09:54.894210Z", - "start_time": "2020-10-02T05:09:54.221291Z" + "end_time": "2020-11-03T03:34:42.059502Z", + "start_time": "2020-11-03T03:34:34.291609Z" } }, "outputs": [ @@ -697,11 +704,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([[0.5462, 0.8865, 0.7696],\n", - " [0.5014, 0.1381, 0.8770],\n", - " [0.1166, 0.8139, 0.0961],\n", - " [0.2721, 0.1751, 0.3259],\n", - " [0.6099, 0.8060, 0.8540]])\n" + "tensor([[3.0750e-01, 1.7755e-01, 4.9070e-01],\n", + " [1.6806e-01, 4.2704e-01, 1.8621e-01],\n", + " [3.7235e-04, 2.2258e-01, 8.0673e-01],\n", + " [6.3377e-01, 1.4874e-02, 2.7018e-01],\n", + " [4.9504e-01, 4.3858e-01, 1.6609e-02]])\n" ] } ], @@ -723,11 +730,11 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 23, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T05:10:14.355417Z", - "start_time": "2020-10-02T05:10:14.351794Z" + "end_time": "2020-11-03T03:34:42.076298Z", + "start_time": "2020-11-03T03:34:42.061886Z" } }, "outputs": [ @@ -753,11 +760,11 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 24, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T05:11:15.672176Z", - "start_time": "2020-10-02T05:11:15.668138Z" + "end_time": "2020-11-03T03:34:42.126772Z", + "start_time": "2020-11-03T03:34:42.077926Z" } }, "outputs": [ @@ -765,7 +772,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([0.3350, 0.2602])\n" + "tensor([ 1.4927, -0.8089])\n" ] } ], @@ -776,11 +783,11 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 25, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T05:11:19.069141Z", - "start_time": "2020-10-02T05:11:19.063639Z" + "end_time": "2020-11-03T03:34:42.172765Z", + "start_time": "2020-11-03T03:34:42.128057Z" } }, "outputs": [ @@ -813,11 +820,11 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 26, "metadata": { "ExecuteTime": { - "end_time": "2020-10-02T05:11:27.912563Z", - "start_time": "2020-10-02T05:11:27.907824Z" + "end_time": "2020-11-03T03:34:42.220396Z", + "start_time": "2020-11-03T03:34:42.174080Z" } }, "outputs": [ @@ -825,7 +832,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "tensor([0.3350, 0.2602]) tensor([0.1107, 0.5595])\n" + "tensor([ 1.4927, -0.8089]) tensor([0.0388, 0.2797])\n" ] } ], @@ -1091,9 +1098,9 @@ "formats": "ipynb,py" }, "kernelspec": { - "display_name": "Python 3", + "display_name": "py37_pytorch", "language": "python", - "name": "python3" + "name": "conda-env-py37_pytorch-py" }, "language_info": { "codemirror_mode": { @@ -1105,7 +1112,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.7.0" }, "toc": { "base_numbering": 1, diff --git a/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.py b/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.py index ef9d1f1..ec423d6 100644 --- a/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.py +++ b/notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.py @@ -9,9 +9,9 @@ # format_version: '1.5' # jupytext_version: 1.6.0 # kernelspec: -# display_name: Python 3 +# display_name: py37_pytorch # language: python -# name: python3 +# name: conda-env-py37_pytorch-py # --- from IPython.display import HTML @@ -109,7 +109,10 @@ # # There are visualisation of many of these optimisers here: https://github.com/3springs/viz_torch_optim # -# Notice that they sometimes get caught in local minima. Also not that this is a 3d space, but most backprop is in a higher dimensional space that has less change to get stuck. +# Notice that they sometimes get caught in local minima. Also note that this example shows a 2d space + error, but most machine learning is in a higher dimensional space that has less chance to get stuck. +# +# +# # # # @@ -139,7 +142,9 @@ # HTML( - '' + ''' + "https://playground.tensorflow.org" + ''' ) # @@ -161,7 +166,7 @@ # Load the digits dataset digits = datasets.load_digits() -idx = 200 +idx = 0 # Let's first see one of the images plt.figure(1, figsize=(3, 3)) print('Target: {}'.format(digits.target[idx])) @@ -210,7 +215,7 @@ # Now let's pick some hyperparameters before the training. # Learning rate is by default 0.001, we will use the default value -def train(X_train, y_train, hidden_layers, activation): +def train(X_train, y_train, hidden_layers, activation, solver): clf = MLPClassifier( hidden_layer_sizes=hidden_layers, activation=activation, @@ -227,7 +232,7 @@ def train(X_train, y_train, hidden_layers, activation): solver = "sgd" # Stochastic Gradient Descent optimizer # Let's train the model using our custom hyperparameters -clf = train(X_train, y_train, hidden_layers, activation) +clf = train(X_train, y_train, hidden_layers, activation, solver) # Let's evaluate the accuracy of the model using the test data clf.score(X_test, y_test) # - @@ -238,7 +243,7 @@ def train(X_train, y_train, hidden_layers, activation): hidden_layers = 10 # Let's train the model using our custom hyperparameters -clf = train(X_train, y_train, hidden_layers, activation) +clf = train(X_train, y_train, hidden_layers, activation, solver) # Let's evaluate the accuracy of the model using the test data clf.score(X_test, y_test) # -