吴恩达-机器学习(Meachine Learning)-第一周

为了督促自己进行学习,也为了记录一下要点,还为了补充点博客,毕竟这么久没写几篇博客怪不好意思的。
CSDN上有好多比本篇更全面的,本文只做个人记录(从Coursera上复制的),肯定比较简陋,想看更全的笔记请移步别处,我主要的笔记都在iPad上了。

What is Machine Learning?

What is Machine Learning?
Two definitions of Machine Learning are offered. Arthur Samuel described it as: “the field of study that gives computers the ability to learn without being explicitly programmed.” This is an older, informal definition.

Tom Mitchell provides a more modern definition: “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.

In general, any machine learning problem can be assigned to one of two broad classifications:
Supervised learning and Unsupervised learning.

译文(机翻):

什么是机器学习?
给出了机器学习的两个定义。亚瑟·塞缪尔(Arthur Samuel)将其描述为:“赋予计算机学习能力而无需明确编程的研究领域。”这是一个更古老、非正式的定义。
Tom Mitchell提供了一个更为现代的定义:“一个计算机程序据说是从经验E中学习关于某类任务T和性能度量P的知识,如果它在T中的任务性能(用P度量)随着经验E的提高而提高。”

例如:跳棋。

E=玩许多跳棋游戏的经验(经验)
T=跳棋的任务。(任务的目的,想要干什么,达成什么效果)
P=程序赢得下一场比赛的概率。(性能度量,比如正确率、赢的概率)

一般来说,任何机器学习问题都可以分为两大类:
有监督学习(Supervised learning)和无监督学习(Unsupervised learning)。

Supervised Learning

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.

Supervised learning problems are categorized into “regression” and “classification” problems. In a regression problem, we are trying to predict results within a continuous output, meaning that we are trying to map input variables to some continuous function. In a classification problem, we are instead trying to predict results in a discrete output. In other words, we are trying to map input variables into discrete categories.

Example 1:

Given data about the size of houses on the real estate market, try to predict their price. Price as a function of size is a continuous output, so this is a regression problem.
We could turn this example into a classification problem by instead making our output about whether the house “sells for more or less than the asking price.” Here we are classifying the houses based on price into two discrete categories.

Example 2:

(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.

译文(机翻):

有监督学习
在有监督学习中,我们得到一个数据集,并且已经知道我们正确的输出应该是什么样的,有这样一个想法,即输入和输出之间是有关系的。

监督学习问题分为回归问题(Regression)和分类问题(Classification)。
在回归问题中,我们试图在连续输出中预测结果,这意味着我们试图将输入变量映射到某个连续函数。
在分类问题中,我们试图以离散输出预测结果。换句话说,我们试图将输入变量映射到离散的类别中。

例1:

给出房地产市场上房屋面积的数据,试着预测它们的价格。价格作为规模的函数是一个连续输出,所以这是一个回归问题。
我们可以把这个例子转化为一个分类问题,而不是让我们的输出关于房子是否“售价高于或低于要价。”这里我们将基于价格的房子分为两个离散的类别。

例2:

(a) 回归-给定一个人的图片,我们必须根据给定的图片预测他们的年龄
(b) 分类-对于患有肿瘤的患者,我们必须预测肿瘤是恶性的还是良性的。

Unsupervised Learning

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.

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).

译文(机翻):

无监督学习

无监督学习允许我们在处理问题时很少或根本不知道结果应该是什么样子。我们可以从不一定知道变量影响的数据中导出结构。

我们可以根据数据中变量之间的关系对数据进行聚类,从而得出这种结构。

对于无监督学习,没有基于预测结果的反馈。

例子:
聚类:收集1000000个不同的基因,并找到一种方法来自动将这些基因分组,这些基因以某种方式相似,或由不同的变量(如寿命、位置、角色等)相关。
非聚类:“鸡尾酒会算法”,允许您在混乱的环境中查找结构(例如从鸡尾酒会上的网状声音中识别个人的声音和音乐)。

Model Representation

To establish notation for future use, we’ll use x(i) to denote the “input” variables (living area in this example), also called input features, and y(i) to denote the “output” or target variable that we are trying to predict (price). A pair (x(i) , y(i)) is called a training example, and the dataset that we’ll be using to learn—a list of m training examples (x(i) , y(i)); i = 1, . . . , m—is called a training set. Note that the superscript “(i)” in the notation is simply an index into the training set, and has nothing to do with exponentiation. We will also use X to denote the space of input values, and Y to denote 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.

译文(机翻):

