机器学习—逻辑回归

逻辑回归

@(My machine learing)

week three 4.30

Classification

For now, we will focus on the binary classification problem in which y can take on only two values, 0 and 1.
例如,一个邮件是垃圾邮件还是正常的
可以分为两类
也可以分为很多类

Hypothesis Representation

假设函数
因为对于一个逻辑分类问题来说,我们要得到的
一定是1,0
而以前的可能得到一个很大的数
所以我们要选择一个新的假设函数
如下所示
利用对数的性质,让其值在于0,1之间
机器学习—逻辑回归
hθ(x) will give us the probability that our output is 1.
如果大于0.5我们就认为它是一个1,反而就是0
hθ(x)≥0.5→y=1
hθ(x)<0.5→y=0
g(z)≥0.5
when z≥0
θTx≥0
The decision boundary is the line that separates the area where y = 0 and where y = 1. It is created by our hypothesis function.

Cost Function

假设函数变了,我们的cost Function一定也要改变
比较简单的说,对于我们的h(x)是一个指数形式的函数
如果我们给和以前一样算J(x)的时候用平方,那就会得到一个多凸函数
导致我们得到局部最优解,而不是全局的min
所以要对其cost function 进行求log
机器学习—逻辑回归
机器学习—逻辑回归

更简化的形式
机器学习—逻辑回归

Gradient Descent

对于这部分来说,我们对新的代价函数进行求导,会发现
我们得到的跟那个线性回归的一模一样
机器学习—逻辑回归

而且特征缩放也适用

Multiclass Classification

一对多
训练的时候我们先把一个当成一类,然后把其他所有的并为一类
然后就会得到一个h1,然后再重复得到h2,。。。。
最后会得到一个向量表示,是个个分类的概率,概率最大的那个就是我们要求的
机器学习—逻辑回归