Coursera | Andrew Ng (01-week-2-2.2)—Logistic 回归

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

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


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

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

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


Logistic 回归

In this video, we’ll go over logistic regression.This is a learning algorithm that you use when the output labels y in a supervised learning problem are all either zero or one,so for binary classification problems.Given an input feature vector x maybe corresponding to an image that you want to recognize as either a cat picture or not a cat picture,you want an algorithm that can output a prediction,which we’ll call y hat,which is your estimate of y.More formally, you want y^ to be the probability of the chance that y is equal to one given the input features x.

这里写图片描述

本视频中,我们讲讲 logistic 回归,这是一个用在监督学习问题中的学习算法 ,输出 y 标签是 0 或 1 时,这是一个二元分类问题。已知的输入特征向量 x 可能是一张图,你希望把识别出,这是不是猫图,你需要一个算法,可以给出一个预测值,我们说预测值 y^ ,就是你对 y 的预测,更正式的说,你希望 y^ 是一个概率,当输入特征 x 满足条件时,y 就是 1。

So in other words, if x is a picture,as we saw in the last video,you want y hat to tell you,what is the chance that this is a cat picture.So x, as we said in the previous video,is an nx dimensional vector,given that the parameters of logistic regression will be w,which is also an nx dimensional vector,together with b which is just a real number.So given an input X and the parameters W and b,how do we generate the output y^ ? Well, one thing you could try, that doesn’t work,would be to have y hat be w transpose X plus B,kind of a linear function of the input X.

所以换句话说,如果 x 是图片,正如我们在上一个视频中看到的,你希望 y^ 能告诉你,这是一张猫图的概率,所以x 正如我们之前的视频里说过的,是一个 nx 维向量,已知 Logistic 回归的参数是 w,也是一个 nx 维向量,而 b 就是一个实数,所以已知输入 x 和参数 w 和 b,我们如何计算输出预测 y^ ? 好,你可以这么试,但其实不靠谱,就是 y^=wTx+b ,输入 X 的线性函数。

And in fact, this is what you use if you were doing linear regression.But this isn’t a very good algorithm for binary classification,because you want y hat to be the chance that Y is equal to one.So y hat should really be between zero and one,and it’s difficult to enforce that because wTx+b can be much bigger then one or it can even be negative,which doesn’t make sense for probability,that you want it to be between zero and one.

这里写图片描述

事实上,如果你做线性回归 就是这么算的。但这不是一个非常好的二元分类算法,因为你希望 y^ 是 y=1 的概率,所以 y^ 应该介于 0 和 1 之间,但实际上这很难实现,因为 wTx+b ,可能比 1 大得多或者甚至是负值 ,这样的概率是没意义的, 你希望概率介于 0 和 1 之间。

So in logistic regression our output is instead going to be y hat equals the sigmoid function applied to this quantity.This is what the sigmoid function looks like.If on the horizontal axis I plot Z then the function sigmoid of Z looks like this.So it goes smoothly from zero up to one.Let me label my axes here,this is zero and it crosses the vertical axis as 0.5.So this is what sigmoid of Z looks likeand we’re going to use Z to denote this quantity,W transpose X plus B.

sigmoid

所以在 Logisitc 回归中我们的输出变成, y^ 等于 sigmoid 函数作用到这个量上,这就是 sigmoid 函数的图形,横轴是 z,那么 sigmoid(z) 就是这样的,从 0 到 1 的光滑函数,我标记一下这里的轴,这是 0 然后和垂直轴相交在 0.5 处,这就是 sigmoid(z) 的图形,我们用 z 来表示这个量,w 转置 x + b。

Here’s the formula for the sigmoid function.Sigmoid of Z, where Z is a real number,is one over one plus e to the negative Z.So notice a couple of things.If Z is very large then e to the negative, Z will be close to zero.So then sigmoid of Z will be approximately one over one plus something very close to zero,because e to the negative of very large number will be close to zero.So this is close to 1.

这是 Sigmoid 函数的公式, sigmoid(z) 其中 z 是实数,就是 11+ez ,要注意一些事情,如果 z 非常大 那么 ez 就很接近0,那么 sigmoid(z) 就是,大约等于 11+0 ,因为 ez 在 z 很大时就很接近 0,所以这接近 1。

And indeed, if you look in the plot on the left,if Z is very large the sigmoid of Z is very close to one.Conversely, if Z is very small,or it is a very large negative number,then sigmoid of Z becomes one over one plus E to the negative Z,and this becomes, it’s a huge number.

