【2022吴恩达机器学习课程视频翻译笔记】3.3代价函数公式

news2024/10/5 21:25:44

忙了一阵子,回来继续更新

3.3 代价函数公式

In order to implement linear regression. The first key step is first to define something called a cost function. This is something we’ll build in this video, and the cost function will tell us how well the model is doing so that we can try to get it to do better. Let’s look at what this means.
为了实现线性回归,第一个关键步骤是先定义一个叫作代价函数的东西。在此视频中,我们将构建这个代价函数,代价函数将告诉我们模型的表现如何,以便我们可以尝试使模型变得更好。让我们看看代价函数是什么意思。

Recall that you have a training set that contains input features x and output targets y. The model you’re going to use to fit this training set is this linear function f_w, b of x equals to w times x plus b. To introduce a little bit more terminology the w and b are called the parameters of the model.
回想一下,你有一个包含输入特征 x 和输出目标 y 的训练集。你要使用的模型是用来将这个训练集的数据拟合为一个线性函数 f w , b ( x ) = w x + b f_{w,b}(x)=wx+b fw,b(x)=wx+b。为了描述的更专业一些,我们将 w w w b b b 称为模型的参数。

In machine learning parameters of the model are the variables you can adjust during training in order to improve the model. Sometimes you also hear the parameters w and b referred to as coefficients or as weights. Now let’s take a look at what these parameters w and b do.
在机器学习中,模型的参数是可以在训练过程中进行调整以改善模型性能的变量。有时你也会听到参数 w w w b b b 被称为系数或权重。现在让我们来看看这些参数 w w w b b b 的作用。

Depending on the values you’ve chosen for w and b you get a different function f of x, which generates a different line on the graph. Remember that we can write f of x as a shorthand for f_w, b of x. We’re going to take a look at some plots of f of x on a chart.
根据所选择的 w w w b b b 的值,你会得到一个不同的函数 f ( x ) f(x) f(x),这将在图表上生成一条不同的线。记住,我们可以用 f ( x ) f(x) f(x)来简写 f w , b ( x ) f_{w, b}(x) fw,b(x)。接下来,我们将看一些 f ( x ) f(x) f(x) 在图表上的绘图。

Maybe you’re already familiar with drawing lines on charts, but even if this is a review for you, I hope this will help you build intuition on how w and b the parameters determine f. When w is equal to 0 and b is equal to 1.5, then f looks like this horizontal line. In this case, the function f of x is 0 times x plus 1.5 so f is always a constant value. It always predicts 1.5 for the estimated value of y. Y hat is always equal to b and here b is also called the y intercept because that’s where it crosses the vertical axis or the y axis on this graph.
也许你已经熟悉在图表上绘制线条,但即使这对你来说是复习,我希望这能帮助你建立如何用参数 w w w b b b 确定函数 f f f的直觉。当 w = 0 w=0 w=0 b = 1.5 b=1.5 b=1.5时,函数 f f f 就像是一条水平线。在这种情况下,函数 f ( x ) = 0 × x + 1.5 f(x)=0\times x+1.5 f(x)=0×x+1.5 ,因此 f f f 始终是一个常数值。它总是对估计的 y y y 值预测为 1.5。 y ^ = b \hat y=b y^=b,而在这里 b b b也被称为 y y y截距(y intercept),因为它是函数在图表上穿过垂直轴或y轴的位置。

As a second example, if w is 0.5 and b is equal 0, then f of x is 0.5 times x. When x is 0, the prediction is also 0, and when x is 2, then the prediction is 0.5 times 2, which is 1. You get a line that looks like this and notice that the slope is 0.5 divided by 1. The value of w gives you the slope of the line, which is 0.5.
作为第二个示例,如果 w = 0.5 w=0.5 w=0.5 b = 0 b=0 b=0,那么 f ( x ) = 0.5 x f(x)=0.5x f(x)=0.5x. 当 x = 0 x=0 x=0时,预测值也为0,当 x = 2 x=2 x=2时,预测值就是 0.5 × 2 = 1 0.5\times 2=1 0.5×2=1. 你会得到一条看起来像这样的线,并且注意到斜率是 0.5 1 \frac{0.5}{1} 10.5。而 w w w的值给出了线条的斜率,也就是0.5。

