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

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

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.mzph.cn/news/38418.shtml

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

相关文章

Redis专题-队列

Redis专题-队列 首先,想一想 Redis 适合做消息队列吗? 1、消息队列的消息存取需求是什么?redis中的解决方案是什么? 无非就是下面这几点: 0、数据可以顺序读取 1、支持阻塞等待拉取消息 2、支持发布/订阅模式 3、重…

前后端分离------后端创建笔记(09)密码加密网络安全

本文章转载于【SpringBootVue】全网最简单但实用的前后端分离项目实战笔记 - 前端_大菜007的博客-CSDN博客 仅用于学习和讨论,如有侵权请联系 源码:https://gitee.com/green_vegetables/x-admin-project.git 素材:https://pan.baidu.com/s/…

数据库概述、部署MySQL服务、必备命令、密码管理、安装图形软件、SELECT语法 、筛选条件

Top NSD DBA DAY01 案例1:构建MySQL服务器案例2:密码管理案例3:安装图形软件案例4:筛选条件 1 案例1:构建MySQL服务器 1.1 问题 在IP地址192.168.88.50主机和192.168.88.51主机上部署mysql服务练习必备命令的使用 …

代理模式概述

1.代理模式概述 学习内容 1)概述 为什么要有 “代理” ? 生活中就有很多例子,比如委托业务,黄牛(票贩子)等等代理就是被代理者没有能力或者不愿意去完成某件事情,需要找个人代替自己去完成这…

Nginx+Tomcat负载均衡、动静分离实例详细部署

一、反向代理两种模式 四层反向代理 基于四层的iptcp/upd端口的代理 他是http块同一级,一般配置在http块上面。 他是需要用到stream模块的,一般四层里面没有自带,需要编译安装一下。并在stream模块里面添加upstream 服务器名称,…

kafka生产者幂等与事务

目录 前言: 幂等 事务 总结: 参考资料 前言: Kafka 消息交付可靠性保障以及精确处理一次语义的实现。 所谓的消息交付可靠性保障,是指 Kafka 对 Producer 和 Consumer 要处理的消息提供什么样的承诺。常见的承诺有以下三…

No view found for id 0x7f0901c3 for fragment解决以及线上bug排查技巧

情景再现 开发这么久,不知道你们是否也经历过这样的情况,测试或者用户,反馈app闪退,结果你自己打开开发工具,去调试,一切正常,然后闪退还是存在,只是在开发环境中不能重现。这种情况…

boost下的asio异步高并发tcp服务器搭建

C 网络编程 asio 使用总结 - 知乎 (zhihu.com) 基于Boost::asio的多线程异步TCP服务器&#xff0c;实现了io_service线程池&#xff0c;测试了1万左右的并发访问&#xff0c;读写无压力_boost asio支持最大并发_E404的博客-CSDN博客 单线程 server.cpp #include <cstdlib&g…

【ARM 嵌入式 编译系列 11.1 -- GCC __attribute__((aligned(x)))详细介绍】

文章目录 __attribute__((aligned(x)))详细介绍其它对齐方式 上篇文章&#xff1a;ARM 嵌入式 编译系列 11 – GCC attribute&#xff08;(packed)&#xff09;详细介绍 attribute((aligned(x)))详细介绍 __attribute__((aligned(x))) 是 GCC 编译器的一个特性&#xff0c;它可…

SpringBoot代理访问本地静态资源400 404

SpringBoot代理访问静态资源400 404 背景&#xff1a;pdf文件上传到linux服务器上&#xff0c;使用SpringBoot代理访问问题&#xff1a;访问过程中可能会出现400、404问题 前提&#xff1a;保证有文件&#xff0c;并且文件路径正确 SpringBoot如何配置静态资源代理&#xff0…

Flutter实现倒计时功能,秒数转时分秒,然后倒计时

