Regression and AI in practice
引入本课内容
| English | 释义 | 拼音 |
|---|---|---|
| model/ˈmɒdl/ | 模型 | mó xíng |
| supervised learning/ˈsuːpəvaɪzd ˈlɜːnɪŋ/ | 监督学习 | jiān dū xué xí |
| regression/rɪˈɡreʃn/ | 回归 | huí guī |
| classification/ˌklæsɪfɪˈkeɪʃn/ | 分类 | fēn lèi |
| linear regression/ˈlɪnɪə rɪˈɡreʃn/ | 线性回归 | xiàn xìng huí guī |
| pipeline/ˈpaɪplaɪn/ | 流水线 | liú shuǐ xiàn |
| category/ˈkætɪɡəri/ | 类别 | lèi bié |
| labelled examples | 有标签样本 | yǒu biāo qiān yàng běn |
| label/ˈleɪbl/ | 标签 | biāo qiān |
| classifier | 分类器 | fēn lèi qì |
| regressor | 回归器 | huí guī qì |
| loss functions | 损失函数 | sǔn shī hán shù |
| coefficients/ˌkəʊɪˈfɪʃənts/ | 系数 | xì shù |
| sum of the squared errors | 误差平方和 | wù chā píng fāng hé |
| training/ˈtreɪnɪŋ/ | 训练 | xùn liàn |
| polynomial regression | 多项式回归 | duō xiàng shì huí guī |
| decision tree/dɪˈsɪʒn triː/ | 决策树 | jué cè shù |
| neural network | 神经网络 | shén jīng wǎng luò |
| loss/lɒs/ | 损失 | sǔn shī |
| gradient descent/ˈɡreɪdɪənt dɪˈsent/ | 梯度下降 | tī dù xià jiàng |
| Face identification | 人脸识别 | rén liǎn shí bié |
| image recognition/ˈɪmɪdʒ ˌrekəɡˈnɪʃn/ | 图像识别 | tú xiàng shí bié |
| OCR/ˌəʊ siː ˈɑː/ | 光学字符识别 | guāng xué zì fú shí bié |
| pixels/ˈpɪkslz/ | 像素 | xiàng sù |
| machine translation/məˈʃiːn trænˈsleɪʃn/ | 机器翻译 | jī qì fān yì |
| text-to-speech/tekst tə spiːtʃ/ | 语音合成 | yǔ yīn hé chéng |
| inference/ˈɪnfərəns/ | 推理 | tuī lǐ |
| forward and backward passes | 前向传播和反向传播 | qián xiàng chuán bō hé fǎn xiàng chuán bō |
| labelled dataset | 有标签数据集 | yǒu biāo qiān shù jù jí |
| weights | 权重 | quán zhòng |
| epochs/ˈiːpɒks/ | 训练轮次 | xùn liàn lún cì |
| network/ˈnetwɜːk/ | 网络 | wǎng luò |
| activate | 激活 | jī huó |
| layer/ˈleɪə/ | 层 | céng |
| exit/ˈeɡzɪt/ | 出口 | chū kǒu |
预测一个数,而不是一个名字
- 问模型“这封邮件是垃圾邮件吗?”,它必须从一组固定的答案里选。问它“这套房子会卖多少钱?”,却没有可选的集合:答案是一个数,而差一千英镑也算基本正确。
- 这是两种不同的任务,把它们混为一谈是本课题最常见的错误。两者都是监督学习;不同的只是答案的形状。
- 这一课讲回归与分类的对比、线性回归怎样选出它的直线,以及真实产品怎样把训练好的模型串成流水线。
回归与分类
- 分类从一个固定集合中预测一个类别:猫还是狗、垃圾邮件还是非垃圾邮件、十个数字中的哪一个。
- 回归在连续的尺度上预测一个数:房价、明天的气温、一次行程要多久。
- 两者都是监督的:都从有标签样本中学习。选择哪一种取决于一个问题:答案是标签还是数字?
- 这个区别改变了衡量成败的方式。分类器要么对要么错;回归器则是差了多少,这就是它们的损失函数不同的原因。

The difference between regression and classification is that regression predicts:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Regression outputs a continuous number (price, temperature); classification outputs a category.
Regression predicts a continuous number (a price, a temperature), while classification predicts a category (cat vs dog).
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Number out = regression; category out = classification — the two main kinds of supervised prediction.
例题:哪个任务是哪一种
- 预测一位购物者属于五种顾客类型中的哪一种。 分类:答案是固定类别集合中的一个。
- 预测那位购物者下个月会花多少钱。 回归:答案是一个数,接近就算基本正确。
- 预测一台机器下周是否会故障。 分类:是或否。预测还有几天会故障。 回归。
- 同样的底层数据可以喂给任何一种。要读被问的问题,而不是看题材。
Match each prediction task to its kind.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
The same data can feed either. Read the question: a label from a fixed set, or a number on a scale.
线性回归
- 线性回归拟合一条直线,当输入有多个时则拟合一个平面:
- 选择系数,使直线的预测值与训练数据实际值之间的平方误差之和最小化。
- 用平方有两个考试接受的理由:线上方和下方的误差不会互相抵消,而且一个大误差受到的惩罚远大于几个小误差。