Finally, if w equals 0.5 and b equals 1, then f of x is 0.5 times x plus 1 and when x is 0, then f of x equals b, which is 1 so the line intersects the vertical axis at b, the y intercept. Also when x is 2, then f of x is 2, so the line looks like this. Again, this slope is 0.5 divided by 1 so the value of w gives you the slope which is 0.5.
最后,如果 w = 0.5 w=0.5 w=0.5 b = 1 b=1 b=1,那么 f ( x ) = 0.5 x + 1 f(x)=0.5x+1 f(x)=0.5x+1. 当 x = 0 x=0 x=0时, f ( x ) = b f(x)=b f(x)=b,也就是1,因此线条与垂直轴在b处相交,即y截距。此外,当 x = 2 x=2 x=2时, f ( x ) = 2 f(x)=2 f(x)=2,因此线条呈现如下形状。同样,这个斜率是 0.5 1 \frac{0.5}{1} 10.5,因此 w w w的值给出了斜率,即0.5。

Recall that you have a training set like the one shown here. With linear regression, what you want to do is to choose values for the parameters w and b so that the straight line you get from the function f somehow fits the data well. Like maybe this line shown here.
回想一下,你有一个类似于这里展示的训练集。

在线性回归中,你希望选择参数 w w w b b b的值,使得由函数f生成的直线与数据相拟合得较好,就像这里展示的这条线一样。

When I see that the line fits the data visually, you can think of this to mean that the line defined by f is roughly passing through or somewhere close to the training examples as compared to other possible lines that are not as close to these points. Just to remind you of some notation, a training example like this point here is defined by x superscript i, y superscript i where y is the target.
当我看到直线在视觉上与数据拟合时,你可以这样理解,相对于其他可能不太接近这些点的直线,由函数 f f f所定义的直线大致通过或接近于训练样本组成的集合。再次提醒一下符号的表示,像这个点一样的训练样本被定义为 x ( i ) x^{(i)} x(i) y ( i ) y^{(i)} y(i),其中 y y y是目标值。

For a given input x^i, the function f also makes a predictive value for y and a value that it predicts to y is y hat i shown here. For our choice of a model f of x^i is w times x^i plus b. Stated differently, the prediction y hat i is f of wb of x^i where for the model we’re using f of x^i is equal to wx^i plus b.
对于给定的输入 x ( i ) x^{(i)} x(i),函数 f f f还会对 y y y有一个预测的值,表示为 y ^ ( i ) \hat y^{(i)} y^(i)。我们选择的模型 f f f对于输入 x ( i ) x^{(i)} x(i)的表达式是 f ( x ) = w x ( i ) + b f(x)=wx^{(i)}+b f(x)=wx(i)+b. 换句话说,预测值 y ^ ( i ) \hat y^{(i)} y^(i)可以表示为 y ^ ( i ) = f w , b ( x ( i ) ) \hat y^{(i)}=f_{w,b}(x^{(i)}) y^(i)=fw,b(x(i)),其中对于我们使用的模型, f w , b ( x ( i ) ) = w x ( i ) + b f_{w,b}(x^{(i)})=wx^{(i)}+b fw,b(x(i))=wx(i)+b.

Now the question is how do you find values for w and b so that the prediction y hat i is close to the true target y^i for many or maybe all training examples x^i, y^i. To answer that question, let’s first take a look at how to measure how well a line fits the training data. To do that, we’re going to construct a cost function.
现在的问题是如何找到参数 w w w b b b的值,使得对于许多或者所有的训练样本 x ( i ) x^{(i)} x(i) y ( i ) y^{(i)} y(i),预测值 y ^ ( i ) \hat y^{(i)} y^(i)与真实目标值 y ( i ) y^{(i)} y(i)接近。为了回答这个问题,让我们首先看一下如何衡量一条直线对训练数据的拟合程度。为此,我们将构建一个代价函数(cost function)。

