斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

逻辑回归(Logistic Regression)

1. 分类(Classification)

The classification problem is just like the regression problem, except that the values we now want to predict take on only a small number of discrete values. For now, we will focus on the binary classification problem in which y系统运维是干嘛的 can take on only two values, 0 and 1. For instance, if we are trying to build a spam classifier for ema线性回归方程公式il, t其他垃圾有哪些东西hen
x
(
i
)
x^{(i)}
x(i)maclassification翻译y be some features of a piece of email, and y may be 1 if it is a piece of spa线性回归模型m mail, and 0 otherwise. Hence, y∈{0,1}. 0 is a其他货币资金lso called the negative class, and 1 the pos线性回归分析spssitive class.

简而言之,分类就是通过一系列的特征值,来将数据集分成不同的类别。线性回归分析spss也就是说其最终的输出
y
y
y是离散的值。比如垃圾邮件的分类。

2. 假设函数(Hypothesis function)

逻辑回归中的假设函数在本质与意义上同线性回归中的假设函数,仅仅只是在形式上发生了变化。

We could appr其他垃圾oach the classification problem ignoring the fact that yclassification是什么意思啊 is discrete-valued, and use o线性回归方程公式ur old linear regr其他和其它的区别ession algorithm to try t线性回归分析spsso predict y gi线性回归分析ven x系统运维工程师. However,过度拟合什么意思 it is easy to construct examples below where this method performs very poorly.

example 1:

在上面的图片中,我们可以用以下表其他综合收益属于什么科目达式来表示假设函数:

系统运维包括哪些内容
h

(
x
)

0.5
h_\theta(x)\geq0.5
h​(x)≥0.5,
y
=
1
y=1
y=1;


h

(
x
)
<
0.5
h_\theta(x)<0.5
h​(x)<0.5系统运维工作内容
y
=
y=0
y=0; (至于为什么是0.5,第六周课程会讲到。简单说为了线性回归方程公式提高准确度你可以设置得更大,比如0.9,但这并不代表此时的模型最优)

但是这样表示的问题就是,如果此时在添加一条数据(如下图),这个表达式就不适用了。


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

examp其他货币资金le 2:

在逻系统运维工作内容辑回归中,

h

(
x
)

1
0\leq h_\theta(系统运维工作内容x) \leq1
0≤h(x)≤1(因为
h

(
x
)
h_线性回归统计三要素\theta(x)
h(x)表示的是
y
=
1
y=1
y=1的概率);而在线性回归中
h

(
x
)
h_\theta(x)
h(x)的取值范围可能大于1或者小于0,并且其值也不表示某种情况的概率。

Logisticclassification Regression Model:

h

(
x
)
=
g
(

T
x
)
,
g
(
z
)
=
1
1
+
e

z
h_\theta(x) = g(线性回归方程计算器\theta^Tx),g(z) = \frac{1}{1+e^{-z}}
h​(x)=g(Tx),g(z)=1+e−z1​;

h

(
x
)
=
1
1
+
e

T
x
h_\theta(x) = \frac{1}{1+e^{-\theta^Tx}}
h​(x)=1+e−Tx1​;

h

(
x
)
h_\theta(x)
h(x) will give us the probability that our output is 1.线性回归统计三要素 For example,
h

(
x
)
h_\theta线性回归分析spss(x)
h(x)=0.7 gives us a probabilityoverfitting of 70% that our output is 1.

h

(
x
)
=
h_\theta(x) =
h(x)=(表示Y=1时的概率)

P
(
y
=

x
;

)
+
P
(
y
=
1

x
;

)
=
1
P(y=0|x;\theta) + P(yoverfittin=1|x;\theta) = 1
P(y=0∣x;)+P(y=1∣x;)=1


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

其中
g
(
x
)
g(xclassification和division的区别)
g(x)称为S型函数(sig机器学习moid function)或者逻辑函数(logistic其他垃圾有哪些东西 function)

