跳到主要内容

A.4 · 机器学习

IB 计算机科学 SL · 知识点 4

本主题的视频课程 打开视频页面
3:21

机器学习

垃圾邮件过滤器并非由规则列表驱动。相反,它被展示成千上万封标记为垃圾邮件或非垃圾邮件的电子邮件,并自行发现模式。当垃圾邮件发送者……

英文讲解 · 可切换中英文字幕

4.1

范围与先修条件

English

This handout teaches Theme A4, Machine learning, for the course first assessed in 2027: what machine learning is, its main types, how models are judged, and its ethical issues.

Prerequisites: reading a scatter graph and a percentage. The datasets here are small and fictional.

4.2

什么是机器学习?

English

A program that learns from examples

A spam filter is not given a list of rules such as "block any e-mail containing 'prize'". Instead it is shown thousands of e-mails labelled "spam" or "not spam" and finds the patterns itself. When spammers change their wording, it is retrained on new examples. This is machine learning 机器学习 (ML): a program improves at a task by learning patterns from data rather than following rules written by a programmer.

A white Waymo self-driving car on a city street, with a spinning lidar sensor unit on its roof and extra cameras at the front corners
A self-driving car uses cameras and lidar sensors to see the road around it

ML is one part of artificial intelligence 人工智能 (AI), the wider field of making computers do tasks that seem to need human intelligence. Deep learning 深度学习 is a kind of ML that uses neural networks with many layers.

Types of machine learning

Type Learns from Typical task Example
supervised learning 监督学习 labelled data: inputs with the right answers classify, predict a number spam or not; a house price
unsupervised learning 无监督学习 unlabelled data find groups or patterns grouping shoppers by habits
reinforcement learning 强化学习 rewards and penalties from trial and error choose actions a robot learning to walk; a game player

Supervised learning splits into classification 分类 (the answer is a category: cat or dog) and regression 回归 (the answer is a number: a score or a price).

Scatter graph of hours of revision against test score for five students, rising from 52 at 1 hour to 74 at 5 hours, with the straight best-fit line y = 5.6x + 46.2 and a prediction of 79.8 at 6 hours
Supervised learning: the model learns a line from labelled examples, then predicts a new case

Training and testing

  1. Collect and label data.
  2. Split it: most for training 训练 the model, the rest held back as test data 测试数据.
  3. Train the model on the training data.
  4. Measure it on the test data, which it has never seen.

Testing on unseen data shows whether the model has learned the general pattern. A model that memorises its training data but fails on new data is overfitting 过拟合. A model too simple to capture the pattern is underfitting.

Measuring a classifier

Accuracy 准确率 is the share of predictions that are correct:

$$\text{accuracy} = \frac{\text{correct predictions}}{\text{total predictions}} \times 100\%$$

A model correct on 90 of 100 test cases has 90% accuracy. Accuracy can mislead when the classes are unbalanced:

Bar chart of 100 cases: 90 in the majority class and 10 in the minority class
With 90 of 100 cases in one class, always predicting that class scores 90% yet misses every minority case

A "model" that always answers "healthy" for a disease affecting 10% of patients scores 90% and finds no one who is ill. So check how the model does on each class, not just overall.

Hardware for machine learning

Training repeats the same arithmetic on huge amounts of data, so it runs on GPUs and special chips with thousands of cores working in parallel, often rented in the cloud. Using a trained model (inference) needs far less power and can run on a phone.

探索

准确率与类别分布

比较总体准确率、各类别召回率与正类精确率。不同分母回答不同的问题,类别分布会影响总体准确率。