The cost function takes the prediction y hat and compares it to the target y by taking y hat minus y. This difference is called the error, we’re measuring how far off to prediction is from the target. Next, let’s computes the square of this error. Also, we’re going to want to compute this term for different training examples i in the training set. When measuring the error, for example i, we’ll compute this squared error term.
代价函数将预测值 y ^ \hat y y^与真实的目标值 y y y进行比较,通过计算 y ^ − y \hat y-y y^y得到一个差值。这个差值被称为误差(error),我们测量了预测值与目标值之间的偏差大小。接下来,我们会计算这个误差的平方。同时,对于训练集中的第 i i i个样本,我们需要计算每个样本的预测值和真实值之间的误差。当我们计算误差时,比如,对于第 i i i个训练样本,我们将计算这个平方误差项 y ^ ( i ) − y ( i ) \hat y^{(i)}-y^{(i)} y^(i)y(i).

Finally, we want to measure the error across the entire training set. In particular, let’s sum up the squared errors like this. We’ll sum from i equals 1,2, 3 all the way up to m and remember that m is the number of training examples, which is 47 for this dataset.
最后,我们希望衡量整个训练集上的误差。具体而言,我们将按照如下方式将这些平方误差求和,即 ∑ i = 1 m ( y ^ ( i ) − y ( i ) ) 2 \displaystyle \sum_{i=1}^{m}(\hat y^{(i)}-y^{(i)})^{2} i=1m(y^(i)y(i))2,需要记住 m m m是训练样本的数量,对于这个数据集来说 m = 47 m=47 m=47

Notice that if we have more training examples m is larger and your cost function will calculate a bigger number. This is summing over more examples. To build a cost function that doesn’t automatically get bigger as the training set size gets larger by convention, we will compute the average squared error instead of the total squared error and we do that by dividing by m like this.
请注意,如果我们有更多的训练样本,即m更大,那么你的代价函数会计算一个更大的数值。这是因为我们对更多的样本进行求和操作。为了构建一个无论训练集大小如何都不会自动增大的代价函数,我们通常计算平均平方误差而不是总平方误差,这可以通过除以 m m m来实现,如下所示。

We’re nearly there. Just one last thing. By convention, the cost function that machine learning people use actually divides by 2 times m. The extra division by 2 is just meant to make some of our later calculations look neater, but the cost function still works whether you include this division by 2 or not. This expression right here is the cost function and we’re going to write J of wb to refer to the cost function. This is also called the squared error cost function, and it’s called this because you’re taking the square of these error terms.
我们快要完成了,只剩下最后一点。按照惯例,机器学习中使用的代价函数实际上会除以2倍的m。这额外的除以2只是为了使我们后面的计算更加简洁,但无论是否包括这个除以2,代价函数仍然有效。这个表达式就是代价函数,即 1 2 m ∑ i = 1 m ( y ^ ( i ) − y ( i ) ) 2 \frac{1}{2m} \displaystyle \sum_{i=1}^{m}(\hat y^{(i)}-y^{(i)})^{2} 2m1i=1m(y^(i)y(i))2,我们将用 J ( w , b ) = 1 2 m ∑ i = 1 m ( y ^ ( i ) − y ( i ) ) 2 J(w,b)=\frac{1}{2m} \displaystyle \sum_{i=1}^{m}(\hat y^{(i)}-y^{(i)})^{2} J(w,b)=2m1i=1m(y^(i)y(i))2表示损失函数。这个损失函数也被称为平方误差代价函数,因为它对这些误差项取平方。

In machine learning different people will use different cost functions for different applications, but the squared error cost function is by far the most commonly used one for linear regression and for that matter, for all regression problems where it seems to give good results for many applications. Just as a reminder, the prediction y hat is equal to the outputs of the model f at x.
在机器学习中,不同的人会根据不同的应用选择不同的代价函数,但是对于线性回归以及其他许多回归问题来说,平方误差代价函数是最常用的。这个代价函数在许多应用中都能给出良好的结果。提醒一下,预测值 y ^ ( i ) \hat y^{(i)} y^(i)等于模型 f f f在输入 x x x上的输出结果。