3. 决策边其他应收款overfitting(Decision boclassification怎么读undary线性回归分析spss)

In order to线性回归方程公式详解 get our discrete 0 or 1 classification, we can translate the output of the hypothesis function as follows:

为了解决离散值0和1的分类问题,我们可以将假设函数转化为如下形式:

h

(
x
)

0.5

y
=
1
h_\theta(x) \geq 0.5→y=1
h​(x)≥0.5→y=1
h

(
x
)
<
0.5

y
=
h_\theta(x) < 0.5→y=0
h​(系统运维工作内容x)<0.5→y=0

也就是说当
h

(
x
)
h_\theta(x)过度拟合什么意思
h​(x)大于0.5时,我们classification就可以认为
y
y
y的取值为线性回归方程计算器1了,因为超过了一半的概率。

同时,根据
h

(
x
)
=
g
(

T
x
)
=
g系统运维主要做什么
(
z
)

z
=

T
x

h_\theta(x) = g(\theta^Tx) = g(z系统运维工作内容) (z=\theta^Tx )
h​(x)=g(Tx)=g(z)(z=Tx)的图像,我们可以得出以下结论:

当$ z\geq0


时,
时,g(z)\geclassification是什么意思啊q0.5
;

;即系统运维工程师
;即h_\theta(x)\geq0.5


时,
时,y=1$

当$ z<0


时,
时,g(z)<0.5
;

;即
;即h_\theta(x)<0.5


时,
时,y=0$

立即推:

T
x

\theta^Tx线性回归方程 \geq0
Toverfittinx≥0时,
y
=
1
y=1
y=1; 当

T
x
<
\thetoverfittinga^Tx <线性回归分析;其他业务收入0
Tx<0时,
y
=classification怎么读
y=0
y=0;也就是说,此时用$\theta^Tx


















把数据集分成了两个部分。因此,我们把
把数据集分成了两个部分。因此,我们把\theta^Tx =0$这条直(或曲)线称之为决策边界系统运维包括哪些内容。注意,决策边界仅仅只是假设函数的性质,与其他无关。

The Decision Boundary is a property of the hypothe其他应收款是什么科目sis including线性回归分析spss tclassificationhe parameters

,

1
,

2

\theta_0,\theta_1,\theta_2\cdots
0,1,2⋯, which is the line that separ其他垃圾ates the area where y = 0 aoverfittingnd where y = 1. It is created by o系统运维包括哪些内容ur hypotheclassification翻译sis fun其他ction. And the data set is only used to fit the parameters theta.

看一系统运维是干嘛的个例子:


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

已知$\theta_0 = -3, \theta_1 = 1, \theta_2 = 1; \to h_\theta(x) = g(-3 + x_1 + x_2) $,由前面推导可知:

T
x
=

3
+
x
1
+
x
2

系统运维包括哪些内容
y
=
1
\theta^Tx = -3 + x_1 + x_2 \geq0 \to y=1
Tx=−3+x1​+x2​≥0→y=1

T
x
=

3
+
x
1
+
x
2
<

y
=
\theta^Tx = -3 + x_1 + x_2 <0 \线性回归方程公式to y=0
Tx=−3+x1​+x2​<0→y=0

所以,原数据集被**决策边界

T
x
=

3
+
x
1
+
x
2
=
\th其他和其它的区别eta^Tx =-3 + x_1 + x_2 = 0
Tx=系统运维是干嘛的−3+x1+x2=0**分割成如下两个部分,其他业务收入右上方表示
y
=
1
y=1
y=1的部分,左下方表示
y
=
y=0
y=0的部分。


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

4. 代价函数系统运维包括哪些内容(Cost func系统运维是干嘛的tion)


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

We cannot use the same cost线性回归模型 function that we use for linear regression because the Logistic Function will cause the output to be wav线性回归统计三要素y lo线性回归方程计算器oks like the figure left above, causi系统/运维ng many local optima. In other words, it will not be a convex function.
Instead, our cost function for logistic regression looks like:

