Coursera | Andrew Ng (01-week-2-2.9)—Logistic 回归中的梯度下降法

该系列仅在原课程基础上部分知识点添加个人学习笔记,或相关推导补充等。如有错误,还请批评指教。在学习了 Andrew Ng 课程的基础上,为了更方便的查阅复习,将其整理成文字。因本人一直在学习英语,所以该系列以英文为主,同时也建议读者以英文为主,中文辅助,以便后期进阶时,为学习相关领域的学术论文做铺垫。- ZJ

Coursera 课程 |deeplearning.ai |网易云课堂


转载请注明作者和出处:ZJ 微信公众号-「SelfImprovementLab」

知乎https://zhuanlan.zhihu.com/c_147249273

CSDNhttp://blog.csdn.net/JUNJUN_ZHAO/article/details/78913044


2.9 logistic 回归中的梯度下降法
Logistic Regression Gradient Descent

(字幕来源:网易云课堂)

这里写图片描述

welcome back, in this video we’ll talk about how to compute derivatives for you,to implement gradient descent for logistic regression.the key take aways will be what you need to implement that are the key equations you need,in order to implement gradient descent for logistic regression.but in this video I want to do this computation,using the computation graph.I have to admit using the computation graph is a little bit of an overkill for deriving gradient descent for logistic regression.but I want to start explaining things this way to get you familiar with these ideas.so that hopefully you’ll make a bit more sense when we talk about full fledged neural networks.

欢迎回来,在本节我们将讨论怎样计算偏导数,来实现 logistic 回归的梯度下降法,它的核心关键点是 其中有几个重要的公式,用来实现 logistic 回归的梯度下降法,但是在本节视频中 我将使用导数流程图,来计算梯度,必须承认,用导数流程图来计算 logistic 回归的梯度下降 有点大材小用了,但是我认为以这种方式来讲解,可以更好地理解梯度下降,从而在讨论神经网络时,可以更深刻而全面地理解神经网络。

so let’s dive into gradient descent for logistic regression to recap we had set up logistic regression as follows your predictions y hat is defined as follows,where z is that and if we focus on just one example for now,then the loss or respect to that one example is defined as follows,where a is the output of the logistic regression,and y is the ground truth label,so let’s write this out as a computation graph,and for this example let’s say we have only two features x1 and x2.so in order to compute z,we’ll need to input w1 w2 and b,in addition to the feature values x1 x2

接下来开始学习 logistic 回归的梯度下降法, 回想一下 logistic 回归的公式, y^ 定义如下 y^ 的定义是这样的, z 则是这样 现在只考虑单个样本的情况,关于该样本的损失函数,定义如下,其中a logistic 回归的输出, y 是样本的基本真值标签值,现在写出该样本的偏导数流程图,假设样本只有两个 特征x1 x2 ,为了计算 z ,我们需要输入参数w1 w2 b ,还有样本特征值x1 x2

so these things in a computation graph get used to compute z which is w1 x1 plus w2 x2 plus b.draw a rectangle box around that and then we compute y hat,or a equals Sigma of Z that’s the next step in a computation graph,and then finally we compute L(a,y),and I won’t copy the formula again,so in logistic regression what we want to do,is to modify the parameters w and b,in order to reduce this loss,we’ve described before propagation steps,of how you actually compute the loss on a single training example.

因此用来计算 z 的 偏导数计算公式,z等于 w1x1+w2x2+b ,如图用矩形括起来了 然后计算 y^ ,即 a 等于sigma(z) 也就是偏导数流程图的下一步,最后计算 L(a,y) ,我不会再写出这个公式了,因此在 logistic 回归中 我们需要做的是,变换参数 w b 的值,来最小化损失函数, 在前面我们已经前向传播步骤,在单个训练样本上计算损失函数。

now let’s talk about how you can go backwards to talk to compute the derivatives,here’s the cleaned up version of the diagram,because what we want to do is compute derivatives respect to this loss,the first thing we want to do we’re going backwards is to compute the derivative of this loss with respect to the script over there,with respect to this variable a,and so in the code,you know you just use da right to denote this variable,and it turns out that if you are familiar with calculus,you can show that this ends up being negative y over a,plus one minus y over one minus a,and the way you do that is you take the formula,for the loss and if you are familiar with calculus,you can compute the derivative with respect to the variable lowercase a and you get this formula.