为便于将来使用,我们将使用x(i)表示“输入”变量(本例中为居住区),也称为输入特征,以及y(i)表示我们正在预测(价格)的“输出”或目标变量。一对(x(i) , y(i))称为训练示例,我们将使用这个数据集来学习m个训练示例的列表(x(i) , y(i));i = 1, . . . , m称为训练集。注意,符号中的上标“(i)”只是训练集的索引,与指数无关。我们还将使用X表示输入值的空间,使用Y表示输出值的空间。在本例中,X=Y=ℝ.

为了更正式地描述监督学习问题,我们的目标是,给定一个训练集,学习一个函数h:X→ 所以h(x)是对应Y值的“好”预测值。由于历史原因,这个函数h被称为假设。从图片上看,过程如下:

当我们试图预测的目标变量是连续的时,比如在我们的住房例子中,我们称学习问题为回归问题。当y只能取一小部分离散值时(例如,给定居住面积,我们想预测住宅是房子还是公寓),我们称之为分类问题。

Cost Function

We can measure the accuracy of our hypothesis function by using a cost function. This takes an average difference (actually a fancier version of an average) of all the results of the hypothesis with inputs from x’s and the actual output y’s.

在这里插入图片描述

译文(机翻):

我们可以通过使用代价函数来衡量假设函数的准确性。这取所有假设结果的平均差(实际上是平均值的一个更高级的版本),输入x和实际输出y。

这个函数又称为“平方误差函数”或“均方误差”。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
右上图为等高线图
等高线图是包含许多等高线的图形。二元函数的等高线在同一直线的所有点上都有一个常数。右上的图就是这样一个例子。

在这里插入图片描述
取任何颜色,沿着“圆”走,都可以得到相同的代价函数值。例如,上面绿线上的三个绿点具有相同的J值。

在这里插入图片描述

Gradient Descent

So we have our hypothesis function and we have a way of measuring how well it fits into the data. Now we need to estimate the parameters in the hypothesis function. That’s where gradient descent comes in.

Imagine that we graph our hypothesis function based on its fields θ0 and θ1 (actually we are graphing the cost function as a function of the parameter estimates). We are not graphing x and y itself, but the parameter range of our hypothesis function and the cost resulting from selecting a particular set of parameters.

We put θ0 on the x axis and θ1 on the y axis, with the cost function on the vertical z axis. The points on our graph will be the result of the cost function using our hypothesis with those specific theta parameters. The graph below depicts such a setup.
在这里插入图片描述
We will know that we have succeeded when our cost function is at the very bottom of the pits in our graph, i.e. when its value is the minimum. The red arrows show the minimum points in the graph.

The way we do this is by taking the derivative (the tangential line to a function) of our cost function. The slope of the tangent is the derivative at that point and it will give us a direction to move towards. We make steps down the cost function in the direction with the steepest descent. The size of each step is determined by the parameter α, which is called the learning rate.

For example, the distance between each ‘star’ in the graph above represents a step determined by our parameter α. A smaller α would result in a smaller step and a larger α results in a larger step. The direction in which the step is taken is determined by the partial derivative of J(θ0,θ1). Depending on where one starts on the graph, one could end up at different points. The image above shows us two different starting points that end up in two different places.

在这里插入图片描述
At each iteration j, one should simultaneously update the parameters θ1,θ2,…,θn. Updating a specific parameter prior to calculating another one on the j(th) iteration would yield to a wrong implementation.
在这里插入图片描述
In this video we explored the scenario where we used one parameter θ1and plotted its cost function to implement a gradient descent. Our formula for a single parameter was :

在这里插入图片描述

翻译(机翻):

所以我们有我们的假设函数,我们有一种方法来衡量它与数据的吻合程度。现在我们需要估计假设函数中的参数。这就是梯度下降的原因。

假设我们根据假设函数的域θ0和θ1来绘制假设函数(实际上,我们将代价函数绘制为参数估计的函数)。我们画的不是x和y本身,而是假设函数的参数范围和选择一组特定参数所产生的代价。

我们将θ0放在x轴上,将θ1放在y轴上,将代价函数放在竖直的z轴上。图上的点将是使用我们的假设和那些特定θ参数的代价函数的结果。下图描述了这种设置。

我们将知道,当我们的代价函数在我们的图中最底部时,即当它的值最小时,我们就成功求得所需要的值。红色箭头表示图中的最小点。

我们做这件事的方法是取代价函数的导数(函数的切线)。切线的斜率是这一点的导数,它会给我们一个移动的方向。我们沿着下降最快的方向逐步降低成本函数。每个步骤的大小由参数确定α, 这就是学习率。

