学习笔记:Deep Learning Specialization: Neural Networks and Deep Learning - Python basics with Numpy
终于搞定了怎么上Coursera的问题,然后就开始修吴恩达的Deep Learning Specialization了,一个月$49,看在钱的份上还是要好好学习!
其实之前是有学过Andrew的Machine Learning课的,在课程的最后一周就是神经网络,当时还是用Matlab/Octave做作业,神经网络里的各种下标真是要把我整崩溃了。同样的东西用矩阵运算的库来做不仅简单很多,效率还更高。
需要了解的东西并不需要太多,简单了解一些基本概念做作业是足够了。
Sigmoid函数 1 / ( 1 + e − x ) 1/(1 + e^{-x}) 1/(1+e−x)
import math
def basic_sigmoid(x):
return 1 / (1 + math.exp(-x))
x
=
(
x
1
,
x
2
,
.
.
.
,
x
n
)
x = (x_1, x_2, ..., x_n)
x=(x1,x2,...,xn) 将exp
函数应用至每一个元素
n
p
.
e
x
p
(
x
)
=
(
e
x
1
,
e
x
2
,
.
.
.
,
e
x
n
)
np.exp(x) = (e^{x_1}, e^{x_2}, ..., e^{x_n})
np.exp(x)=(ex1,ex2,...,exn)
import numpy as pn
def sigmoid(x):
return 1 / (1 + np.exp(-x))
Reshape
img.reshape((32 * 32 * 3, 1))
Broadcasting
a = np.random.randn(3, 2)
b = np.random.randn(3, 1)
a + b # (3, 2)
a + 1 # (3, 2)
Vectorization
Python的循环效率非常低,矩阵运算应该尽可能使用Numpy的矩阵计算模块。
np.dot: 矩阵乘法
np.multiply/*: element-wise乘法