diff --git a/ex4/Lecture 10 cs229-notes-deep_learning.pdf b/ex4/Lecture 10 cs229-notes-deep_learning.pdf new file mode 100644 index 0000000..3bb3629 Binary files /dev/null and b/ex4/Lecture 10 cs229-notes-deep_learning.pdf differ diff --git a/ex4/PE4 - Learning Neural Networks (Exercises).ipynb b/ex4/PE4 - Learning Neural Networks (Exercises).ipynb index 0480aae..67304d8 100644 --- a/ex4/PE4 - Learning Neural Networks (Exercises).ipynb +++ b/ex4/PE4 - Learning Neural Networks (Exercises).ipynb @@ -35,7 +35,7 @@ "\n", "Load the data and view some samples in the same way as [ex3](https://github.com/rickwierenga/CS229-Python/tree/master/ex3).\n", "\n", - "Remember the output of a neural network: $h_\\Theta(x) \\in \\mathbb{R}^K$. We want y to be a 2 dimensional vector in the form that are network should output. For example, we would represent the output 1 as:\n", + "Remember the output of a neural network: $h_\\Theta(x) \\in \\mathbb{R}^K$. We want y to be a K dimensional vector in the form that are network should output. For example, we would represent the output 1 as:\n", "\n", "$\\begin{bmatrix}0\\\\1\\\\0\\\\0\\\\0\\\\0\\\\0\\\\0\\\\0\\\\0\\end{bmatrix}$" ] @@ -68,6 +68,13 @@ "y = data[\"y\"]\n", "y = y.reshape(len(y))\n", "\n", + "# ----------NOTE-----------------\n", + "# X should have training examples in columns, not rows\n", + "# Read also end of page 7 of 'Lecture 10 cs229-notes-deep_learning.pdf', where it says the same thing \n", + "# And also the function 'forward' assumes training examples are in columns\n", + "X = X.T\n", + "\n", + "\n", "# Initialize some useful variables\n", "m, n = X.shape\n", "input_layer_size = 400\n", @@ -112,7 +119,7 @@ "\n", "# get 100 random images from the dataset\n", "num_samples = 100\n", - "samples = random.sample(list(X), num_samples)\n", + "samples = random.sample(list(X.T), num_samples)\n", "display_img = Image.new('RGB', (200, 200))\n", "\n", "# loop over the images, turn them into a PIL image\n", @@ -168,7 +175,7 @@ " return 1 / (1 + np.exp(-z))\n", "\n", "def add_bias(X):\n", - " m = len(X)\n", + " m = X.shape[1]\n", " bias = np.ones(m)\n", " X = np.vstack((bias, X.T)).T\n", " return X\n", @@ -670,7 +677,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -684,7 +691,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.9.7" } }, "nbformat": 4,