现在让我们来 讨论怎样向后计算偏导数,这是整洁版本的图,要想计算损失函数L的导数,首先我们要,向前一步 先计算损失函数的导数,这里有个标记,关于变量 a 的导数,在代码中,你只需要使用da来表示这个变量,事实上 如果你熟悉微积分,这个结果是 y/a ,加上 (1y)/(1a) ,损失函数导数的计算公式,就是这样 如果你熟悉微积分,你计算的关于变量 a 的导数,就是这个式子。

这里写图片描述

but if you’re not familiar of calculus,don’t worry about it,we’ll provide the derivative formulas you need,through out this course so if you are a expert in calculus,you’ll encourage you to look up the formula for the loss from their previous slide,and try to get director for respect to a using you know calculus,but if you don’t know enough calculus to do that,don’t worry about it,now having computed this quantity or da,the derivative of your final output variable respect to a,you can then go backwards and it turns out that you can show dz,which this is the Python code variable name,this is going to be you know the derivative of the loss,with respect to 关于 z or for L you can really write,the loss including a and y explicitly as parameters,or not right give either type of notation is equally acceptable they can show that,this is equal to a minus y,just a couple comments only for those of you did a experts in calculus.

如果你不熟悉微积分,也不必太担心,我们会列出本课程涉及的所有求导公式,因此 如果你非常熟悉微积分,我们鼓励你,通过上一张幻灯片中的损失函数公式,使用微积分 直接求出变量a的导数,如果你不太了解微积分,也不用太担心,现在计算出 da ,最终结果关于变量 a 的导数,现在可以再向后一步 计算dz dz 是代码中的变量名, dz 是损失函数关于 z 的导数,对于dL,可以写成 dL(a,y) ,两种形式都可以,都是等价的,结果等于 ay ,给熟悉微积分的人解释一下。

if you’re not explain calculus,don’t worry about it,but it turns out that this right dL dz,this can be expressed as dL da times,da dz and it turns out that da dz,this turns out to be a times 1 minus a,and dL da we are previously worked out over here,and so if you take these two quantities dL da,which is this term together with da dz,which is this term and just take these two things,and multiply them you can show that you,the equation simplifies the a minus y,so that’s how you derive it,and this is really the chain rule that,and this is really the chain rule that.

如果你对微积分不熟悉,也不用担心,实际上 dL/dz ,等于 (dL/da) 乘上, da/dz da/dz ,等于 a(1a) ,而 dL/da 在前面已经计算过了,因此将这两项 dL/da ,即这部分 和 da/dz ,这部分进行相乘,最终的公式,化简成 (ay ),这个推导的过程,就是我之前提到过的“链式法则”。

这里写图片描述

I briefly clue to you before ok,so feel free to go through that calculation yourself,if you are knowledgeable calculus,but if you aren’t all you need to know is that,you can compute dz as a minus y,and it already done the calculus for you,and then the final step in back propagation is to go back to compute how much you need to change w and b,so in particular you can show that the derivative respect to w1 ,and will call this DW 1 that,this is equal to x1 times dz,and then similarly dw 2,which is how much you want to change w2 is x2 times dz,and b excuse me db is equal to dz.

如果你对微积分熟悉,放心地去计算,整个求导过程,如果不熟悉微积分,你只需要知道, dz 等于 (ay) ,已经计算好了,现在向后传播的最后一步,特别地 关于 w1 的导数 dL/dw1 ,写成 dw1 ,等于 x1dz ,同样地 dw2 w2 的变化量 dw2 等于 x2dz b 不好意思 应该是db等于dz。

so if you want to do gradient descents,with respect to just this one example,what you will do is the following,you would use this formula to compute dz,and then use these formulas to compute dw1 dw2 ,and db and then you perform these,updates w1 gets updated w1 - learning rate alpha,rate alpha times dw1 w2 gets updated,similarly and B gets set as b - the learning rate times db ,and so this will be one step of gradicent descent,with respect to a single example,so you’ve seen how to compute derivatives and implement gradient descent for logistic regression with respect to a single training example.

因此关于单个样本的梯度下降法,你所需要做的就是这些事情,使用这个公式计算 dz ,使用这个计算 dw1 dw2 ,还有 db 然后,更新 w1 w1 减去学习率乘以 dw1 ,类似地 更新 w2 ,更新b 为b减去学习率乘以 db 这就是单个样本实例的,一次梯度更新步骤,现在你已经知道了,怎样计算导数 并且实现了单个训练样本的, logistic 回归的梯度下降法。

