Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

时间:2022-05-15 07:09:31

总结

一、处理数据

1.1 向量化(vectorization)

  • (height, width, 3) ===> 展开shape为(heigh*width*3, m)的向量

1.2 特征归一化(Normalization)

  • 一般数据,使用标准化(Standardlization), z(i) = (x(i) - mean) / delta,mean与delta代表X的均值和标准差,最终特征处于【-1,1】区间
  • 对于图片,可直接使用 Min-Max Scaliing,即将每个特征直接除以 255,使值处于 【-1,1】之间

二、初始化参数

  • 一般将w 和 b随机初始化。这里用逻辑回归思想,设为0

三、梯度下降(Gradient descent)

  • 根据w, b和训练集,来训练数据。需要设定迭代次数与learning rate α

3.1 计算代价函数(前向传播)

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

# 激活函数
A = sigmoid(w.T.dot(X) + b)
# 代价函数
cost = -np.sum(Y * np.log(A) + (1-Y) * np.log(1 - A)) / m

3.2 反向传播计算梯度

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

dw = X.dot((A - Y).T) / m
db = np.sum(A - Y) / m

3.3 更新参数(w, b)

w = w - learning_rate * dw
b = b - learning_rate * db

四、预测测试集

  • 用训练好的模型(训练后的参数w, b),对测试集使用 y_hat = sigmoid(wx + b),计算预测结果的概率( np.round(y_hat)))

详细内容

逻辑回归

(1)  逻辑回归的代价函数(Logistic Regression Cost Function )

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

(2) 梯度下降法(Gradient Descent )

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

在你测试集上,通过最小化代价函数(成本函数)J(w,b)来训练的参数 w 和 b

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)Neural Networks and Deep Learning 课程笔记(第二周)神经网络的编程基础 (Basics of Neural Network programming)

假定代价函数(成本函数)J(