资源简介
吴恩达深度学习Python完整代码,包含无正则化、L2正则化及Dropout三种情况并包含绘制边缘曲线,跑通视频已在压缩包,更加直观的证明本程序跑通并实现哪些功能
代码片段和文件信息
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 datasets\data.mat
文件 19889 2018-12-25 11:16 Regularization_French Football_3NN.py
- 上一篇:Python课件教程
- 下一篇:K-SVD稀疏字典学习去噪
相关资源
- Python课件教程
- python官方文档中文汉化版
-
Python and xm
l - 《机器学习实战》Python3代码
- 段力辉大神翻译原版OpenCV-Python
- Twisted-18.9.0-cp37-cp37m-win_amd64.whl
- pygame for python 3.6 64位
- Python基础教程第3版中英文源码.rar
- Pythonocc官方未默认安装的extend文件夹
- 书城购物开发web项目
- 《自学是门手艺》李笑来-PDF
- 坦克大战.zip
- python数据结构与算法中文版.zip
- Python爬虫入门到实战 (二花) PDF版
- 模仿瓜子二手车的python网站
- Python贪吃蛇源码+背景音乐+中文字体
- Python3学习笔记
- Python数据挖掘和实战课程源码
- Python编程快速上手 让繁琐工作自动化
- 卷积神经网络python
- Python3.7.2中文文档-标准库-通用操作系
- Python3.7.2中文文档-标准库-Python数据类
- pygame-1.9.6-cp36-cp36m-win_amd64.whl
- Introduction to Data Science - A Python Approa
- python网络爬虫爬取整个网页
- Deep Learning With Python - Jason Brownlee
- Long Short Terms Memory Networks with Python J
- 破解wifi密码python小程序
- python之外星人入侵完整版程序源码
- python之外星人入侵
评论
共有 条评论