but to train logistic regression model you have not just one training example,given entire training set of m training examples,so in the next video.let’s see how you can take these ideas and apply them,to learning not just from one example,but from an entire training set.

但是训练 logistic 回归模型,不仅仅只有一个训练样本,而是有 m 个训练样本的整个训练集,因此在下一节视频中,这些想法如何应用到,整个训练样本集中,而不仅仅只是单个样本上。


重点总结:

对单个样本而言,逻辑回归 Loss function 表达式:

z=wTx+by^=a=σ(z)L(a,y)=(ylog(a)+(1y)log(1a))

反向传播过程:(红色部分)

这里写图片描述

前面过程的 da dz 求导:

da=La=ya+1y1adz=Lz=Laaz=(ya+1y1a)a(1a)=ay

再对 w1w2b 进行求导:

dw1=Lw1=Lzzw1=x1dz=x1(ay)

梯度下降法:

w1:=w1αdw1

w2:=w2αdw2

b:=bαdb

参考文献:

[1]. 大树先生.吴恩达Coursera深度学习课程 DeepLearning.ai 提炼笔记(1-2)– 神经网络基础


PS: 欢迎扫码关注公众号:「SelfImprovementLab」!专注「深度学习」,「机器学习」,「人工智能」。以及 「早起」,「阅读」,「运动」,「英语 」「其他」不定期建群 打卡互助活动。

### 回答1: Coursera-ml-andrewng-notes-master.zip是一个包含Andrew Ng的机器学习课程笔记和代码的压缩包。这门课程是由斯坦福大学提供的计算机科学和人工智能实验室(CSAIL)的教授Andrew Ng教授开设的,旨在通过深入浅出的方式介绍机器学习的基础概念,包括监督学习、无监督学习、逻辑回归、神经网络等等。 这个压缩包的笔记和代码可以帮助机器学习初学者更好地理解和应用所学的知识。笔记包含了课程涉及到的各种公式、算法和概念的详细解释,同时也包括了编程作业的指导和解答。而代码部分包含了课程使用的MATLAB代码,以及Python代码的实现。 这个压缩包对机器学习爱好者和学生来说是一个非常有用的资源,能够让他们深入了解机器学习的基础,并掌握如何运用这些知识去解决实际问题。此外,这个压缩包还可以作为教师和讲师的教学资源,帮助他们更好地传授机器学习的知识和技能。 ### 回答2: coursera-ml-andrewng-notes-master.zip 是一个 Coursera Machine Learning 课程的笔记和教材的压缩包,由学生或者讲师编写。这个压缩包包括了 Andrew Ng 教授在 Coursera 上发布的 Machine Learning 课程的全部讲义、练习题和答案等相关学习材料。 Machine Learning 课程是一个介绍机器学习的课程,它包括了许多重要的机器学习算法和理论,例如线性回归、神经网络、决策树、支持向量机等。这个课程的目标是让学生了解机器学习的方法,学习如何使用机器学习来解决实际问题,并最终构建自己的机器学习系统。 这个压缩包包含的所有学习材料都是免费的,每个人都可以从 Coursera 的网站上免费获取。通过学习这个课程,你将学习到机器学习的基础知识和核心算法,掌握机器学习的实际应用技巧,以及学会如何处理不同种类的数据和问题。 总之,coursera-ml-andrewng-notes-master.zip 是一个非常有用的学习资源,它可以帮助人们更好地学习、理解和掌握机器学习的知识和技能。无论你是机器学习初学者还是资深的机器学习专家,它都将是一个重要的参考工具。 ### 回答3: coursera-ml-andrewng-notes-master.zip是一份具有高价值的文件,其包含了Andrew NgCoursera上开授的机器学习课程的笔记。这份课程笔记可以帮助学习者更好地理解掌握机器学习技术和方法,提高在机器学习领域的实践能力。通过这份文件,学习者可以学习到机器学习的算法、原理和应用,其包括线性回归、逻辑回归、神经网络、支持向量机、聚类、降维等多个内容。同时,这份笔记还提供了很多代码实现和模板,学习者可以通过这些实例来理解、运用和进一步深入研究机器学习技术。 总的来说,coursera-ml-andrewng-notes-master.zip对于想要深入学习和掌握机器学习技术和方法的学习者来说是一份不可多得的资料,对于企业从事机器学习相关工作的从业人员来说也是进行技能提升或者知识更新的重要资料。因此,对于机器学习领域的学习者和从业人员来说,学习并掌握coursera-ml-andrewng-notes-master.zip所提供的知识和技能是非常有价值的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值