事实上,如果你看看左边的图,z 很大时 sigmoid(z) 就很接近1,相反 如果 z 很小,或者是非常大的负数,那么 sigmoid(z) 就变成 11+ez ,就变成很大的数字。

So this becomes, think of it as one over one plus a number that is very, very big, and so,that’s close to zero.And indeed, you see that as Z becomes a very large negative number,sigmoid of Z goes very close to zero.So when you implement logistic regression,your job is to try to learn parameters W and B.so that y hat becomes a good estimateof the chance of Y being equal to one.

这里写图片描述

这就变成.. 想一下,1 除以 1 加上很大的数字 ,那是非常大的数字,所以这接近 0,确实 当你看到 z 变成非常大的负值时, sigmoid(z) 就很接近 0,所以当你实现 logistic 回归时,你要做的是学习参数 w 和 b,你要做的是学习参数w 和 b,所以 y^ 变成了比较好的估计,对 y=1 概率的比较好的估计。

Before moving on, just another note on the notation.When we programmed neural networks,we’ll usually keep the parameter W and parameter b separate,where here, b corresponds to an interceptor.In some other courses,you might have seen a notation that handles this differently.In some conventions you define an extra feature called x0 and that equals a one.So that now x is in R(nx+1) .And then you define y hat to be equal to sigma of theta transpose X.

在继续之前,们再讲讲符号约定,当我们对神经网络编程时,我们通常会把 w和参数 b 分开,这里 b 对应一个拦截器。在其他一些课程中,你们可能看过不同的表示,在一些符号约定中,你定义一个额外的特征向量 叫 x0 那等于 1,所以出现 x 就是 R(nx+1) 维向量,然后你将 y^ 定义为 σ(θTx)

In this alternative notational convention,you have vector parameters theta,theta zero θ0 , theta one θ1 , theta two θ2 ,down to theta nx θnx .And so, theta zero θ0 , plays the role of b,that’s just a real number,and theta one θ0 down to theta nx θnx play the role of W.It turns out, when you implement you implement your neural network,it will be easier to just keep b and W as separate parameters.

这里写图片描述

在这另一种符号约定中,你有一个向量参数 θ θ0 θ1 还有 θ2 ,一直到 θnx ,所以 θ0 扮演的是 b 的角色,这是一个实数,而 θ1 直到 θnx 的作用和 w 一样,事实上 当你实现你的神经网络时,将 b 和 w 看作独立的参数可能更好。

And so, in this class,we will not use any of this notational convention that I just wrote in red.If you’ve not seen this notation before in other courses,don’t worry about it.It’s just that for those of you that have seen this notation I wanted to mention explicitly that we’re not using that notation in this course.But if you’ve not seen this before,it’s not important and you don’t need to worry about it.So you have now seen what the logistic regression model looks like.Next to change the parameters W and B.you need to define a cost function.Let’s do that in the next video.

所以对于这门课,我们不会用那种符号约定,就是红色写的那些我不会用,如果你们没有在其他课程里见过这个符号约定,不要担心太多,我讲这个是为了服务那些见过这种符号约定的学生,我们在本课中不会使用那种符号约定,如果你以前没见过,这不重要所以不用担心,现在你看到了 logistic 回归模型长什么样,接下来我们看参数 w 和 b,你需要定义一个成本函数,我们下一个视频来讨论。


重点总结:

2. logistic Regression

逻辑回归中,预测值:

h^=P(y=1|x)

其表示为 1 的概率,取值范围在 [0,1] 之间。

引入 Sigmoid 函数,预测值:

y^=Sigmoid(wTx+b)=σ(wTx+b)

其中

Sigmoid(z)=11+ez

注意点:函数的一阶导数可以用其自身表示,

该部分的求导可查看:Logistic回归-代价函数求导过程 | 内含数学相关基础

σ(z)=σ(z)(1σ(z))

这里可以解释梯度消失的问题,当 z=0 时,导数最大,但是导数最大为 σ(0)=σ(0)(1σ(0))=0.5(10.5)=0.25 ,这里导数仅为原函数值的 0.25 倍。

参数梯度下降公式的不断更新, σ'(z) 会变得越来越小,每次迭代参数更新的步伐越来越小,最终接近于 0,产生梯度消失的现象。


参考文献:

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


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答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所提供的知识和技能是非常有价值的。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值