Planar data classification with one hidden layer
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:
- Implement a 2-class classification neural network with a single hidden layer
- Use units with a non-linear activation function, such as tanh
- Compute the cross entropy loss
- Implement forward and backward propagation
这次主要是构建一个one hidden layer的简单神经网络,并且完成数据分类的工作,下面分成几点来进行说明。
1)本次作业的坑点以及修改调试过程(是十分的坑啊)
2)模型的构建过程
3)测试结果
1.作业的坑点
从数据的导入开始说起,导入必要的packages
# Package imports
import numpy as np
import matplotlib.pyplot as plt
from testCases import *
import sklearn
import sklearn.datasets
import sklearn.linear_model
from planar_utils import plot_decision_boundary, sigmoid, load_planar_dataset, load_extra_datasets
%matplotlib inline
np.random.seed(1) # set a seed so that the results are consistent
#load date-set
X, Y = load_planar_dataset()
#visualize the date
plt.scatter(X[0, :], X[1, :], c=np.squeeze(Y), s=40, cmap=plt.cm.Spectral);
这边在原来给的代码中,为了可视化我们的数据集,调用了plt.scatter。原来吴恩达给的代码是c = Y,如果直接运行的话会出现如下错误
因为一开始我们Y的维度是(1,400)而在使用绘图函数的时候,需要进行降维度处理,去除冗余的维度。通常算法的结果是可以表示