例如,上图中每个“星”之间的距离表示由参数确定的步长α. 较小的α 将导致更小的步骤,而更大的α 结果是更大的一步。每步前进方的向由J(θ0,θ1)的偏导数决定. 根据在图形上的不同的起始位置,它可能会在不同的点结束。上图向我们展示了两个不同的起点,最终在两个不同的地方结束。

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

在本视频中,我们探讨了使用一个参数θ1的场景并绘制其代价函数以实现梯度下降。我们的含一个单一参数公式是:

在这里插入图片描述

不管偏导数斜率的符号是正还是负,θ1最终都会收敛到最小值。下图显示了当坡度为负时θ1增加,当它为正时θ1减少。

接下来说明学习率α的选择:
在这里插入图片描述
另一方面,我们应该调整参数α来保证梯度下降算法在合理的时间内收敛。没有收敛或太多的时间来获得最小值意味着我们的步长是错误的。

若α太小,则梯度下降会非常缓慢;相反若α太大,则梯度下降会越过最小值,导致不能收敛或者发散。

在这里插入图片描述
收敛背后的直观显示就是随着我们到达凸函数的底部,导数取值接近0。在最小值点,导数始终为0,因此我们得到上式。

梯度下降可以收敛到一个局部最小值,即使是学习率α固定的情况下。

随着我们到达一个局部最小值点,梯度下降自动地采用更小的步长,所以不需要随着时间增加学习率α的大小。

在这里插入图片描述
当具体应用于线性回归时,可以导出一种新形式的梯度下降方程。我们可以替换实际代价函数和实际假设函数,并将方程修改为上述式子。其中m是训练集的大小,θ0是一个常数,它将与θ1同时改变,x,y是给定训练集中的数据。

在这里插入图片描述
所有这一切的关键是,如果我们从我们的假设开始猜测,然后反复应用这些梯度下降方程,我们的假设将变得越来越准确。

所以,这就是在原代价函数J上的梯度下降。这种方法在每一步上都会查看整个训练集中的每个示例,称为Batch梯度下降法。注意,虽然梯度下降通常容易受到局部极小值的影响,但我们在这里提出的线性回归优化问题只有一个全局最优值,没有其他局部最优值;因此梯度下降总是收敛(假设学习率α 不太大)到全局最小值。实际上,J是一个凸二次函数。这里是一个梯度下降的例子,因为它是运行最小化二次函数。

在这里插入图片描述
上面显示的椭圆是二次函数的轮廓。图中还显示了梯度下降的轨迹,其初始值为(48,30)。图中的x(由直线连接)表示θ 当它收敛到最小值时,梯度下降就发生了。

Matrices and Vectors

矩阵和向量基本要点:
在这里插入图片描述
在这里插入图片描述
加法和减法是按元素进行的,因此只需对每个相应的元素进行加法或减法

要加或减两个矩阵,它们的维数必须相同:
在这里插入图片描述

在标量乘法中,我们只需将每个元素乘以标量值;在标量除法中,我们只需将每个元素除以标量值:
在这里插入图片描述

在这里插入图片描述
一个m×n的矩阵乘以一个n×1的向量,结果是一个m×1的向量

矩阵的列数必须等于向量的行数

在这里插入图片描述
一个m×n的矩阵乘以一个n×o的矩阵,结果是一个m×o的矩阵

要将两个矩阵相乘,第一个矩阵的列数必须等于第二个矩阵的行数

在这里插入图片描述
矩阵乘法的性质:
一般地,有 A∗B≠ B∗A;(A∗B)∗C = A∗(B∗C);

单位矩阵:当单位矩阵与任何具有相同维数的矩阵相乘时,得到原始矩阵。就像数字乘以1一样,单位矩阵的对角线上只有1(从左上到右下对角线),其他地方只有0。

在这里插入图片描述
当在某个矩阵(A)之后乘以单位矩阵时(A∗I) ,平方恒等矩阵的维数应与其他矩阵的列匹配。当将单位矩阵乘以其他矩阵(I∗A) ,平方恒等矩阵的维数应与其他矩阵的行相匹配。

在这里插入图片描述

矩阵A的逆矩阵是A-1,二者相乘就是单位矩阵。

非方阵没有逆矩阵。我们可以在octave中用pinv(A)函数计算矩阵的逆,在Matlab中用inv(A)函数计算矩阵的逆。没有逆的矩阵是奇异的或退化的。

矩阵的转置类似于将矩阵顺时针旋转90度° ,然后反转。我们可以在matlab中用transpose(A)函数或A’计算矩阵的转置。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值