使总平方距离最小的直线
Fitting a regression line
Drag the controls. Linear regression draws the straight line that makes the squared distances to the data points as small as possible — then it predicts a number for any new input.
Linear regression chooses its coefficients to:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
It fits the line/hyperplane that makes the squared differences from the data points as small as possible.
Why does linear regression minimise the sum of the SQUARED errors rather than the errors themselves?
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Both reasons are accepted. Without squaring, a line could have a huge error above and below and still score zero.
什么时候直线是合适的模型
- 当关系看起来大致线性,而且你想要一个人能读懂的模型时,就用线性回归:每个系数说明对应的输入有多重要,以及影响的方向。
- 当数据呈曲线时,换一个模型,同样的想法仍然适用:多项式回归、决策树或神经网络。每一种情况下配方都一样:选一个模型、定义一个损失、将损失最小化。
- 这个配方正是本课与上一课的联系:当没有求解公式时,梯度下降就是完成最小化的方法。

真实产品里的人工智能
- 真实系统很少只用一个模型。它们把几个训练好的模型串成一条流水线,每个模型完成一步。
- 门口的人脸识别:摄像头捕捉人脸,图像识别把它转换成数值表示,再将它与已登记人员的数值表示进行匹配。
- 为旅行者朗读路牌:图像识别定位文字,OCR 将像素转换成字符,机器翻译转换文字,文本转语音生成音频。
- 考试会给出一个情境,问用到了哪些模型,以及它们的顺序。要说出每个阶段,以及它为下一阶段产生什么。

Match each AI idea to what it means.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
Training fits the model once; inference is the quick prediction each time a user interacts.
A "read a sign aloud" feature typically chains which models?
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Several trained models form a pipeline: find the text, extract characters, translate, then speak.
Put the stages of an app that reads a foreign sign aloud in order.
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
Several trained models chained together, each handing its output to the next. Name the stage and what it produces.
例题:训练与推理的对比
- 一个手机应用能瞬间从照片中认出一种植物,而训练它的模型却在许多台机器上花了几周。解释为什么。
- 训练在一个非常大的有标签数据集上反复进行前向和反向传播,经过很多训练轮次来调整数百万个权重。这些过程花了几周时间。
- 推理即使用训练好的模型,是在权重已固定的网络上做一次前向传播:逐层相乘、相加、激活,只进行一次。
- 智能存在于学到的权重里,这就是训练完成后的模型足够小、足够快,能够安装在手机上的原因。

Using a trained model to make a prediction requires only a single ____ pass.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Training repeats forward and backward passes over a huge dataset; inference runs the fixed weights once, which is why it is instant.
容易丢掉的分
- **分类给出类别,回归给出数字。**两者都是监督的;那不是区别所在。
- 线性回归最小化的是平方误差之和,不是"总距离"。要说平方,并说出为什么。
- 流水线的答案必须按顺序给出各阶段,并说出每个交给下一个什么。
- 训练是反复的前向和反向传播;推理是一次前向传播。题目问使用时不要去描述训练。
你掌握了
- 分类预测类别,回归预测数字;两者都是监督的,由问题答案的形状决定用哪个
- 线性回归通过最小化平方误差之和来拟合 $y = m_1x_1 + \ldots + c$,这样误差不会抵消,大误差受重罚
- 弯曲的数据需要别的模型,但配方不变:选模型、定损失、最小化
- 真实产品把模型串起来:图像识别、OCR、翻译和文本转语音;训练是许多次前向和反向传播,推理是一次前向传播
出了什么问题?只有网站团队能看到这些信息。
Try it in the lab 32
All labs →- Teach a Perceptron
- Train a Network on Your Drawings
- Teach a Robot by Reward
- Build a Decision Tree
- Nearest Neighbours
- Roll Down the Loss
- Find the Groups
- Find the Shortest Route
- See Like a Computer
- Guess the Next Word
- Is the Computer Fair?
- Build an Expert System
- Evolve a Catapult
- Catch the Spam
- Think Ahead
- Inside a Neural Network
- Learning or Remembering? Overfitting
- Search the Maze
- What Should I Watch? A Recommender
- Teach a Car to Drive
- Matchbox Learner
- Build a Chatbot
- Fewer Colours
- Mood Meter
- Spot the Fraud
- Hear the Word
- Follow the Ants
- Plan the Delivery Round
- Squash the Data
- Explore or Exploit? Learning by Trying
- Mark the Model
- Ask Many Models