We can rewrite the cost function J of wb as 1 over 2m times the sum from i equals 1 to m of f of x^i minus y^i the quantity squared.
我们可以将损失函数 J ( w , b ) J(w,b) J(w,b)重写为 J ( w , b ) = 1 2 m ∑ i = 1 m ( f ( x ( i ) ) − y ( i ) ) 2 J(w,b)=\frac{1}{2m}\displaystyle \sum_{i=1}^{m} \left(f(x^{(i)})-y^{(i)}\right)^2 J(w,b)=2m1i=1m(f(x(i))y(i))2


Eventually we’re going to want to find values of w and b that make the cost function small.
最后,我们要找到使代价函数最小的 w w w b b b.

But before going there, let’s first gain more intuition about what J of wb is really computing.
在深入探讨之前,让我们首先更好地理解 J ( w , b ) J(w,b) J(w,b)到底在计算什么。

At this point you might be thinking we’ve done a whole lot of math to define the cost function. But what exactly is it doing? Let’s go on to the next video where we’ll step through one example of what the cost function is really computing that I hope will help you build intuition about what it means if J of wb is large versus if the cost j is small. Let’s go on to the next video.
到目前为止,你可能正在想我们已经进行了很多数学推导来定义代价函数。但是,它到底是在做什么呢?让我们继续看下一个视频,在下一个视频中,我们将通过一个例子详细解释损失函数到底在计算什么,希望能帮助你对 J ( w , b ) J(w,b) J(w,b)的大或小的含义建立直觉。让我们继续观看下一个视频。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/883044.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SMART PLC 64位双精度浮点数转32位单精度浮点数(Double_TO_Float)

有关博途PLC对位、字节、字元素的拆分和合并,请参看下面文章链接: 博途PLC 位/字/字节 Bit/ Word/Byte拆分与合并_博途的bit_RXXW_Dor的博客-CSDN博客有时候我们需要将分散分布的开关量信号组合为一个整体比如一个字节再完成发送,或者一些报警联锁控制,组合为一个字方便触…

原型模式 Prototype Pattern 《游戏编程模式》学习笔记

原型的定义 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象。 举个例子 假设我现在要做一款游戏,这个游戏里有许多不同种类的怪物,鬼魂,恶魔和巫师。这些怪物通过“生产者”进入这片区域,每种敌人…

VR/AR眼镜方案,MTK联发科平台智能眼镜安卓主板设计方案

随着人工智能在不同领域的逐渐深入,人们对一款产品的需求不再局限于某种单一的功能或单一场景,尤其是在工业医疗等专业领域,加快数字化转型才能实现产业的升级。 AR智能眼镜,是一个可以让现场作业更智能的综合管控设备。采用移动…

实验三 图像分割与描述

一、实验目的: (1)进一步掌握图像处理工具Matlab,熟悉基于Matlab的图像处理函数。 (2)掌握图像分割方法,熟悉常用图像描述方法。 二、实验原理 1.肤色检测 肤色是人类皮肤重要特征之一&#xff…

Springboot 实践(4)swagger-ui 测试controller

前文项目操作,完成了项目的创建、数据源的配置以及数据库DAO程序的生成与配置。此文讲解利用swagger-ui界面,测试生成的数据库DAO程序。目前,项目swagger-ui界面如下: 以”用户管理”为例,简单讲述swagger-ui测试数据库…

家纺行业小程序商城搭建指南

家纺行业作为一个不可或缺的消费领域,近年来备受关注。随着互联网的发展,小程序商城成为家纺行业拓展市场的新利器。搭建一个家纺行业小程序商城并不是一件困难的事情,只需要按照以下几个步骤进行操作,就能轻松上手。 首先&#x…

软件测试52讲-学习笔记