Flutter实现倒计时功能 发布时间&#xff1a;2023/05/12 本文实例为大家分享了Flutter实现倒计时功能的具体代码&#xff0c;供大家参考&#xff0c;具体内容如下 有一个需求&#xff0c;需要在页面进行显示倒计时&#xff0c;倒计时结束后&#xff0c;做相应的逻辑处理。 实…

Antd的日期选择器中文化配置

当你使用antd的日期选择器后&#xff0c;你会发现日期什么都是英文的&#xff1a;即便你已经在项目中配置了中文化&#xff1a; 我确实已经配置了中文化&#xff1a; 但是为啥没生效&#xff1f;官网回答&#xff1a;FAQ - Ant Design dayjs中文网&#xff1a; 安装 | Day…

零拷贝详解

1、在没有DMA技术之前的I/O过程是这样的&#xff1a; CPU发出对应的指令给磁盘控制器&#xff0c;然后返回磁盘控制器收到指令后&#xff0c;于是就开始准备数据&#xff0c;会把数据放入到磁盘控制器的内部缓冲区&#xff0c;然后产生中断CPU收到中断信号后&#xff0c;停下手…

华为OD机试-5键键盘的输出

题目描述 【5键键盘的输出】有一个特殊的 5键键盘&#xff0c;上面有 a,ctrl-c,ctrl-x,ctrl-v,ctrl-a五个键。 a键在屏幕上输出一个字母 a; ctrl-c将当前选择的字母复制到剪贴板; ctrl-x将当前选择的 字母复制到剪贴板&#xff0c;并清空选择的字母; ctrl-v将当前剪贴板里的字母…

HTML是什么?

HTML是什么&#xff1f; 超文本标记语言&#xff08;英语&#xff1a;HyperText Markup Language&#xff0c;简称&#xff1a;HTML&#xff09;是一种用于创建网页的标准标记语言。 您可以使用 HTML 来建立自己的 WEB 站点&#xff0c;HTML 运行在浏览器上&#xff0c;由浏览器…

【业务功能篇63】Springboot聊聊 过滤器和拦截器

过滤器的场景&#xff1a;过滤器通常用于对数据或资源进行筛选、修改或转换的场景。例如&#xff0c;在一个电子商务网站中&#xff0c;用户进行商品搜索时&#xff0c;你可以使用过滤器来过滤特定的商品类别、价格范围或其他条件&#xff0c;以便用户仅看到符合筛选条件的结果…

人工智能时代的科学探索 | 《自然》评述

人工智能(AI)正越来越多地融入科学发现&#xff0c;以增强和加速研究&#xff0c;帮助科学家提出假设、设计实验、收集和解释大型数据集&#xff0c;并获得仅靠传统科学方法可能无法实现的洞察力。 过去十年间&#xff0c;AI取得了巨大的突破。其中就包括自监督学习和几何深度学…

手机的发展历史

目录 一.人类的通信方式变化 二.手机对人类通信的影响 三.手机的发展过程 四.手机对现代人的影响 一.人类的通信方式变化 人类通信方式的变化是一个非常广泛和复杂的话题&#xff0c;随着技术的进步和社会的发展&#xff0c;人类通信方式发生了许多重大的变化。下面是一些主…

go mod使用最新提交依赖

例如一个项目在其中依赖了 github.com/linuxsuren/go-fake-runtime v0.0.1 go.mod内容&#xff1a; github.com/linuxsuren/go-fake-runtime v0.0.1 修改了github.com/linuxsuren/go-fake-runtime代码&#xff0c;存在一个最新的commit hash值为25fa814c6232e545f5bce03bd…

【opencv】指定宽或高按比例缩放图片 拼接图片

指定宽或高按比例缩放图片 import cv2def resize_by_ratio(image, widthNone, heightNone, intercv2.INTER_AREA):img_new_size None(h, w) image.shape[:2] # 获得高度和宽度if width is None and height is None: # 如果输入的宽度和高度都为空return image # 直接返回原图…