吴恩达深度学习超参数调制完整程序无正则化、L2正则化及Dropout
吴恩达深度学习Python完整代码,包含无正则化、L2正则化及Dropout三种情况并包含绘制边缘曲线,跑通视频已在压缩包,更加直观的证明本程序跑通并实现哪些功能
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2545837 2018-12-25 14:16 20181215Python-无正则化、L2正则化与Dropout.mp4
目录 0 2018-12-25 14:29 datasets
文件 6038 2017-09-03 18:02 datasetsdata.mat
文件 19889 2018-12-25 11:16 Regularization_French Football_3NN.py
import matplotlib.pyplot as plt
import h5py
import sklearn
import sklearn.datasets
import sklearn.linear_model
import scipy.io
import numpy as np
np.seterr(divide=‘ignore‘ invalid=‘ignore‘)
plt.rcParams[‘figure.figsize‘] = (7.0 4.0) # set default size of plots
plt.rcParams[‘image.interpolation‘] = ‘nearest‘
plt.rcParams[‘image.cmap‘] = ‘gray‘
def load_2D_dataset():
data = scipy.io.loadmat(‘datasets/data.mat‘)
train_X = data[‘X‘].T
train_Y = data[‘y‘].T
test_X = data[‘Xval‘].T
test_Y = data[‘yval‘].T
plt.scatter(train_X[0 :] train_X[1 :] c=train_Y[0 :] s=40 cmap=plt.cm.Spectral);
plt.show()
return train_X train_Y test_X test_Y
def print_size():
train_X_size = print(train_X.shape) #(2 211)
train_Y_size = print(train_Y.shape) #(1 211)
test_X_size = print(test_X.shape) #(2 200)
test_Y_size = print(test_Y.shape) #(1 200)
return train_X_size train_Y_size test_X_size test_Y_size
#train_X train_Y test_X test_Y = load_2D_dataset()
#train_X_size train_Y_size test_X_size test_Y_size = print_size()
def sigmoid(x):
“““
Compute the sigmoid of x
Arguments:
x -- A scalar or numpy array of any size.
Return:
s -- sigmoid(x)
“““
s = 1 / (1 + np.exp(-x))
return s
def relu(x):
“““
Compute the relu of x
Arguments:
x -- A scalar or numpy array of any size.
Return:
s -- relu(x)
“““
s = np.maximum(0 x)
return s
#类似He et al Initialize
def initialize_parameters(layer_dims):
“““
Arguments:
layer_dims -- python array (list) containing the dimensions of each layer in our network
Returns:
parameters -- python dictionary containing your parameters “W1“ “b1“ ... “WL“ “bL“:
W1 -- weight matrix of shape (layer_dims[l] layer_dims[l-1])
b1 -- bias vector of shape (layer_dims[l] 1)
Wl -- weight matrix of shape (layer_dims[l-1] layer_dims[l])
bl -- bias vector of shape (1 layer_dims[l])
Tips:
- For example: the layer_dims for the “Planar Data classification model“ would have been [221].
This means W1‘s shape was (22) b1 was (12) W2 was (21) and b2 was (11). Now you have to generalize it!
- In the for loop use parameters[‘W‘ + str(l)] to access Wl where l is the iterative integer.
“““
np.random.seed(3)
parameters = {}
L = len(layer_dims) # number of layers in the network
for l in range(1 L):
parameters[‘W‘ + str(l)] = np.random.randn(layer_dims[l] layer_dims[l - 1]) / np.sqrt(layer_dims[l - 1])
parameters[‘b‘ + str(l)] = np.zeros((layer_dims[l] 1))
#assert (parameters[‘W‘ + str(l)].shape == layer_dims[l] layer_dims[l - 1])
#assert (parameters[‘W‘ + str(l)].shape == layer_dims[l] 1)
return parameters
def forward_propagation(X
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2545837 2018-12-25 14:16 20181215Python-无正则化、L2正则化与Dropout.mp4
目录 0 2018-12-25 14:29 datasets
文件 6038 2017-09-03 18:02 datasetsdata.mat
文件 19889 2018-12-25 11:16 Regularization_French Football_3NN.py
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)