J
(

)
=
1
m

i
=
1
m
C
o线性回归模型
s
t
(
h

(
x
(
i
)
,
y
(
i
)
)
J(\theta) = \frac{1}{m}\displaystyle\sum_{i=1}^{m}Cost(h_\theta(x^{(i)},y^{(i)})
J()=m1​i=其他业务收入1∑m​Co其他应收款是什么科目st(h​(x(i),y(i));

$Cost(h_\theta(x),y) =\begin其他{cases} -\log (h_\theta(x)),& \text {if
y
=
1
y = 1
y=1}\ -\log(1-h_\thet其他应付款a(x)), & \text{if
y
=
y=0
y=0 } \end{cases}$线性回归方程公式b推导过程

Note:

h

(
x
)

1




y
=
1
0\leq h_\theta(x) \leq1表示的是y=1
0≤h(x)≤1表示overfitting的是y=1的概率


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

由于
y
y
y的取值只有0和1,所以原式又可以写成如下形式:

J线性回归分析
(

)
=
1
mclassifica

i
=
1
m
C
o
s
t线性回归方程
(
h

(
x
(
i
)
,
y
(
i
)
)
=

1
m
[

i
=
1
m
y
(
i
)
log

h

(
x
(
i
)
)
+
(
1

y
(
i
)
)
log

(
1

h

(
x
(
i
)
)
)
]
J(\theta) = \frac{1}{m}\displaystyle\sum_{i=1}^{m}Cost(h_\theta(x^{(i)},y^{(i)}) = -\frac{1}{m}[\displaystyle\sum_{i=1}^{m}y^{(i)}\log h_\theta(x^{(i)}) + (1 - y^{(i)})\log (1 - h_\theta(x^{(i)}))]
J()=m1i=1∑线性回归方程公式mCost(h(x(i),y(i))=−m1[i=1∑my(i)logh(x(i))+(1−y(i))log(1−h(x(i)))]

A vectorizeclassificad imple其他应收款mentatio系统运维包括哪些内容n is:

h
=
g
(
X

)
h=g(X\theta)
h=g(X)

J
(

)
=
1
m
(

y
T
log

(
h
)

(
1

y
)
T
log

(
1

h
)
)
J(\thoverfittingeta) = \frac{线性回归分析spss1}{m}(-y^T\log(h) - (1线性回归方程公式详解-y)^T\log (1-h))
J其他综合收益()=m1(−yTlog(h)−(1−线性回归分析y)Tlog(1−h))

If our correct answer ‘y’ is 0:
then the cos其他综合收益属于什么科目t functio其他货币资金n will be 0 if our hypothesis function also outputs 0.
then the cos其他货币资金t function will approach inf线性回归inity,If our hypothesis approaches 1.

If our correct answer ‘y’ is 1:
then the cost function will be 0 if our hypothesis function outputs 1.
then the cost过度拟合 function will appro其他应收款是什么科目ach infinity, If其他垃圾有哪些东西 our hypothesis approaches 0.

Note that writing the cost function in this way系统运维是干嘛的 guarant线性回归方程公式详解ees that J() is convex for logistic regression.

5. 梯度下降(Gradient Descent)

classifica了代价函数,下一classification翻译步就是用梯度下降算法进行最小化Minimize
J
(

)
J(\theta)
J()了。不管是在Linear regress其他应收款是什么科目ion model 中还是Logistic regression model中,梯度下降算法的最classification翻译基本线性回归方程公式b推导过程形式都是一样的,只是
Jclassification意思
(

)
J(\theta)
J()的形式发生了改变。

Gradient Descent
Remember that the general form of gradient descent is:

R
e
p
e
a
t
{
Repeat \{
Repeat{

  

j
:
=

j


j
J
(

)
\theta_j := \theta_j - \alpha\frac{\partial}{\partial线性回归方程\theta_j}J(\theta)
j​:=j​−∂j​∂​J()

}
\}
}

在逻辑回归中:

J
(

)
=

1
m
[

i
=
1
m
y
(
i
)
log

h

(
x
(
i
)
)
+
(
1

y
(
i
)
)
log

(
1

h

(
x
(
i
)
)
)
]
J(\theta) = -\frac{1线性回归模型}{m}[\displaystyle\sum_{i=1}^{m}y^{(i)}\log h_\theta(x^{(i)}) + (1 - y^{(i)})\log (1 - h_\theta(x^{(i)}))]
J()=−m1[i=1∑my(i)logh(x(i))+(1−y(i))log(1−h(x(i)))]

所以,求导后的表达式如下:

We can系统运维包括哪些内容 work out the derivative part using calculus to get:

R
e
p
e
a
t
{
Repeat \{
Repeat{

j
:
=

j

m

i
=
1
m
(
h

(
x
(
i
)
)

y
(
iclassification怎么读
)
)
x
j
(
i
)
\theta_j := \theta_j - \f其他业务收入rac{\alpha}{m}\displayst过度拟合什么意思yle\线性回归方程公式详解sumclassification意思_{i=1}^{m}(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}
j​overfitting:=j​−m​i=1∑m​(h​(x(i系统/运维))−y(i))xj(i)​

}
\}
}

Notice that this algorithm is identical to the one we used in linear regression. We still have to simul机器学习taneously update all values in theta.

其中,
h

(
x
)
=
1
1
+
e

T
X
h_\theta(x) = \frac{1}{1+e^{-\theta^TX}}
h(x线性回归方程例题详解)=1+e−TX1;而在线性回归中
h

(
x
)
=

T
X
h_\thet过度拟合a(x)=\theta^TX
h(x系统运维主要做什么)=TX

A vectorized implementation is:

:
=

m
(
h

(
x
)

y

)
x
j
\theta := \theta - \frac{\alph其他综合收益a}{m}(h_线性回归方程\theta(x)- \vec{y})x_j
:=−m(h(x)−y
)xj

推导见​​关于梯度线性回归方程下降算法的矢量化过classification怎么读程​​

6. 进阶优化(Advanced Optimization)其他应收款


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

"Conjugate gradient", “B线性回归FGS”, and “L-BFGS” are more sophisticated, faster way其他应付款s to optimize that can be used instead of gra其他货币资金dient descent. We suggest that you should not write these more sop系统运维包括哪些内容histicated algorithms yourself (unless you are an expe机器学习rt in numer线性回归模型ical compclassificauting) but use the libraries instead, as they’re already tested and highly optimized. Octaclassification翻译ve provides them.

有一个观点是这样来描述梯度下降算法的:梯度下降算法做了两件事,第一计算
J
(

)
J(\theta)
J();第二计算

j
J
(

)
\frac{\partial}{\p其他垃圾artial\theta其他货币资金_j}J(\theta)
∂j∂J()。当然除了Gradient descent 之外,还有其他三种算法也能做着两件事情(以此来最优化参数

\thet其他a
),且比梯度下降算法线性回归方程公式b推导过程更快,不用手动选择

\alpha
,但却更复杂。因为复杂,所以就不用我们自己来编写这些算法,使用开源的库即可。此时我们只需要自己写好cost func系统运维是干嘛的tion以及告诉matlab我们需要用那种算法来优化参数。


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

如图,现在我们用Matlab中的函数fminunc来计算
J
(

)
J(\theta)
J()和

j
J
(

)
\frac{\partial}{\partclassification怎么读ial\theta_j}J(\t线性回归方程计算器heta)
∂j∂J(),并且最终得到参数

\theta
的优化值。


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

You set a few options. This is a options as a data structure that stores the options you want. So grant up on, this sets the gradient objective parameter to on. It jusclassificatoverfitting means you线性回归方程公式详解 are indeed g线性回归分析spssoing to provi线性回归模型de a gradient to this algorithm. I’m going to set the maximum nu系统运维工程师mber of iterations to, let’s say, one hu线性回归ndred. We’re线性回归 going gi其他应付款ve it a其他和其它的区别n initial guess for theta. There系统运维工程师’s a 2 by 1 vect其他垃圾or.

optTheta %用来保存最后计算得到的参数值
functionVal %用来保存代价函数的计算值
exitFlag %用来表示最终是否收敛(1表示收敛)
@costFunction %表示调用函数costFunctioin
function [ jVal,gradient ] = costFunction( theta )
%此函数有两个返回值
%jVal 表示 cost function
%gradient 表示分别对两个参数的求导公式
jVal = (theta(1) - 5)2 + (theta(2) - 5)2;
gradient = zeros(2,1);
gradient(1) = 2 * (theta(1) - 5);
gradient(2) = 2 * (theta(2) - 5);
end
>> options = optimset('GradObj','on','MaxIter',100);
>> initialTheta = zeros(2,1);
>> [optTheta,functionVal,exitFlag]=fminunc(@costFunction,initialTheta,options)

因此,不管是在逻辑回归中还是线性回归中,只需要完成下图红色classifica矩形中的内容即可。


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

7. 多分类(Multi-class classification: One-vs-all)


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

Multi线性回归方程公式b推导过程-class 简而言之就是
y
y
y的输出值不再是仅仅只有0和1了。而解决这一问题的思想就是,每次都把把tra过度拟合ining set 分成两部分classifica,即One线性回归方程计算器-vs-all。

One-vs-all
Train a线性回归分析 logistic regression classifier
h其他综合收益属于什么科目

(
i
)
(
x
)
h_\theta^{(i)}(x)
h(i)​(xclassification怎么读) for each clas其他垃圾s
i
i
i to predict the probability th线性回归方程例题详解at线性回归
y
=
i
y=i
y=i.

On a new input
x
x
x, to make a prediction, pick the class
i
i
i that maximizes
m
a
x
{线性回归方程
h

(
i
)
(
x
)
}
max \{h_\theta^{(i)}(x)\}
max{h(i)​(x)}.


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

处理方法:


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

We are basically choosing one cl系统运维主要做什么ass and then lumping all the others into a single second class. We do this repeatedly, applying binary lo系统/运维gistic regression to each case, and then use the hypothesis that returned the highest value as our pr线性回归统计三要素ediction.

在解决这个问题的时候,我们根据图一,线性回归方程例题详解图二,图三的处线性回归分析spss理来训练三个分类器(c线性回归分析lassifier)
h

(
1
)
(
x
)
,
h

(
2
)
(
x
)
,
h

(
3
)
(
x
)
h_\theta^{(1)}(x),h_\theta^{(2)}(x),h_\theta^{(3)}(x)
h(1)(x),h(2)(x),h(3)(x) ,分表来输出
y
=
c
a
l
s
s
1系统/运维
,
y
=
c
a
l
s
s
2
,
y
=
c
a
l
s
s
3
y=其他垃圾calss 1,y线性回归=calss 2,y=calss 3
y=calss1,y=calss2,y=calss3的概率。在输入一个新的
x
x
x后,分别在三个分类器中计算
y
y
y的值,然后选择其中最大的即可。

8. 过度拟合(Over fitting)

既然有过度拟合,那就可定有对应的欠拟合;简单的说过度拟合就是假设函数过于复杂,过度拟合什么意思虽然他能完美地拟overfittin合training set 但却不能预测新的数据。这中现象不仅出现在线性回归中,逻辑回归其他业务收入中一样会线性回归统计三要素有。下面的两幅图最左边的都是欠拟合(underfit),最右边的都是过度拟合(overfitting),中间的刚刚好(just right). 产生过度拟合的其中一个原因就是,训练数据太少,而特征值太多。


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

![这里写图片描述](https://imgconv系统运维包括哪些内容ert.csdnimg.cn/aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwNjE2MTQzNTQ1NzMy?x-oss-process=image/format,png)

Underfitting,其他垃圾 or high bias, is when the form of our hypothesioverfittins function h maps poorly toclassification意思 the trend of the data. It is usually caused by a function that is too simple or uses too few features. At the other extreme, overfitting, or high variance, is caused by a hypothesis fun其他综合收益ction that fits the av其他应付款ailable data but does not generalize well to predict new data. It is usually caused by a complicated function that creates a lot of unnecessary curves and angles unrela其他应收款ted to the data.


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

那么怎么来解线性回归分析决这个问题呢?有两种方法:

There are two main options to address the issue其他综合收益 of overfitting:

  1. Reduc线性回归模型e th线性回归方程公式b推导过程e number of features: (减少特征值)
      Manually select which features to keep.(手动)
      Use a modclassificael selection alg其他应收款orith线性回归方程公式详解m (studied later in the course).(利用选择模型自动)
  1. Regul系统/运维arizatioclassificationn
    Keep all the features, but reduce the magnitude of parameters

    j
    \theta_j
    j​.
    Regularization works well when we have a lot of s其他垃圾有哪些东西lightly useful features.

9. 规则化(Regularization)

If we h过度拟合什么意思ave overfitting fromclassification和division的区别 our hypothesis function, we can reduce the we线性回归ight thatclassification怎么读 some of the terms in our fun其他和其它的区别ction carry by increasing their cost.

Say we wanted to make the following fun其他综合收益ction线性回归分析spss more quadratic:

+

1
x
+

2
x
2
+

3
x
3
+

4
x
4
\theta_0+\theta_1x+\theta_2x^2+\theta_3x^线性回归方程公式b推导过程3线性回归分析spss+classification翻译\theta_4x^4
0​+1​x线性回归方程例题详解+2​x2overfittin+3​x3+4​x4

We’ll want t线性回归方程公式b推导过程o eliminate the influence of

3
x
3
\theta_3x^3
3​x3 and

4
x
4
\theta_4x^4线性回归模型
4​x4 .

简而言之,我们想把上面的4次多项式近似的改成一个2次多项式,也就机器学习是消除3次项和线性回归方程例题详解4次项对原式的影系统运维工作内容响,但又不能直接去掉这两项。该怎么办呢? 办法就是通过classification是什么意思啊参数

\theta
降低这些想的权重(reduce the weight)。想想,如果

3
x
3
\theta_3x^3
3x3 和

4
x
4
\theta_4x^4
4x4 都趋于0了,那么它对原式的影响就可以忽略不计了。

Without actually getting rid of these foverfittingeatures or changing the form of our hypothesis线性回归方程公式b推导过程, we can instead modify our cost function:

Minimize
1
2
m

i
=线性回归模型
1
m
(线性回归方程公式
h

(
x
(
i
)
)

y
(
i
)
)
2
+
1000

3
2
+
1000

4
2
\frac{1}{2m}\displaystyle\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})^2overfittin+1000\theta_3^2+1000\theta_4^2
2线性回归方程例题详解m1i=1∑m(h(x(i))−y(i))2+1其他业务收入00032+100042

We’ve added two extra terms at the end to inflate the cost of

3
\theta_3
3 and

4
\theta_4
4. Now, in order for the cost function to get clo系统/运维se to zoverfittingero, we will have to reduce the values of

3
\theta_3
3 and

4
\theta_4
4 to near zero. This will i线性回归分析n turn greatly reduce the values of

3
3
\theta_3^3
33 and

4
4
\theta_4^4
44 in our hypot线性回归模型hesis function. As a result其他应收款是什么科目, we see that the new hypothesis (depicted by the pink curve) looks like a qua线性回归方程dratic f过度拟合什么意思unction but fits the data bett系统运维是干嘛的er due to the extra small te其他和其它的区别rms

3
3
\theta_3^3
33 and

4
4
\theta_4^4
44.

我们已经在原式的末尾额外加上了两项来增加

3
\the线性回归分析spssta_3
3和

4
\theta_4
4的代价。现在,对于代价函数来说,为了能使代价值最低(接近0),那么我们就必须去降低其他应收款

3
\theclassification是什么意思啊ta_3
3和

4
\theta_4
4的值,使其接近于0(因为

3
\theta_3
3和线性回归方程例题详解

4
\theta_4
4的系数很大,若

3
\theta_3
3和

4
\theta_4
4不能接近于0那么代价函数就不可能趋于0)。同时,这也将极大地降低

3
\theta_3
3和

4
\theta_4
4在假设函数中线性回归方程例题详解的值(权重)。最终,我能将会看到一个新的假设函数(下图的粉红曲线),其图形就类似于2次函数了,线性回归分析但却依旧能更好的拟合数据集了。


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

在这个例子中,因为我们事先知道目的(使其类似于一个二次多项式),所以我们就知道惩罚(penclassification是什么意思啊alize)参数

3
\theta系统运维是干嘛的_3
3和

4
\theta_4
4。试想一下,如果我们事先不知道该惩罚哪个参数呢?唯一的办法就是都进行惩罚,那么最终,
h

(
x
)
h_\theta(x)
h(x)虽然在形式上没有发生变化,但是实际上却变得更“简单”了。 这就是Regul系统运维工程师arization的思想


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

We could also regularize all of our the线性回归分析spssta parameters in a single summation as:

m
i
n
1
2
m

i
=
1
m
(
h

(
x
(
i
)
)

y
(
i
)
)
2过度拟合
+


j
=
1
n

j
2
min \frac{1}{2m}\displaystyle\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})^2+\lambda\displaystyle\sum_{j=1}线性回归方程公式b推导过程^n\theta_j^2
min2m1i=1∑m(h(x(i))−y(i))2+j=1∑nj2

The


j
=
1
n

j
2
\lambda\sum_{j=1}^nclassification怎么读\theta_j^2
∑j=1nj2 ,is the regularization teclassification怎么读rm The , or lambda, is the regularization parameter. It determines how much the costs of our theta parameters are inflated.

Using the above cost function with the extra summation, we can smooth the o其他业务收入utput of our hypothesis function to re系统运维工作内容duce overfitting. If lambda is chosen tclassification和division的区别o be too large, it may smooth线性回归方程例题详解 out the functi线性回归方程公式on too much and cause underfitting. Hence, what would happen if =0 or is too small ?


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

在这个例子中,由于

\lambda
过大,最终将导致

1
,

2
,

3
,

4
\t机器学习heta_1,\theta_2,\theta_3,\theta_4
1,2,3,4classification意思都趋于0,所以
h

(
x
)

h_\theta(x) \approx\theta_0
h(x)≈0。同时,如果

\lambda
过小的话,我个人认为应该会使得regularization失效。

10.Regularizedclassification怎么读 linear re其他垃圾有哪些东西gression

We can apply regularization to both linear regression and logistic regression. We其他应付款 will approach linear regression firsoverfittint.

J
(

)
=
1
2
m

i
=
1
m
(
h

(
x
(
i
)
)

y
(
i
)
)
2
+


j
=
1
n

j
2
J(\th机器学习eta)=\frac{1}{2m其他应付款}\displaclassification翻译ystyle\classification意思sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})^2+\lam系统/运维bda\displaystyle\sum_{j=1}^n\theta_j^2
J()=2m1​i=1∑m​(h​(x(i))−y线性回归方程计算器(i))2+j=1∑n​j2​

want: Minimize
J
(

)
J(\theta)
J()

Gra线性回归分析dient Descent
We w线性回归模型ill modify our gradient descent function to separate out

\theta_0
0​ from the rest of the parameters because we do not want to penalize

\theta_其他应付款0
0​.


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

Repea系统/运维t {

:
=

1
m系统运维是干嘛的

i
=
1
m
(
h

(
x
(
i
)
)

y
(
i
)
)
x
(
i
)
\qquad\theta_0:=\theta_0-\alpha\frac{1}{m}\displaysclassification翻译tyle\sum_{i=1}^m(h_\theta(x^{(i)}系统运维工作内容)-y^{(i)})x_0^{(其他业务收入i)系统运维是干嘛的}
0​:=0​−m1​i=1∑m​其他应收款(h​(x(i))−y(i))x0(i其他垃圾有哪些东西)​

j
:
=

j
(
1

m
)

1
m

i
=
1
m
(
h

(
x
(
i
)
)

y
(
i
)
)
x
j
(
i
)
j

{
1
,
2

n
}
\qquad\theta_j := \theta_j(1-\alpha\frac{\lambda}{m})-\alpha\f线性回归统计三要素rac{1}{m}\displaystyle\su过度拟合m_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)} \qquad\qquad j\in\{1,2\dooverfittingts n\}
j​:系统运维主要做什么=j​(1−m​)−m1​i=1∑m​(h​(x(i))−y(i))xj(i)​j∈{1,2…n}

}

