吴恩达第一课logistic Regress编程练习(学习笔记)
2017-11-07 21:31
369 查看
目标:利用logisitic Regression来预测图片是否有猫咪,即简单的二分类问题。
过程:初始化(向量输入,归一化),前向和反向传播,梯度下降,优化,预测,输出与可视化
初始化:1.明确输入集数量;测试集数量dim;
2.输入向量化n*n*nc;
A trick when you want to flatten a matrix X of shape (a,b,c,d) to a matrix X_flatten of shape (b ∗∗ c ∗∗ d, a) is to use:
X_flatten = X.reshape(X.shape[0], -1).T # X.T is the transpose of X
3.确定batch-size,输入归一化,压缩到【0,1】之间,便于计算。
4.初始化权值、偏差
w = np.zeros((dim, 1))
b = 0
前向与反向传播:
1.激活函数sigmoid
2.z = w.T * X + b
3.激活函数sigmoid
4.损失函数cost = -y*log(pred_y) -(1-y)*log(1-pred_y)
A = sigmoid(np.dot(w.T, X) + b) # compute activation
cost = -1/m * np.sum((Y*np.log(A) + (1-Y)*np.log(1-A))) # compute cost
反向传播梯度下降:根据链式法则有:损失函数对w的偏导为(a-y)*X,损失函数对b的偏导为(a-y)
dw = np.dot(X, (A - Y).T)/m
db = np.sum(A - Y)/m
优化(多次迭代):
w = w - learning_rate*dw
预测:
将新的输入与模型参数运算得到结果Pred-y,若大于0.5则输出1,反之输出0
模型整合:
1.初始化参数;2.正反向传播;3.优化;4.预测;5.打印显示与绘图可视化
超参数调试:
尝试不同的学习速率、batch-size和迭代次数,观察训练和测试准确率问题。
What you need to remember:
Common steps for pre-processing a new dataset are:
Figure out the dimensions and shapes of the problem (m_train, m_test, num_px, ...)
Reshape the datasets such that each example is now a vector of size (num_px * num_px * 3, 1)
"Standardize" the data
What to remember: You've implemented several functions that:
Initialize (w,b)Optimize the loss iteratively to learn parameters (w,b):
computing the cost and its gradient
updating the parameters using gradient descent
Use the learned (w,b) to predict the labels for a given set of examples
What to remember from this assignment:
Preprocessing the dataset is important.You implemented each function separately: initialize(), propagate(), optimize(). Then you built a model().Tuning the learning rate (which is an example of a "hyperparameter") can make a big difference to the algorithm. You will see more examples of this later in this course!
过程:初始化(向量输入,归一化),前向和反向传播,梯度下降,优化,预测,输出与可视化
初始化:1.明确输入集数量;测试集数量dim;
2.输入向量化n*n*nc;
A trick when you want to flatten a matrix X of shape (a,b,c,d) to a matrix X_flatten of shape (b ∗∗ c ∗∗ d, a) is to use:
X_flatten = X.reshape(X.shape[0], -1).T # X.T is the transpose of X
3.确定batch-size,输入归一化,压缩到【0,1】之间,便于计算。
4.初始化权值、偏差
w = np.zeros((dim, 1))
b = 0
前向与反向传播:
1.激活函数sigmoid
2.z = w.T * X + b
3.激活函数sigmoid
4.损失函数cost = -y*log(pred_y) -(1-y)*log(1-pred_y)
A = sigmoid(np.dot(w.T, X) + b) # compute activation
cost = -1/m * np.sum((Y*np.log(A) + (1-Y)*np.log(1-A))) # compute cost
反向传播梯度下降:根据链式法则有:损失函数对w的偏导为(a-y)*X,损失函数对b的偏导为(a-y)
dw = np.dot(X, (A - Y).T)/m
db = np.sum(A - Y)/m
优化(多次迭代):
w = w - learning_rate*dw
预测:
将新的输入与模型参数运算得到结果Pred-y,若大于0.5则输出1,反之输出0
模型整合:
1.初始化参数;2.正反向传播;3.优化;4.预测;5.打印显示与绘图可视化
超参数调试:
尝试不同的学习速率、batch-size和迭代次数,观察训练和测试准确率问题。
What you need to remember:
Common steps for pre-processing a new dataset are:
Figure out the dimensions and shapes of the problem (m_train, m_test, num_px, ...)
Reshape the datasets such that each example is now a vector of size (num_px * num_px * 3, 1)
"Standardize" the data
What to remember: You've implemented several functions that:
Initialize (w,b)Optimize the loss iteratively to learn parameters (w,b):
computing the cost and its gradient
updating the parameters using gradient descent
Use the learned (w,b) to predict the labels for a given set of examples
What to remember from this assignment:
Preprocessing the dataset is important.You implemented each function separately: initialize(), propagate(), optimize(). Then you built a model().Tuning the learning rate (which is an example of a "hyperparameter") can make a big difference to the algorithm. You will see more examples of this later in this course!
相关文章推荐
- 吴恩达Coursera深度学习(4-3)编程练习
- 原生JS实例练习——控制div属性—— JS学习笔记2015-8-4(第93天)
- 吴恩达深度学习笔记 course2 week3 测验
- 【Matlab学习笔记】(四)认识matlab的文件类型和简单练习
- 【吴恩达机器学习学习笔记01】监督学习和无监督学习介绍
- C++基础学习笔记----第一课补充(符号表)
- C++学习笔记:图形输出练习
- ANDROID基础学习笔记_1.1_练习
- Python学习笔记(3)-输出、输入、输出输入综合小练习
- scala学习笔记☞二:简单语法练习
- opengl学习笔记1:vs2013 nehe教程第一课 创建窗口
- 【OpenGL】nehe教程第一课学习笔记
- 吴恩达机器学习 学习笔记 之 三 线性代数基础
- Udacity 深度学习_学习笔记(1)TensorFlow练习环境安装
- 学习笔记(PHP php php-cgi php引擎 zend 引擎) [第一课]
- 【算法学习笔记】08.数据结构基础 二叉树初步练习1
- 网易云课堂吴恩达Andrew Ng深度学习笔记(三)
- java学习笔记之String类及其练习
- Java学习笔记(第一课)
- PL/SQL第一课(学习笔记)