Midterm 自拟练习|D 机器学习
自拟练习 D 机器学习:英文题干,逐题折叠中文解析、英文参考答案与回查页码。
手机上宽表格可左右滑动;自测答案默认收起,点击题目下方按钮查看。
使用边界:2026-11-04 课堂期中复习,非官方材料;考试安排按讲师通知整理,正式要求以讲师通知和课堂公告为准。主体覆盖 L01–L07、Tutorial 1–5 与 Assignment 1;通知列出的课件只到 Lecture 7,L08 放在第 08 节作范围存疑附节。练习题均为自拟,不是往年真题或预测卷。
复习资料:范围与搜索 · 概率与逻辑 · 机器学习与聚类 · 神经网络与 L08 附节
先做题再看解析:A 搜索 · B 概率 · C 逻辑 · D 机器学习 · E 聚类与神经网络 · F 论文与 PyTorch
怎么做:先只看题面,用英文作答,写出公式和每一步,再展开解析核对。解析里的数值都用 python 复算过;每题末尾给回查出处,页码为 PDF 页序。
D 机器学习
D1 · Computing the cost
Training set: (x, y) = (1, 2), (2, 3), (3, 5). Hypothesis h_θ(x) = θ₀ + θ₁x with the squared-error cost J(θ₀, θ₁) = (1/2m) Σ (h_θ(x⁽ⁱ⁾) − y⁽ⁱ⁾)².
(a) Compute J(1, 1). (b) Compute J(0, 0).
D1 · 查看答案与解析
推理过程:m = 3。
(a) θ₀ = 1、θ₁ = 1 时预测 2、3、4,误差 0、0、−1,平方和 1,J = 1/6 ≈ 0.1667。
(b) θ₀ = θ₁ = 0 时预测全为 0,误差 −2、−3、−5,平方和 4 + 9 + 25 = 38,J = 38/6 ≈ 6.3333。
答案:J(1, 1) ≈ 0.1667,J(0, 0) ≈ 6.3333。
English: The squared-error cost averages the squared differences between predictions and targets; the factor 1/2 only simplifies the derivative.
易错点:分母是 2m = 6,不是 m。
回查:L04b p.9–12。
D2 · One step of gradient descent
Use the training set of D1. Start from θ₀ = 0, θ₁ = 0 with learning rate α = 0.1.
(a) Perform one step of gradient descent with simultaneous update. (b) A student updates θ₀ first and then uses the new θ₀ to compute the gradient for θ₁. What value of θ₁ does the student get? (c) Which implementation is correct?
D2 · 查看答案与解析
推理过程:
(a) 误差 h − y 为 −2、−3、−5,求和 −10;乘 x 后为 −2、−6、−15,求和 −23。
- θ₀ := 0 − 0.1 × (1/3) × (−10) ≈ 0.3333
- θ₁ := 0 − 0.1 × (1/3) × (−23) ≈ 0.7667
更新后 J ≈ 1.2826,比 6.3333 小。
(b) 先把 θ₀ 改成 0.3333,再算误差约为 −1.6667、−2.6667、−4.6667,乘 x 求和为 −21,θ₁ = 0.1 × 21/3 = 0.7。
(c) 第 (a) 问的做法正确。两个梯度都要用更新前的 θ 算完,再同时赋值。
答案:(a) θ₀ ≈ 0.3333,θ₁ ≈ 0.7667;(b) 0.7;(c) 同时更新的版本正确。
English: All parameters must be updated simultaneously: compute every partial derivative with the old parameters before assigning any new value.
易错点:θ₁ 的梯度要乘 x⁽ⁱ⁾;θ₀ 的不乘。
回查:L04b p.22–26。
D3 · Bias or variance
Two polynomial models are trained on the same data.
Model X: J_train = 0.42, J_cv = 0.45. Model Y: J_train = 0.03, J_cv = 0.61.
(a) Diagnose each model as high bias or high variance. (b) For each model, would collecting more training data be likely to help? Suggest two other actions.
D3 · 查看答案与解析
推理过程:看 J_train 的高低和两者的间隙。X 的训练误差高、与 CV 误差接近;Y 的训练误差很低、CV 误差远大于训练误差。
答案:
(a) X 高偏差(欠拟合);Y 高方差(过拟合)。
(b) X:多收数据帮助不大,可以加特征、加多项式特征或减小 λ。Y:多收数据可能有帮助,还可以减少特征或增大 λ。
English: High bias shows a high training error with a small gap to the cross-validation error; high variance shows a low training error with a much larger cross-validation error.
易错点:两份数字都要引用到判断里,不能只看 J_cv。
回查:L04c p.29、p.36–39。
D4 · Data split and choosing λ
You have 500 labelled examples and want to choose λ for regularised linear regression.
(a) With a 60/20/20 split, how many examples go to the training, cross-validation and test sets? What is each set used for? (b) A classmate tries 12 values of λ and picks the one with the lowest J_test. What is wrong with this? (c) Should the regularisation term be included when computing J_cv?
D4 · 查看答案与解析
推理过程:
(a) 500 × 60% = 300,500 × 20% = 100,所以是 300、100、100。训练集拟合 θ,CV 集选 λ,测试集最后报一次分。
(b) 用测试集挑 λ,λ 就相当于在测试集上拟合过,报出来的 J_test 会偏乐观。
(c) 不包含。J_train、J_cv、J_test 都只算平方误差。
答案:见上。
English: The hyperparameter should be chosen on the cross-validation set; the test set is used only once to report the generalisation error.
易错点:课件候选 λ 是 0 加上从 0.01 起翻倍,共 12 个,第 12 项是 10.24。
回查:L04c p.20–24、p.33。
D5 · Which kind of learning?
For each task, state whether it is supervised regression, supervised classification, unsupervised learning or reinforcement learning, and give the reason in one sentence.
(a) Predicting tomorrow’s maximum temperature in degrees. (b) Grouping customers by purchase history when no group labels exist. (c) A robot learns to walk by receiving a reward when it moves forward. (d) Predicting whether a loan applicant will default (yes or no) from past labelled cases.
D5 · 查看答案与解析
答案:
(a) 监督回归,输出是连续的温度值。
(b) 无监督学习(聚类),数据没有标签。
(c) 强化学习,数据靠与环境交互收集,反馈是奖励。
(d) 监督分类,有历史标签,输出是两个类别之一。
English: Supervised learning needs labels y; regression predicts a continuous value and classification predicts a discrete class. Unsupervised learning has no labels, and reinforcement learning collects data interactively through rewards.
易错点:(c) 的奖励可以即时也可以延迟,不等于每一步都有正确动作标签。
回查:L01 p.69–71、p.76;L04a p.20、p.35、p.42。
个人整理的学习笔记,不是官方材料;数字与结论以课件和讲师为准。