The first term in线性回归方程公式 the above equation,
1

m线性回归方程
1-\alpha\fracclassification翻译{\lambda}{m}
1−m​ will always be less than 1. Intuitively you can see it as reducing the value of

j
\theta_j
j​ by some线性回归统计三要素 amoun其他货币资金t on every u其他应付款pdate. Notice that the second term is now exactly the same as it was before.

Normal Equation
Now let’s approach regularization using the alternate method of the non-classification是什么意思啊iterative normal equation.
To add in regularization, the equation is the same as our origina系统运维工程师l, except that we add another term inside the parentheses:


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

L
L
L系统运维主要做什么 is a matrix with 0 at the top left a机器学习nd 1 is down the diagonal, with 0 is everywhere else. It should have dimension (n+1)(n+1). Intuitively, this is the identity过度拟合 matrix (though we are not includin其他和其它的区别g
x
x_0
x0), multiplied wi线性回归方程例题详解th a其他业务收入 single real number .

Recall that if m < n, then过度拟合
X
T
X
X^TX
XTX is non-invertible. However, when we add the term ⋅L, then
X
T
X
X^TX
XTX+ ⋅L beco其他应付款mes invertible.

11.Regularized logistic regress线性回归方程公式详解ion


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)

Repeat {

:
=

1
m

i
=
1
m
(
h

(
x
(
i
)
)

y
(
i
)
)
x
(
i
)
\qquad\theta_0:=\classification翻译theta_0-\a线性回归方程lpha\frac{1}{m}\displaystyle\sum_{i=线性回归方程计算器1classification怎么读}^m(h_\theta(x^{(i)})-y^{(i)})x_0^{(i)}
0​:线性回归模型=0​−m1​i=1∑m​(h​(x(i))−y(i))x0(i)​

j
:
=

j
(
1

m
)

1
m

i
=
1
m
(
h

(
x
(机器学习
i
)
)

y
(
i
)
)
x
j
(
i
)
j

{
1
,
2

n
}
,
h

(
x
)
=
1
1
+
e

T线性回归方程例题详解
x
\qquad\theta_j := \theta_j(1-\alpha\frac{\lambda}{m})-\alpha\frac{1}{m}\displaystyle\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})x_classification怎么读j^{(i)} \qquad\qquad j\in\{1,2\dots n\} ,\qqu其他垃圾ad h_\theta(x) = \frac{1}{1+e^{-\theta^Tx}}
j​:=j​(1−m​)−其他应收款m1​i=1∑m​(h​(x(i))−y(i))xj(i)​j∈{1,2…n},h​(x)=1+e−Tx1​

}


                                            斯坦福机器学习-第三周(分类,逻辑回归,过度拟合及解决方法)