笔记内容都是记录对我有意义的方面,供我以后个人复习参考,打扰大家,还望海涵。
启动jupyter notebook的步骤,参考https://blog.youkuaiyun.com/xiewenrui1996/article/details/89765138:
1.打开Anaconda prompt
2.输入jupyter notebook 你的文件夹的位置
在运行Visualize the dataset using matplotlib 这部分代码时,发生了以下错误:
# Visualize the data:
plt.scatter(X[0, :], X[1, :], c=Y, s=40, cmap=plt.cm.Spectral);
ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 400, 'y' with size 400.
搜索发现解决办法,由于plt.scatter函数进行了改版,所以参数也发生的变动,参考该篇文章和文章下的评论:
将代码其中修改为:c=np.squeeze(Y)
# Visualize the data:
plt.scatter(X[0, :], X[1, :], c=np.squeeze(Y), s=40, cmap=plt.cm.Spectral);
plot_decision_boundary(model, X, y)函数,参考https://sophia0130.github.io/2018/06/25/Deep-Learning-%E5%90%B4%E6%81%A9%E8%BE%BE-%E4%BD%9C%E4%B8%9A%E2%80%94%E2%80%94%E5%85%B3%E4%BA%8Eplot-decision-boundary-%E5%87%BD%E6%95%B0%E7%9A%84%E7%90%86%E8%A7%A3/ :
plot_decision_boundary(lambda x: predict(parameters, x.T), X, Y)
其中lambda函数表示的是匿名函数,而x则代表函数的参数,即在plot_decision_boundary()这个函数中只需要输入x的值,parameters是保持不变的。
enumerate()函数,参考链接:https://www.runoob.com/python/python-func-enumerate.html
enumerate(sequence, [start=0]) 一般用于for循环中
参数解释:
squence表示一个序列
start表示起始位置
该函数返回的是序列中数据的下标以及数据,例如
hidden_layer_sizes = ['a', "b", 'c', 'd', 'e', 'f', 'g']
list(enumerate(hidden_layer_sizes))
[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f'), (6, 'g')]
总结:
1. Define the neural network structure ( # of input units, # of hidden units, etc).
2. Initialize the model's parameters
3. Loop:
- Implement forward propagation
- Compute loss
- Implement backward propagation to get the gradients
- Update parameters (gradient descent)
4. Predict: using update parameters to predict data
在nn_model()函数中输出的结果与给出的结果有一点差别,查询答案是可能由于32位或者64位机运算结果有差异,参考https://www.mscto.com/base/296151.html