这里主要梳理一下作业的主要内容和思路,完整作业文件可参考:
https://github.com/pandenghuang/Andrew-Ng-Deep-Learning-notes/tree/master/assignments/C1W3
作业完整截图,参考本文结尾:作业完整截图。
Welcome to your week 3 programming assignment. It's time to build your first neural network, which will have a hidden layer. You will see a big difference between this model and the one you implemented using logistic regression.
You will learn how to:
...
Let's first import all the packages that you will need during this assignment.
First, let's get the dataset you will work on. The following code will load a "flower" 2-class dataset into variables X
and Y
.
...
Before building a full neural network, lets first see how logistic regression performs on this problem. You can use sklearn's built-in functions to do that. Run the code below to train a logistic regression classifier on the dataset.
...
Logistic regression did not work well on the "flower dataset". You are going to train a Neural Network with a single hidden layer.
数学原理:
...
Exercise: Implement the function initialize_parameters()
.
Instructions:
np.random.randn(a,b) * 0.01
to randomly initialize a matrix of shape (a,b).np.zeros((a,b))
to initialize a matrix of shape (a,b) with zeros....
Question: Implement forward_propagation()
.(前向传播)
Instructions:
sigmoid()
. It is built-in (imported) in the notebook.np.tanh()
. It is part of the numpy library.initialize_parameters()
) by using parameters[".."]
.cache
". The cache
will be given as an input to the backpropagation function....
成本函数:
后向传播:
...
选择合适的学习率并更新参数(即反向传播过程):
Question: Implement the update rule. Use gradient descent. You have to use (dW1, db1, dW2, db2) in order to update (W1, b1, W2, b2).
General gradient descent rule: =−∂∂θ=θ−α∂J∂θ where α is the learning rate and θ represents a parameter.
Illustration: The gradient descent algorithm with a good learning rate (converging) and a bad learning rate (diverging). Images courtesy of Adam Harley.
...
Question: Build your neural network model in nn_model()
.
Instructions: The neural network model has to use the previous functions in the right order.
...
Question: Use your model to predict by building predict(). Use forward propagation to predict results.
Reminder: predictions = ={activation > 0.5}={10if >0.5otherwiseyprediction=1{activation > 0.5}={1if activation>0.50otherwise
As an example, if you would like to set the entries of a matrix X to 0 and 1 based on a threshold you would do: X_new = (X > threshold)
作业完整截屏: