码迷,mamicode.com
首页 > 系统相关 > 详细

《Machine Learning》系列学习笔记之第一周

时间:2017-01-29 16:14:08      阅读:611      评论:0      收藏:0      [点我收藏+]

标签:ar9   ova   pwc   ejs   ffd   pvc   owa   dwz   mib   

《Machine Learning》系列学习笔记

第一周

第一部分 Introduction

The definition of machine learning

(1)older, informal definition——Arthur Samuel——"the field of study that gives computers the ability to learn without being explicitly programmed."

(2)modern definition ——Tom Mitchell——"A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E."

Example: playing checkers.

E = the experience of playing many games of checkers

T = the task of playing checkers.

P = the probability that the program will win the next game.

The classification of machine learning

(1)Supervised learning

(2)Unsupervised learning.

 


Supervised Learning

The definition of supervised learning

In supervised learning, we are given a data set and already know what our correct output should look like, having the idea that there is a relationship between the input and the output.

The classification of supervised learning

(1)regression——map input variables to some continuous function.

(2)classification——map input variables into discrete categories

Example:

(a) Regression - Given a picture of a person, we have to predict their age on the basis of the given picture

(b) Classification - Given a patient with a tumor, we have to predict whether the tumor is malignant or benign.



The definition of unsupervised learning

Unsupervised learning allows us to approach problems with little or no idea what our results should look like. We can derive structure from data where we don‘t necessarily know the effect of the variables.

We can derive this structure by clustering the data based on relationships among the variables in the data.

With unsupervised learning there is no feedback based on the prediction results.

The classification of unsupervised learning

(1)Clustering

(2)Non-clustering

Example:

Clustering: Take a collection of 1,000,000 different genes, and find a way to automatically group these genes into groups that are somehow similar or related by different variables, such as lifespan, location, roles, and so on.

Non-clustering: The "Cocktail Party Algorithm", allows you to find structure in a chaotic environment. (i.e. identifying individual voices and music from a mesh of sounds at a cocktail party).



第二部分 Model and Cost Function

Model Representation

 x(i)——“input” variables (living area in this example), also called input features

 y(i)——“output” or target variable

 A pair (x(i),y(i))——a training example

 training examples (x(i),y(i));i=1,...,m——training set

(i)——an index into the training set

X——the space of input values

Y——the space of output values

In this example, X = Y = ?.

 

To describe the supervised learning problem slightly more formally, our goal is, given a training set, to learn a function h : X → Y so that h(x) is a “good” predictor for the corresponding value of y. For historical reasons, this function h is called a hypothesis. Seen pictorially, the process is therefore like this:

技术分享

When the target variable that we’re trying to predict is continuous, such as in our housing example, we call the learning problem a regression problem.

When y can take on only a small number of discrete values (such as if, given the living area, we wanted to predict if a dwelling is a house or an apartment, say), we call it a classification problem.




Cost Function

cost function("Squared error function"or "Mean squared error")——measure the accuracy of our hypothesis function.

 J(θ0,θ1)=12mi=1m(y^i?yi)2=12mi=1m(hθ(xi)?yi)2

 

The following image summarizes what the cost function does:

技术分享





Cost Function - Intuition I

如果我们试图在视觉术语中考虑它,我们的训练数据集散布在x-y平面上。 我们试图建立一条通过这些散射数据点的直线(由hθ(x)定义)。

我们的目标是获得最好的线。 最佳可能的线将是这样的,使得散射点与线的平均平方垂直距离将是最小的。 理想情况下,线应该通过我们训练数据集的所有点。 在这种情况下,J(θ0,θ1)的值将为0.以下示例显示了我们的成本函数为0的理想情况。

技术分享

当θ1= 1时,我们得到一个斜率为1,它经过我们模型中的每一个数据点。 相反,当θ1= 0.5时,我们看到从我们的拟合到数据点的垂直距离增加。

技术分享

This increases our cost function to 0.58. Plotting several other points yields to the following graph:

技术分享

 as a goal, we should try to minimize the cost function. In this case, θ1=1 is our global minimum.





Cost Function - Intuition II

等高线图是包含许多轮廓线的图。 两个可变函数的轮廓线在同一线的所有点处具有恒定值。 这样的图的示例是下面的一个。

技术分享

以任何颜色和沿着“圆”,人们将期望获得相同的成本函数值。 例如,在上面绿色线上找到的三个绿点具有与J(θ0,θ1)相同的值,因此,它们沿着相同的线找到。 当θ0= 800且θ1= -0.15时,圆圈x显示左侧图形的成本函数的值。 取另一个h(x)并绘制其等值线图,得到以下图表:

 

技术分享

 

当θ0= 360且θ1= 0时,轮廓图中的J(θ0,θ1)的值更接近中心,从而降低成本函数误差。 现在给我们的假设函数稍微正的斜率导致更好的数据拟合。

技术分享

上面的图表尽可能最小化成本函数,因此,θ1和θ0的结果分别趋向于大约0.12和250。 在右边的图形上绘制这些值似乎将我们的点放在最内圈的中心。

 

第三部分 Parameter Learning

 

Gradient Descent

因此,我们有我们的假设函数,我们有一个方法来衡量它是否适合数据。 现在我们需要估计假设函数中的参数。 这就是梯度下降的来源。

想象一下,我们基于其领域θ0和θ1绘制我们的假设函数(实际上我们将成本函数绘制为参数估计的函数)。 我们不是绘制x和y本身,而是我们的假设函数的参数范围和从选择一组特定的参数得到的成本。

我们把θ0放在x轴上,把θ1放在y轴上,成本函数放在垂直z轴上。 我们的图上的点将是使用具有那些特定θ参数的我们的假设的成本函数的结果。 下图描绘了这样的设置。

技术分享

我们将知道,当我们的成本函数在图中的凹坑的最底部时,即当它的值是最小值时,我们已经成功。 红色箭头显示图中的最小点。

我们这样做的方式是通过我们的成本函数的导数(一个函数的切线)。 切线的斜率是在该点的导数,它将给我们移动的方向。 我们在最陡下降的方向上逐步降低成本函数。 每个步骤的大小由参数α确定,其被称为学习速率。

例如,上图中每个“星”之间的距离代表由我们的参数α确定的步长。 较小的α将导致较小的阶跃,较大的α导致较大的阶跃。 通过J(θ0,θ1)的偏导数来确定采取步骤的方向。 根据图表上的起始位置,可以在不同的点结束。 上图显示了两个不同的起点,分别位于两个不同的地方。

梯度下降算法是:

重复直到收敛:

 θj:=θj?α??θjJ(θ0,θ1),j = 0,1表示特征索引号。

在每次迭代j时,应该同时更新参数θ1,θ2,...,θn。 在第j次迭代计算另一个参数之前更新特定参数将导致错误的实现。

技术分享



Gradient Descent Intuition

在这个视频中,我们探索了一个场景,其中我们使用一个参数θ1,并绘制其成本函数来实现梯度下降。 我们对单个参数的公式是:

重复直到收敛:

 θ1:=θ1?αd/dθ1J(θ1)

不管ddθ1J(θ1)的斜率的符号如何,θ1最终收敛到其最小值。 下面的曲线图示出了当斜率为负时,θ1的值增加,而当其为正时,θ1的值减小。

技术分享

在一个侧面说明,我们应该调整我们的参数α,以保证梯度下降算法在合理的时间收敛。失败会聚或太多的时间来获得的最小值意味着我们的步长大小是错误的。

技术分享

梯度下降如何以固定步长收敛α

收敛后的直觉是当我们接近我们的凸函数的底部时,ddθ1J(θ1)接近0。 至少,导数将始终为0,因此我们得到:

 

θ1:=θ1?α?0

技术分享

 

Gradient Descent For Linear Regression

Note: [At 6:15 "h(x) = -900 - 0.1x" should be "h(x) = 900 - 0.1x"]

当具体应用于线性回归的情况下,可以导出梯度下降方程的新形式。 我们可以替换我们的实际成本函数和我们的实际假设函数,并将公式修改为:

 repeat until convergence: {

 θ0:=θ0?α1mi=1m(hθ(xi)?yi)

θ1:=θ1?α1mi=1m((hθ(xi)?yi)xi)

 }

 

其中m是训练集的大小,θ0是将与θ1同时改变的常数,xi,yi是给定训练集(数据)的值。

注意,我们已经将θj的两种情况分离为θ0和θ1的单独方程; 并且对于θ1,由于导数,我们在末端乘以xi。 以下是单个示例的??θjJ(θ)的推导:

技术分享

这一切的要点是,如果我们开始猜测我们的假设,然后重复应用这些梯度下降方程,我们的假设将变得越来越准确。

因此,这是对原始成本函数J的简单梯度下降。该方法查看每个步骤的整个训练集中的每个示例,并且称为批量梯度下降。 注意,虽然梯度下降通常易受局部最小值的影响,但我们在这里提出的用于线性回归的优化问题只有一个全局优化问题,没有其他局部优化问题; 因此梯度下降总是收敛(假设学习速率α不太大)到全局最小值。 实际上,J是凸二次函数。 这里是梯度下降的例子,因为它运行以最小化二次函数。

《Machine Learning》系列学习笔记

第一周

第一部分 Introduction

The definition of machine learning

(1)older, informal definition——Arthur Samuel——"the field of study that gives computers the ability to learn without being explicitly programmed."

(2)modern definition ——Tom Mitchell——"A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E."

Example: playing checkers.

E = the experience of playing many games of checkers

T = the task of playing checkers.

P = the probability that the program will win the next game.

The classification of machine learning

(1)Supervised learning

(2)Unsupervised learning.

 


Supervised Learning

The definition of supervised learning

In supervised learning, we are given a data set and already know what our correct output should look like, having the idea that there is a relationship between the input and the output.

The classification of supervised learning

(1)regression——map input variables to some continuous function.

(2)classification——map input variables into discrete categories

Example:

(a) Regression - Given a picture of a person, we have to predict their age on the basis of the given picture

(b) Classification - Given a patient with a tumor, we have to predict whether the tumor is malignant or benign.



The definition of unsupervised learning

Unsupervised learning allows us to approach problems with little or no idea what our results should look like. We can derive structure from data where we don‘t necessarily know the effect of the variables.

We can derive this structure by clustering the data based on relationships among the variables in the data.

With unsupervised learning there is no feedback based on the prediction results.

The classification of unsupervised learning

(1)Clustering

(2)Non-clustering

Example:

Clustering: Take a collection of 1,000,000 different genes, and find a way to automatically group these genes into groups that are somehow similar or related by different variables, such as lifespan, location, roles, and so on.

Non-clustering: The "Cocktail Party Algorithm", allows you to find structure in a chaotic environment. (i.e. identifying individual voices and music from a mesh of sounds at a cocktail party).



第二部分 Model and Cost Function

Model Representation

 x(i)——“input” variables (living area in this example), also called input features

 y(i)——“output” or target variable

 A pair (x(i),y(i))——a training example

 training examples (x(i),y(i));i=1,...,m——training set

(i)——an index into the training set

X——the space of input values

Y——the space of output values

In this example, X = Y = ?.

 

To describe the supervised learning problem slightly more formally, our goal is, given a training set, to learn a function h : X → Y so that h(x) is a “good” predictor for the corresponding value of y. For historical reasons, this function h is called a hypothesis. Seen pictorially, the process is therefore like this:

技术分享

When the target variable that we’re trying to predict is continuous, such as in our housing example, we call the learning problem a regression problem.

When y can take on only a small number of discrete values (such as if, given the living area, we wanted to predict if a dwelling is a house or an apartment, say), we call it a classification problem.




Cost Function

cost function("Squared error function"or "Mean squared error")——measure the accuracy of our hypothesis function.

 J(θ0,θ1)=12mi=1m(y^i?yi)2=12mi=1m(hθ(xi)?yi)2

 

The following image summarizes what the cost function does:

技术分享





Cost Function - Intuition I

如果我们试图在视觉术语中考虑它,我们的训练数据集散布在x-y平面上。 我们试图建立一条通过这些散射数据点的直线(由hθ(x)定义)。

我们的目标是获得最好的线。 最佳可能的线将是这样的,使得散射点与线的平均平方垂直距离将是最小的。 理想情况下,线应该通过我们训练数据集的所有点。 在这种情况下,J(θ0,θ1)的值将为0.以下示例显示了我们的成本函数为0的理想情况。

技术分享

当θ1= 1时,我们得到一个斜率为1,它经过我们模型中的每一个数据点。 相反,当θ1= 0.5时,我们看到从我们的拟合到数据点的垂直距离增加。

技术分享

This increases our cost function to 0.58. Plotting several other points yields to the following graph:

技术分享

 as a goal, we should try to minimize the cost function. In this case, θ1=1 is our global minimum.





Cost Function - Intuition II

等高线图是包含许多轮廓线的图。 两个可变函数的轮廓线在同一线的所有点处具有恒定值。 这样的图的示例是下面的一个。

技术分享

以任何颜色和沿着“圆”,人们将期望获得相同的成本函数值。 例如,在上面绿色线上找到的三个绿点具有与J(θ0,θ1)相同的值,因此,它们沿着相同的线找到。 当θ0= 800且θ1= -0.15时,圆圈x显示左侧图形的成本函数的值。 取另一个h(x)并绘制其等值线图,得到以下图表:

 

技术分享

 

当θ0= 360且θ1= 0时,轮廓图中的J(θ0,θ1)的值更接近中心,从而降低成本函数误差。 现在给我们的假设函数稍微正的斜率导致更好的数据拟合。

技术分享

上面的图表尽可能最小化成本函数,因此,θ1和θ0的结果分别趋向于大约0.12和250。 在右边的图形上绘制这些值似乎将我们的点放在最内圈的中心。

 

第三部分 Parameter Learning

 

Gradient Descent

因此,我们有我们的假设函数,我们有一个方法来衡量它是否适合数据。 现在我们需要估计假设函数中的参数。 这就是梯度下降的来源。

想象一下,我们基于其领域θ0和θ1绘制我们的假设函数(实际上我们将成本函数绘制为参数估计的函数)。 我们不是绘制x和y本身,而是我们的假设函数的参数范围和从选择一组特定的参数得到的成本。

我们把θ0放在x轴上,把θ1放在y轴上,成本函数放在垂直z轴上。 我们的图上的点将是使用具有那些特定θ参数的我们的假设的成本函数的结果。 下图描绘了这样的设置。

技术分享

我们将知道,当我们的成本函数在图中的凹坑的最底部时,即当它的值是最小值时,我们已经成功。 红色箭头显示图中的最小点。

我们这样做的方式是通过我们的成本函数的导数(一个函数的切线)。 切线的斜率是在该点的导数,它将给我们移动的方向。 我们在最陡下降的方向上逐步降低成本函数。 每个步骤的大小由参数α确定,其被称为学习速率。

例如,上图中每个“星”之间的距离代表由我们的参数α确定的步长。 较小的α将导致较小的阶跃,较大的α导致较大的阶跃。 通过J(θ0,θ1)的偏导数来确定采取步骤的方向。 根据图表上的起始位置,可以在不同的点结束。 上图显示了两个不同的起点,分别位于两个不同的地方。

梯度下降算法是:

重复直到收敛:

 θj:=θj?α??θjJ(θ0,θ1),j = 0,1表示特征索引号。

在每次迭代j时,应该同时更新参数θ1,θ2,...,θn。 在第j次迭代计算另一个参数之前更新特定参数将导致错误的实现。

技术分享



Gradient Descent Intuition

在这个视频中,我们探索了一个场景,其中我们使用一个参数θ1,并绘制其成本函数来实现梯度下降。 我们对单个参数的公式是:

重复直到收敛:

 θ1:=θ1?αd/dθ1J(θ1)

不管ddθ1J(θ1)的斜率的符号如何,θ1最终收敛到其最小值。 下面的曲线图示出了当斜率为负时,θ1的值增加,而当其为正时,θ1的值减小。

技术分享

在一个侧面说明,我们应该调整我们的参数α,以保证梯度下降算法在合理的时间收敛。失败会聚或太多的时间来获得的最小值意味着我们的步长大小是错误的。

技术分享

梯度下降如何以固定步长收敛α

收敛后的直觉是当我们接近我们的凸函数的底部时,ddθ1J(θ1)接近0。 至少,导数将始终为0,因此我们得到:

 

θ1:=θ1?α?0

技术分享

 

Gradient Descent For Linear Regression

Note: [At 6:15 "h(x) = -900 - 0.1x" should be "h(x) = 900 - 0.1x"]

当具体应用于线性回归的情况下,可以导出梯度下降方程的新形式。 我们可以替换我们的实际成本函数和我们的实际假设函数,并将公式修改为:

 repeat until convergence: {

 θ0:=θ0?α1mi=1m(hθ(xi)?yi)

θ1:=θ1?α1mi=1m((hθ(xi)?yi)xi)

 }

 

其中m是训练集的大小,θ0是将与θ1同时改变的常数,xi,yi是给定训练集(数据)的值。

注意,我们已经将θj的两种情况分离为θ0和θ1的单独方程; 并且对于θ1,由于导数,我们在末端乘以xi。 以下是单个示例的??θjJ(θ)的推导:

技术分享

这一切的要点是,如果我们开始猜测我们的假设,然后重复应用这些梯度下降方程,我们的假设将变得越来越准确。

因此,这是对原始成本函数J的简单梯度下降。该方法查看每个步骤的整个训练集中的每个示例,并且称为批量梯度下降。 注意,虽然梯度下降通常易受局部最小值的影响,但我们在这里提出的用于线性回归的优化问题只有一个全局优化问题,没有其他局部优化问题; 因此梯度下降总是收敛(假设学习速率α不太大)到全局最小值。 实际上,J是凸二次函数。 这里是梯度下降的例子,因为它运行以最小化二次函数。

技术分享

上面显示的椭圆是二次函数的轮廓。 还示出了由梯度下降采取的轨迹,其在(48,30)处被初始化。 图中的x(用直线连接)标记梯度下降经过的连续值,因为它收敛到其最小值。

上面显示的椭圆是二次函数的轮廓。 还示出了由梯度下降采取的轨迹,其在(48,30)处被初始化。 图中的x(用直线连接)标记梯度下降经过的连续值,因为它收敛到其最小值。

《Machine Learning》系列学习笔记之第一周

标签:ar9   ova   pwc   ejs   ffd   pvc   owa   dwz   mib   

原文地址:http://www.cnblogs.com/flippedkiki/p/6357519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!