Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ex4/Lecture 10 cs229-notes-deep_learning.pdf
Binary file not shown.
17 changes: 12 additions & 5 deletions ex4/PE4 - Learning Neural Networks (Exercises).ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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}$"
]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -670,7 +677,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -684,7 +691,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down