吴恩达 神经网络和深度学习 观看笔记(2)

Basics of Neural Network Programming


1、Binary Classification

In a binary classification problem, the result is a discrete value output.
在一个二元分类问题中,结果是一个离散的值输出。

例如:帐户被黑客攻击(1)或妥协(0),-肿瘤的恶性(1)或良性(O)

Example: Cat vs Non-Cat
例子:猫对非猫

The goal is to train a classifier that the input is an image represented by a feature vector, x , and predictswhether the corresponding label y is 1 or0. ln this case, whether this is a cat image (1) or a non-cat image(0).
目标是训练一个分类器,使输入是由特征向量x表示的图像,并预测对应的标签y是1还是0。在这种情况下,无论是猫图像(1)还是非猫图像(0)。
在这里插入图片描述
An image is store in the computer in three separate matrices corresponding to the Red, Green, and Bluecolor channels of the image. The three matrices have the same size as the image, for example, theresolution of the cat image is 64 pixels X 64 pixels, the three matrices (RGB) are 64 x 64 each.
图像存储在计算机中与图像的红色、绿色和蓝光通道相对应的三个独立矩阵中。这三个矩阵具有与图像相同的大小,例如,CAT图像的卷积为64像素×64像素,三个矩阵(RGB)为每个矩阵64 x 64。

The value in a cell represents the pixel intensity which will be used to create a feature vector of n-dimension. In pattern recognition and machine learning, a feature vector represents an object, in thiscase, a cat or no cat.
单元格中的值表示像素强度,用于创建n维的特征向量。在模式识别和机器学习中,特征向量表示对象,在这种情况下,表示猫或没有猫。

To create a feature vector, x, the pixel intensity values will be "unroll”or "reshape”for each color.Thedimension of the input feature vector x is n,= 64x 64x 3 =12288.
要创建一个特征向量x,每个颜色的像素强度值将是“展开”或“重塑”,输入特征向量x的维数为n,=64x64x3=12288。

2、Logistic Regression

Logistic regression is a learning algorithm used in a supervised learning problem when the output y areall either zero or one.The goal of logistic regression is to minimize the error between its predictions andtraining data.
Logistic回归是一种用于监督学习问题的学习算法,当输出y为0或1时,其目标是最小化其预测和训练数据之间的误差。

Given an image represented by a feature vector x , the algorithm will evaluate the probability of a catbeing in that image.
给定一个由特征向量x表示的图像,该算法将评估该图像中发生捕捉的概率。

给定x,y=P(y=1|x),其中0≤y≤1

Logistic回归中使用的参数如下:
在这里插入图片描述
(wTx+b)是一个线性函数(ax+b),但由于我们正在寻找[0,1]之间的概率约束,所以使用了Sigmoid函数.函数在[0,1]之间有界,如图所示。当z很大时,sigmoid(z)趋于1,当z很小时,sigmoid(z)趋于0。

To train the parameters w and b, we need to define a cost function.Recap:
为了训练参数w和b,我们需要定义一个成本函数。
在这里插入图片描述
损失函数度量预测(y(0))与期望输出(Y0)之间的差异,换句话说,损失函数计算单个训练示例的误差。成本函数是整个训练集损失函数的平均值。我们将找到参数w和b,使总体成本函数最小化。

3、Gradient Descent

在这里插入图片描述
如图,成本函数是凸函数,成本函数衡量了参数w和b在训练集上的效果,现在要做的就是找到合适的w和b,使得J(w,b)最小,也就是图中最低点。

梯度下降算法:首先以他当前的所处的位置为基准,寻找这个位置最陡峭的地方,然后朝着下降方向走一步,然后又继续以当前位置为基准,再找最陡峭的地方,再走直到最后到达最低处。
在这里插入图片描述
如图,以二维为例,不断重复右边的公式,去寻找最低点。其中α表示学习率,控制每一次的迭代或下降的步长。后面的导数对w更新变化,迭代几次后应该就会达到最低点。

4、Computation Graph

在这里插入图片描述
如图,一个简单的图计算,蓝色的线,从左到右是计算J的值的流程图。主要分为三步,第一步u=bc,第二步v=a+u,最后一步J=3v。

在这里插入图片描述
如图,从右到左,计算流程图的导数,就是用的微积分的链式求导法则。

5、Logistic Regression Gradient Decent

在这里插入图片描述
逻辑回归梯度下降,在我看来就是利用上面第四点的图计算的反向传播,计算L对w1,w2和b的偏导数,利用多次迭代和梯度下降算法去最小化损失函数。图中假设有两个特征值x1,x2。

利用微积分计算很容易得出:dz=a-y,“dw1”=x1dz,“dw2”=x2dz,“db”=dz。当然这只是一个训练样本的损失函数。我们要求全体样本m的成本函数,还需要去取平均值。下图是用代码去实现,利用了两个for循环去迭代,第一个是遍历样本集m,第二个是特征值数量的累加。for循环的实现速度很慢,后续会有一种向量化的方法。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值