测试基础知识篇(11讲) 01 你真的懂测试吗?从“用户登录”测试谈起 测试用例设计框架 基于功能性需求和非功能性需求思考: 功能性需求使用等价类划分、边界值分析、错误推断法设计用例 非功能性需求考虑安全(信息的保存…

Postgresql源码(112)plpgsql执行sql时变量何时替换为值

相关 《Postgresql源码(41)plpgsql函数编译执行流程分析》 《Postgresql源码(46)plpgsql中的变量类型及对应关系》 《Postgresql源码(49)plpgsql函数编译执行流程分析总结》 《Postgresql源码(5…

【每日一题】—— B - Who is Saikyo?(AtCoder Beginner Contest 313)

🌏博客主页:PH_modest的博客主页 🚩当前专栏:每日一题 💌其他专栏: 🔴 每日反刍 🟡 C跬步积累 🟢 C语言跬步积累 🌈座右铭:广积粮,缓称…

线性表,双向链表,静态链表,循环链表(约瑟夫环)

目录 什么是线性表(线性存储结构) 顺序存储结构和链式存储结构 前驱和后继 顺序表(顺序存储结构)及初始化详解 顺序表的初始化 双向链表及创建(C语言)详解 双向链表的创建 静态链表及其创建&#x…

Ant Design Mobile是什么?

在当今的数字时代,移动应用程序和网页设计已经成为各行各业的重要组成部分。用户界面的设计直接影响到用户体验和产品的成功。为了帮助设计师在移动设计领域更好,Antdesignmobile应运而生。Antdesignmobile是蚂蚁金服的移动UI设计语言和框架,…

Android进阶之多级列表

遇到一个需求需要显示多级列表,因为界面是在平板上的,所以层级是从左向右往下排的,类似于 我当时的写法是在xml布局里一个个RecyclerView往下排的 当然前提是已经规定好最大的层级我才敢如此去写界面,如果已经明确规定只有两级或…

回归预测 | MATLAB实现GRNN广义回归神经网络多输入多输出预测

回归预测 | MATLAB实现GRNN广义回归神经网络多输入多输出预测 目录 回归预测 | MATLAB实现GRNN广义回归神经网络多输入多输出预测预测效果基本介绍程序设计往期精彩参考资料 预测效果 基本介绍 MATLAB实现GRNN广义回归神经网络多输入多输出预测,输入10个特征&#x…

每日一题——合并二叉树

题目 已知两颗二叉树,将它们合并成一颗二叉树。合并规则是:都存在的结点,就将结点值加起来,否则空的位置就由另一个树的结点来代替。例如: 两颗二叉树是: Tree 1 Tree 2 合并后的树为 数据范围:树上节点数…

【笔试题心得】排序算法总结整理

排序算法汇总 常用十大排序算法_calm_G的博客-CSDN博客 以下动图参考 十大经典排序算法 Python 版实现(附动图演示) - 知乎 冒泡排序 排序过程如下图所示: 比较相邻的元素。如果第一个比第二个大,就交换他们两个。对每一对相邻…

快速入门vue3组合式API

(创作不易,感谢有你,你的支持,就是我前行的最大动力,如果看完对你有帮助,请留下您的足迹) 使用create-vue创建项目 1. 前提环境条件 已安装 16.0 或更高版本的 Node.js node -v 2. 创建一个Vue应用 npm…

第三章nginx详解

nginx:高性能,轻量级的web服务软件。 特点: 1,稳定性高。(没有apache稳定) 2,系统资源消耗地较低。(处理http请求的并发能力非常高,单台物理服务器可以处理30000-5000…

【漏洞通知】JeecgBoot 修复 Freemarker 模板注入漏洞, 漏洞危害等级:高危

Freemarker模板注入导致远程命令执行, 远程攻击者可利用该漏洞调用在系统上执行任意命令。 JeecgBoot官方已修复,建议大家尽快升级至相关底层依赖和源码 一、漏洞描述 Freemarker模板注入导致远程命令执行, 远程攻击者可利用该漏洞调用在系统上执行任意命令。漏洞…

神经网络基础-神经网络补充概念-14-逻辑回归中损失函数的解释

概念 逻辑回归损失函数是用来衡量逻辑回归模型预测与实际观测之间差异的函数。它的目标是找到一组模型参数,使得预测结果尽可能接近实际观测。 理解 在逻辑回归中,常用的损失函数是对数似然损失(Log-Likelihood Loss)&#xff…

流程挖掘in汽车丨宝马的流程效能提升实例

汽车行业在未来10年里,可能会面临比过去50年更多的变化。电动化、智能化、共享化和自动驾驶等方面的趋势可能给企业流程带来以下挑战: 供应链管理-电动化和智能化的发展可能导致供应链中的零部件和系统结构发生变化,企业需要重新评估和优化供…