← COMP5511 全部讲次
R03

Midterm 复习资料|机器学习与聚类

学习范式、线性回归与梯度下降、模型选择与偏差方差、K-means。

手机上宽表格可左右滑动;自测答案默认收起,点击题目下方按钮查看。

使用边界:2026-11-04 课堂期中复习,非官方材料;考试安排按讲师通知整理,正式要求以讲师通知和课堂公告为准。主体覆盖 L01–L07、Tutorial 1–5 与 Assignment 1;通知列出的课件只到 Lecture 7,L08 放在第 08 节作范围存疑附节。练习题均为自拟,不是往年真题或预测卷。

复习资料:范围与搜索 · 概率与逻辑 · 机器学习与聚类 · 神经网络与 L08 附节

先做题再看解析:A 搜索 · B 概率 · C 逻辑 · D 机器学习 · E 聚类与神经网络 · F 论文与 PyTorch

04|机器学习:范式、线性回归与模型选择

必须会算的

  • 📌 用线性规则分类:课件垃圾邮件规则 2·money + 3·pills − 5·known > 0,判据是严格大于 0(L04a p.12)。
  • 📌 代价函数 J(θ₀, θ₁) = (1/2m) Σ (h_θ(x⁽ⁱ⁾) − y⁽ⁱ⁾)²,h_θ(x) = θ₀ + θ₁x。课件三点例题 (1,1)(2,2)(3,3):J(1) = 0,J(0.5) = 3.5/6 ≈ 0.58(L04b p.4、p.9–12)。
  • 📌 梯度下降一步:θ₀ := θ₀ − α(1/m)Σ(h_θ(x⁽ⁱ⁾) − y⁽ⁱ⁾),θ₁ := θ₁ − α(1/m)Σ(h_θ(x⁽ⁱ⁾) − y⁽ⁱ⁾)·x⁽ⁱ⁾,两个参数同时更新(L04b p.23–26)。
  • 📌 正则化代价:J(θ) = (1/2m)[Σ(h_θ(x⁽ⁱ⁾) − y⁽ⁱ⁾)² + λΣθⱼ²],j 从 1 开始,θ₀ 不罚(L04b p.35)。
  • 📌 数据切分:两分法 70/30;三分法 60/20/20,训练集拟合 θ,CV 集选超参数,测试集最后报一次分(L04c p.15–16、p.22–24)。
  • 📌 选 λ:候选 λ = 0 加上从 0.01 起翻倍到约 10,共 12 个;第 12 项精确值是 10.24(L04c p.33)。
  • 📌 读 J_train 和 J_cv 判断偏差或方差(L04c p.29)。

必须会用英文说清的

  • 📌 Machine learning is the field of study that gives computers the ability to learn without being explicitly programmed (Samuel, 1959).(L01 p.38;L04a p.6)
  • 📌 A program learns from experience E with respect to task T and performance measure P if its performance on T, measured by P, improves with E (Mitchell, 1998).(L01 p.38)
  • 📌 Supervised learning uses labelled pairs (x, y); unsupervised learning has only x and looks for structure; in reinforcement learning the algorithm collects data interactively and receives rewards.(L04a p.11、p.35、p.42;L01 p.69–71)
  • 📌 Regression predicts a continuous y; classification predicts a discrete label.(L04a p.20;L01 p.76)
  • 📌 Underfitting means high bias; overfitting means high variance: the training cost is close to zero but the model generalises poorly.(L04b p.30;L04c p.27)
  • 📌 The training error is an optimistic estimate of the generalisation error, so the model must be evaluated on data that were not used for training.(L04c p.19)
  • 📌 If a learning algorithm suffers from high bias, getting more training data will not help much; if it suffers from high variance, more data is likely to help.(L04c p.38–39)

成立条件和常见误区

  • “Supervision” 指全部标签 y⁽¹⁾…y⁽ⁿ⁾;上标是样本编号,下标是特征编号(L04a p.16、p.18)。
  • 预测降雨概率,输出是 0 到 1 之间的数,但最终要的答案是下不下雨,L01 把它归为分类(L01 p.76)。
  • 同时更新:两个 temp 都用旧 θ 算完再赋值;先更新 θ₀ 再用新 θ₀ 算 θ₁ 是错误实现(L04b p.25–26)。
  • α 太小收敛慢,α 太大会震荡甚至发散(L04b p.27)。线性回归的 J 是碗形凸函数,只有一个最低点;非凸曲面上初值不同可能到不同局部最优(L04b p.15、p.20–21)。
  • λ = 0 时可能过拟合,λ 过大时 h 接近水平线 θ₀,欠拟合(L04b p.36;L04c p.31)。L1 正则叫 Lasso,L2 正则叫 Ridge(L04b p.35)。
  • J_train、J_cv、J_test 三个公式都不含正则项(L04c p.23)。用测试集选 d 或 λ 会让 J_test 偏乐观(L04c p.20)。
  • 诊断规则:J_train 高且 J_cv ≈ J_train 是偏差问题;J_train 低且 J_cv 远大于 J_train 是方差问题(L04c p.29)。随 d 增大 J_train 单调降、J_cv 呈 U 形;随 λ 增大 J_train 单调升、J_cv 呈 U 形(L04c p.28、p.34)。
  • In-context learning 在提示里给示例,课件强调 no gradient updates,参数不变(L04a p.24)。

05|聚类:K-means

必须会算的

  • 📌 K-means 一轮:每个点归给最近的中心(平方欧氏距离),中心改为所属点的算术平均,重复到没有点改变归属(L05 p.6、p.16–17)。
  • 📌 目标函数 SSE = Σᵢ Σ_{x∈Cᵢ} |x − μᵢ|²;两步分别是固定 μ 优化分配、固定分配优化 μ(L05 p.23)。
  • 📌 每轮代价 O(KN),算上维度为 O(KNd)(L05 p.22)。
  • 📌 肘部法选 K:画 SSE 随 K 的曲线,取下降幅度突然变小的那个 K;课件示例的肘点在 K = 3(L05 p.29)。

必须会用英文说清的

  • 📌 In unsupervised learning the dataset contains no labels, and the goal of finding interesting structure is vaguely posed.(L05 p.2;L04a p.35)
  • 📌 K-means alternates between assigning each point to its nearest centre and moving each centre to the mean of its points.(L05 p.16–17)
  • 📌 K-means always terminates because neither step increases the objective and the number of possible partitions is finite, but it may converge to a local optimum.(L05 p.22–23、p.27)
  • 📌 SSE never increases as K grows, so we cannot choose K by minimising SSE; we use the elbow point instead.(L05 p.29)

成立条件和常见误区

  • 正式名称是 k-means,L04a 课件写成 k-mean 是笔误(L04a p.37)。
  • 中心取算术平均,是因为目标函数用的是距离平方(L05 p.23)。
  • 收敛论证只保证会停,不保证全局最优;初值不同结果可能不同(L05 p.27–28)。
  • K 由人给定;同一份数据分两簇、分三簇都可能说得通(L04a p.36–37;L05 p.29)。
  • 簇边界由直线(超平面)拼成,簇形状是凸的;同心环、两个月牙会被切断。换特征或换距离函数可能有帮助,例如把同心环从 (X, Y) 换到 (R, θ)(L05 p.17、p.30–33)。
  • 聚类的分组是算出来的,每组代表什么还要人去解释,不等同于有标签的分类(L01 p.78)。
下一页 →
R04 Midterm 复习资料|神经网络与 L08 附节

个人整理的学习笔记,不是官方材料;数字与结论以课件和讲师为准。