词汇 训练
English 中文 拼音
machine learning/məˈʃiːn ˈlɜːnɪŋ/ 机器学习 jī qì xué xí
artificial intelligence/ˌɑːtɪˈfɪʃl ɪnˈtelɪdʒəns/ 人工智能 rén gōng zhì néng
deep learning/diːp ˈlɜːnɪŋ/ 深度学习 shēn dù xué xí
supervised learning/ˈsuːpəvaɪzd ˈlɜːnɪŋ/ 监督学习 jiān dū xué xí
unsupervised learning/ʌnˈsuːpəvaɪzd ˈlɜːnɪŋ/ 无监督学习 wú jiān dū xué xí
reinforcement learning/ˌriːɪnˈfɔːsmənt ˈlɜːnɪŋ/ 强化学习 qiáng huà xué xí
classification/ˌklæsɪfɪˈkeɪʃn/ 分类 fēn lèi
regression/rɪˈɡreʃn/ 回归 huí guī
training/ˈtreɪnɪŋ/ 训练 xùn liàn
test data/test ˈdeɪtə/ 测试数据 cè shì shù jù
overfitting/ˌəʊvəˈfɪtɪŋ/ 过拟合 guò nǐ hé
accuracy/ˈækjʊrəsi/ 准确率 zhǔn què lǜ
4.3

机器学习的伦理

English

Who is affected?

Issue What can go wrong Example
bias 偏见 training data under-represents a group, so the model works worse for them face recognition less accurate for darker skin
privacy personal data collected or used without consent photos scraped from social media
transparency no one can explain why the model decided a loan refused with no reason given
accountability unclear who is responsible for a harmful decision a self-driving car accident
jobs tasks automated checkout staff, translators
misuse realistic fake images, audio or text deepfakes spread as news
A CCTV control room: surveillance systems trade safety gains against privacy concerns
A CCTV control room: surveillance systems trade safety gains against privacy concerns

Ways to reduce harm: train on data that represents everyone the model affects; test accuracy separately for each group; keep a human in the loop for serious decisions; collect data with consent and remove what is not needed; explain decisions to the people affected.

词汇 训练
English 中文 拼音
bias/ˈbaɪəs/ 偏见 piān jiàn
4.4

练习

English
  1. Define machine learning, and explain how it differs from a program with written rules.
  2. State the type of ML for each: (a) grouping songs by similarity with no labels; (b) predicting tomorrow's temperature from past records; (c) a program learning to play chess by playing itself.
  3. State whether each is classification or regression: (a) a house price; (b) whether a photo shows a cat.
  4. Explain why a model is tested on data it was not trained on.
  5. A model makes 72 correct predictions out of 80. Calculate its accuracy.
  6. A model for a rare disease (2% of patients) has 98% accuracy. Explain why this may be useless.
  7. Explain two ethical issues of using ML to shortlist job applicants, and suggest a way to reduce each.

Answers.

  1. ML is a program that improves at a task by learning patterns from data. A rule-based program follows rules a programmer wrote; an ML model finds its own rules from examples.
  2. (a) unsupervised; (b) supervised (regression); (c) reinforcement.
  3. (a) regression; (b) classification.
  4. To check that it has learned the general pattern rather than memorised the training examples (overfitting); unseen data shows how it will work in real use.
  5. $\dfrac{72}{80} \times 100\% = 90\%$.
  6. Always predicting "healthy" would also score 98% while finding no sick patients; the model must be judged on how many real cases it finds.
  7. E.g. bias: past hiring data may favour one group, so the model repeats it; train on balanced data and test results for each group. Transparency: applicants cannot learn why they were rejected; use an explainable model and keep a human reviewer.
  8. Using information that would not be available when the prediction is made, so test results are falsely good; e.g. predicting who will fail a course using their final exam mark.
  9. $5.6 \times 3.5 + 46.2 = 19.6 + 46.2 = 65.8$.
  10. $k = 1$: the nearest point is B, so B; $k = 3$: two A and one B, so A.
  11. Accuracy $= \dfrac{30 + 140}{200} = 0.85$; precision $= \dfrac{30}{40} = 0.75$; recall $= \dfrac{30}{50} = 0.60$.
4.5

考试技巧

English
  • Name the type of learning from the data: labels → supervised; no labels → unsupervised; rewards → reinforcement.
  • Say why test data is kept separate: to measure performance on unseen data and detect overfitting.
  • Do not trust accuracy alone with unbalanced classes; mention per-class results.
  • Ethics answers: name the issue, explain the harm in the scenario, then give a specific way to reduce it.

更多 IB 计算机科学 SL 知识点

登录或创建账户

IGCSE, A-Level & AP