COMP5318 Practice Exam 3 整卷逐题解析
COMP5318 Practice Exam 3 整卷逐题解析
- 课程:COMP4318/COMP5318 — Machine Learning and Data Mining
- 材料:
Exam Prep/COMP5318_Practice_Exam_3.pdf(题目,20 页)+COMP5318_Practice_Exam_3_Solutions.pdf(官方答案与评分指引,10 页)- 答案来源:所有答案都按官方 Solutions 给出。「为什么其他选项错」和知识点归属是我补充的。
- 形式:与前两套相同——2 小时,闭卷,可用非编程计算器;Part A 30 × 2 分,Part B 4 × 10 分。前两套见 Practice Exam 1 解析、Practice Exam 2 解析。
答案速查(官方)
| Q | 答 | Q | 答 | Q | 答 | Q | 答 | Q | 答 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | D | 7 | D | 13 | A | 19 | C | 25 | C |
| 2 | B | 8 | B | 14 | A | 20 | B | 26 | D |
| 3 | A | 9 | C | 15 | D | 21 | C | 27 | D |
| 4 | D | 10 | A | 16 | B | 22 | C | 28 | C |
| 5 | B | 11 | A | 17 | A | 23 | A | 29 | D |
| 6 | B | 12 | C | 18 | C | 24 | D | 30 | B |
本卷的计算型选择题:Q3(加权投票)、Q7(逻辑回归)、Q10(Accuracy/F1)、Q14(SVM 打分)、Q17(累计方差)、Q19(感知机)、Q22(卷积参数)、Q25(链接距离)、Q27(HMM 前向)、Q30(Q-learning)。
Part A:选择题
Q1 医院按「是否再入院」标签预测 → D 有监督分类
Original question (English) · [2 marks] A hospital learns from records labelled Readmitted or Not readmitted and predicts one of these labels for a new patient. What task is this?
- A. Reinforcement learning from action rewards.
- B. Unsupervised clustering.
- C. Supervised regression of a continuous outcome.
- D. Supervised classification.
训练数据带标签,目标是离散的两个类别 → 有监督分类。A 需要奖励信号;B 没有标签;C 的目标是连续值。
知识点:W01 任务分类
English answer (Official): D — Learning tasks. The target is a known discrete label supplied for the training observations, so this is supervised classification.
Q2 噪声数据上适度增大 k → B 决策边界更平滑
Original question (English) · [2 marks] On a noisy classification dataset, a 1-NN model fits the training examples closely but has unstable predictions. What is a plausible effect of increasing k moderately?
- A. A requirement that features no longer need comparable scales.
- B. A smoother decision boundary that can reduce sensitivity to individual noisy examples.
- C. A guarantee of zero error on every future test set.
- D. A guarantee that every training point still receives its original label.
- 答案 B:1-NN 方差大、易受单个噪声点影响;k 变大相当于在更大邻域里平均,方差下降、偏差上升,边界更平滑。k 的具体取值要靠验证集选。
- A:kNN 基于距离,任何 k 都需要特征缩放;C、D:「guarantee」类绝对说法都错,k > 1 时训练点甚至可能被邻居「投票改判」。
- 知识点:W02 k 的选择
English answer (Official): B — k-NN bias and variance. Larger neighbourhoods average over more examples and can reduce variance. The resulting boundary may have more bias, so validation should guide k.
Q3 1/d² 加权投票 → A(A: 1.00,B: 0.50,预测 A)
Original question (English) · [2 marks] Three neighbours have (class, distance) pairs (A, 1), (B, 2) and (B, 2). Voting uses w = 1/d². What is the total vote for each class and the resulting prediction?
- A. A: 1.00; B: 0.50; predict A.
- B. A: 1.00; B: 2.00; predict B.
- C. A: 1.00; B: 1.00; tie.
- D. A: 0.50; B: 1.00; predict B.
A 的票更重 → 预测 A。不加权时 B 以 2:1 胜出,这正是距离加权想纠正的情况。
- B 把权重写成了
而不是 ;C 用的是 ( );D 是把 A 的权重算错了。 - 知识点:W02 加权 kNN
English answer (Official): A — Weighted k-NN. The A vote is 1/1² = 1. Each B vote is 1/2² = 0.25, giving 0.50 in total. Weighted voting therefore selects A.
Q4 PRISM 得到一条纯规则后 → D 移除已覆盖样本,再生长下一条规则
Original question (English) · [2 marks] PRISM completes a pure rule for class Yes, but other Yes examples remain uncovered. What should happen next for that class?
- A. Discard every remaining Yes example permanently.
- B. Keep adding conditions to the completed pure rule to broaden its coverage.
- C. Stop because one pure rule must cover all Yes examples.
- D. Remove the examples covered by the completed rule and grow another rule for the remaining Yes examples.
PRISM 是分离-征服(separate-and-conquer / covering)算法:对每个类,
- 从空规则
IF ? THEN Yes开始,每次加入使准确率最高的条件,直到规则纯; - 删掉被这条规则覆盖的样本;
- 若该类还有未覆盖的样本,回到第 1 步;否则换下一个类。
- B 是常见误解:加条件(合取)只会让规则变窄,不会扩大覆盖。
- A、C 都会漏掉剩下的 Yes 样本。
- 知识点:规则学习(1R / PRISM)属于 W02 讲课内容,可对照 W05 决策树(树的每条路径也是一条合取规则)。
English answer (Official): D — PRISM rule sets. Separate-and-conquer rule induction learns further rules after removing examples covered by a completed rule. Adding conjunctions cannot broaden a rule.
Q5 训练和验证都差 → B 欠拟合
Original question (English) · [2 marks] A very restrictive model has poor training and validation performance. Which diagnosis is most consistent with these observations?
- A. Perfect generalisation because both scores are similar.
- B. Underfitting; the model may be too inflexible to capture the signal.
- C. Test-set leakage proved by the low validation score.
- D. Overfitting proved solely by the low training score.
| 训练表现 | 验证表现 | 诊断 |
|---|---|---|
| 差 | 差 | 欠拟合(高偏差) |
| 好 | 差 | 过拟合(高方差) |
| 好 | 好 | 合适 |
A:两个分数接近不代表泛化好,可能是两边都差;C:泄漏通常让验证分数虚高;D:过拟合的特征是训练分数高。
知识点:W03 过拟合与欠拟合
English answer (Official): B — Underfitting. Poor performance even on training data suggests high bias or another learning problem. Similar poor scores do not establish good generalisation.
Q6 系数惩罚前为什么要缩放特征 → B
Original question (English) · [2 marks] Why is feature scaling often relevant before applying a coefficient penalty in linear regression?
- A. Scaling guarantees that every coefficient becomes zero.
- B. Feature units affect coefficient magnitudes, so penalties can otherwise act unevenly across features.
- C. A regularisation penalty is independent of coefficient magnitudes.
- D. Scaling makes validation unnecessary when selecting penalty strength.
- 答案 B:把某个特征从「米」换成「千米」,要得到同样的预测,它的系数就要放大 1000 倍;而 Ridge/Lasso 惩罚的是系数大小,所以单位不同的特征会被不公平地惩罚。先标准化,惩罚才对各特征一视同仁。
- A:缩放不会让系数变 0;C:正则项本身就是系数大小的函数;D:λ 仍需要验证集来选。
- 知识点:W03 正则化、W02 归一化/标准化
English answer (Official): B — Regularisation and scaling. Rescaling a feature changes the coefficient needed for the same prediction. A penalty on raw coefficients therefore depends on the feature units.
Q7 逻辑回归 z = 0 → D(概率 0.50,类 1)
Original question (English) · [2 marks] A logistic-regression model has score z = 0.8x − 1.2. For x = 1.5 and a decision threshold of 0.5, what are its positive-class probability and predicted class? Use class 1 when the probability is at least 0.5.
- A. Probability 0.00; class 0.
- B. Probability 0.50; class 0.
- C. Probability 1.00; class 1.
- D. Probability 0.50; class 1.
题目规定「概率 ≥ 0.5 取类 1」,所以 0.5 恰好归为类 1。B 是故意设的陷阱(概率对、边界条件错);A、C 把 z 当成了概率或把 σ 的取值范围搞错。
知识点:W03 逻辑回归
English answer (Official): D — Logistic regression calculation. The score is z = 0.8×1.5 − 1.2 = 0. A sigmoid at zero equals 1/(1+1) = 0.5, which meets the stated threshold for class 1.
Q8 朴素贝叶斯可以直接比较未归一化得分 → B
Original question (English) · [2 marks] Naive Bayes gives unnormalised class scores s_A and s_B for an observation. Why can the larger score be used directly for classification?
- A. The larger likelihood always wins even if the class priors differ.
- B. The common normalising denominator does not change which posterior is larger.
- C. The class priors can never influence the scores.
- D. The two class scores must always sum to one before normalisation.
两个类的后验除以同一个
- A、C 错在忽略先验:
里就含先验 ;D:只有归一化之后才和为 1。 - 知识点:W04 朴素贝叶斯
English answer (Official): B — Naive Bayes scores. Both posterior probabilities are obtained by dividing their nonnegative class scores by the same evidence term. The argmax is unchanged.
Q9 正类只占 2% 时准确率会骗人 → C
Original question (English) · [2 marks] A rare positive class forms 2% of observations. Why can accuracy alone conceal poor detection of positives?
- A. High accuracy guarantees high positive-class F1.
- B. Recall must equal accuracy on imbalanced data.
- C. A classifier predicting every observation as negative can still achieve 98% accuracy.
- D. Accuracy is mathematically undefined whenever classes are imbalanced.
全部预测为负:Accuracy = 98%,但 TP = 0,正类 Recall = 0,F1 = 0。不平衡数据要看正类的 Precision / Recall / F1。A、B、D 都是错误断言。
知识点:W04 评估指标
English answer (Official): C — Performance evaluation. Correctly classifying the majority class can dominate accuracy. Positive-class precision, recall and F1 reveal aspects of performance that accuracy can obscure.
Q10 由混淆矩阵算 Accuracy 和 F1 → A(0.85,≈ 0.667)
Original question (English) · [2 marks] A binary classifier has TP = 9, FN = 3, FP = 6 and TN = 42. What are accuracy and positive-class F1?
- A. Accuracy 0.85; F1 approximately 0.667.
- B. Accuracy 0.85; F1 0.850.
- C. Accuracy 0.70; F1 approximately 0.667.
- D. Accuracy 0.75; F1 0.750.
- B 把 F1 当成了准确率;D 的 0.75 是 Recall。
- 知识点:W04 混淆矩阵与 F1
English answer (Official): A — Classification metrics. There are 60 observations and 51 correct predictions, so accuracy = 51/60 = 0.85. F1 = 18/(18+6+3) = 18/27 ≈ 0.667.
Q11 完整树训练更好、验证更差 → A 剪枝减少了过拟合
Original question (English) · [2 marks] A fully grown tree performs better on training data but worse on validation data than a pruned tree. What is the most plausible explanation?
- A. Pruning reduced overfitting by simplifying the fitted tree.
- B. Training accuracy alone proves the larger tree is preferable.
- C. Pruning must have increased the number of leaf nodes.
- D. The validation observations were necessarily added to training.
完整树把噪声也拟合进去了(过拟合),剪枝牺牲一点训练拟合,换来更好的泛化。B 只看训练集;C 剪枝减少叶节点;D 没有依据。
知识点:W05 剪枝
English answer (Official): A — Tree pruning. A simpler tree may trade some training fit for better generalisation. The pattern is consistent with overfitting by the larger tree.
Q12 成员错误不相关的集成更好 → C
Original question (English) · [2 marks] Two ensembles have the same number of individually accurate classifiers. Why might an ensemble whose members make different errors perform better under voting?
- A. The number of classifiers is the only property that affects voting.
- B. Copying one fitted classifier creates independent errors.
- C. Less correlated errors give voting a greater opportunity to correct individual mistakes.
- D. Disagreement guarantees every majority prediction is correct.
投票能纠错的前提是成员犯错的地方不同(多样性):某个成员错了,其他多数还对。成员错误完全相关时(比如 B 里的复制品),加多少个都一样。D「guarantee」错。
知识点:W05 集成为什么有效
English answer (Official): C — Ensemble diversity. Voting benefits from useful diversity. If all members make the same error, adding identical copies cannot correct it.
Q13 Boosting 与 Bagging 的构造方式 → A
Original question (English) · [2 marks] Which statement best contrasts the usual construction of boosting with bagging?
- A. Boosting builds learners sequentially using the current ensemble's errors; bagging trains on bootstrap resamples.
- B. Boosting always uses identical copied learners; bagging never uses resampling.
- C. Both methods must produce exactly the same fitted ensemble.
- D. Bagging requires each learner's predictions before the next training set can be weighted.
| Bagging | Boosting | |
|---|---|---|
| 训练方式 | 并行、相互独立 | 串行,后一个依赖前面的错误 |
| 数据 | bootstrap 有放回抽样 | 对错分样本加权(AdaBoost)或拟合残差(Gradient Boosting) |
| 主要降低 | 方差 | 偏差 |
D 描述的其实是 Boosting;B、C 明显错误。
English answer (Official): A — Boosting versus bagging. Boosting uses sequential corrections, such as reweighting errors or fitting residuals. Bagging creates bootstrap training sets and can train learners independently.
Q14 线性 SVM 打分 → A(1.5,类 +1)
Original question (English) · [2 marks] An SVM decision score is g(x) = wᵀx + b, with w = (1, −2), b = 0.5 and x = (3, 1). Predict class +1 if g(x) is positive, otherwise class −1. What are the score and prediction?
- A. Score 1.5; class +1.
- B. Score −1.5; class −1.
- C. Score 0.5; class −1.
- D. Score 5.5; class +1.
D 的 5.5 是把
知识点:W06 SVM 决策函数
English answer (Official): A — Linear SVM decision. The score is 1×3 − 2×1 + 0.5 = 1.5. It is positive, so the model predicts class +1.
Q15 硬间隔 SVM 的支持向量 → D
Original question (English) · [2 marks] In a separable hard-margin SVM, which observations are the support vectors?
- A. Every observation in the test set.
- B. All points farther from the decision plane than every other training point.
- C. Only observations with the largest raw feature values.
- D. Training points on the canonical support planes that determine the maximum-margin solution.
支持向量是落在
知识点:W06 最大间隔与支持向量
English answer (Official): D — SVM support vectors. For the hard-margin formulation, support vectors lie at the margin constraints and determine the fitted separating hyperplane.
Q16 只保留第一主成分可能伤害分类 → B
Original question (English) · [2 marks] PCA retains directions with high input variance. Why might retaining only the first component harm classification?
- A. PCA cannot be applied to labelled datasets even if labels are ignored.
- B. A lower-variance direction may contain information important for separating the classes.
- C. The first component is always the direction that best separates class labels.
- D. PCA maximises classification accuracy by definition.
PCA 是无监督的,只找方差最大的方向,不看标签。区分两类的信息可能恰好在方差小的方向上,丢掉它就分不开了。C、D 把 PCA 当成了有监督方法;A:忽略标签就可以用。
知识点:W06 PCA
English answer (Official): B — PCA and labels. PCA is unsupervised and does not optimise class separation. High-variance structure can be unrelated to the target labels.
Q17 保留至少 80% 方差 → A(3 个,87.5%)
Original question (English) · [2 marks] Exactly four principal components have variances 7, 4, 3 and 2. What is the smallest number of leading components needed to retain at least 80% of the total variance? Here d = 4; the total is the sum of all four variances.
- A. Three components, retaining 87.5%.
- B. Two components, retaining 68.75%.
- C. Four components, retaining 100%.
- D. Three components, retaining 80%.
总方差
| 保留个数 | 累计方差 | 比例 |
|---|---|---|
| 1 | 7 | 43.75% |
| 2 | 11 | 68.75% |
| 3 | 14 | 87.5% ✓ |
| 4 | 16 | 100% |
B 没到 80%;C 不是最少;D 个数对、百分比错。
知识点:W06 选择主成分个数
English answer (Official): A — PCA retained variance. The total is 16. The first two give 11/16 = 68.75%; the first three give 14/16 = 87.5%. Three is the smallest number meeting 80%.
Q18 多个仿射层但没有非线性激活 → C 整体仍是一个仿射映射
Original question (English) · [2 marks] A network contains multiple affine layers but no nonlinear activations. What can be said about the overall input-output mapping?
- A. It can represent every nonlinear function simply by adding more affine layers.
- B. Its outputs must always be zero.
- C. It can still be represented as one affine mapping.
- D. Its parameters cannot be learned by gradient descent.
叠多少层都能合并成一层,表达能力等于线性模型。所以多层网络必须有非线性激活。B、D 没有依据。
知识点:W07 激活函数
English answer (Official): C — Nonlinear neural networks. Composing affine maps gives another affine map. Nonlinear activations are needed for the usual nonlinear representational benefit of multilayer networks.
Q19 感知机一步更新 → C(w = (0.0, 0.5),b = −0.5)
Original question (English) · [2 marks] A perceptron has w = (−0.1, 0.3), b = −0.6 and η = 0.1. For x = (1, 2), its supplied actual output is a = 0 and target is t = 1. What are the updated weights and bias?
- A. w = (−0.2, 0.1); b = −0.7.
- B. w = (−0.1, 0.3); b = −0.5.
- C. w = (0.0, 0.5); b = −0.5.
- D. w = (0.0, 0.5); b = −0.6.
感知机学习规则:
- A 符号反了(减去了更新量);B 只更新了 b;D 只更新了 w。
- 知识点:W07 感知机学习规则
English answer (Official): C — Perceptron update. η(t−a) = 0.1. Add 0.1(1,2) to the weights, giving (0,0.5), and add 0.1 to the bias, giving −0.5.
Q20 后层组合前层的边缘特征 → B 层级特征
Original question (English) · [2 marks] A later CNN layer combines several edge-like features from an earlier layer. What does this illustrate?
- A. Convolutional filters must remain fixed before training begins.
- B. Hierarchical construction of more complex features from simpler learned features.
- C. Each added layer necessarily reduces the effective receptive field.
- D. Every later layer discards the earlier feature maps and starts from raw labels.
CNN 逐层构建特征:边缘 → 纹理/角点 → 部件 → 物体,越往后有效感受野越大(C 说反了)。A:滤波器是学出来的;D:后层输入正是前层的特征图。
知识点:W08 CNN 层级特征
English answer (Official): B — CNN representations. Successive CNN layers combine earlier features and often integrate information over larger effective receptive fields.
Q21 RNN 展开 10 步和 20 步的参数量 → C 不变(时间上共享权重)
Original question (English) · [2 marks] A simple RNN is unrolled over ten time steps and then over twenty time steps, with the same input and hidden dimensions. What happens to its recurrent parameter count?
- A. It becomes zero because states replace parameters.
- B. It doubles because every time step has independent recurrent weights.
- C. It stays the same because the recurrent weights are shared across time.
- D. It depends only on the number of training labels.
知识点:W08 RNN 展开
English answer (Official): C — Recurrent weight sharing. Unrolling shows repeated uses of the same recurrent mapping. More time steps add computations and states, not independent copies of the learned matrices.
Q22 卷积层参数量 → C(78)
Original question (English) · [2 marks] A convolutional layer has three 5 × 5 filters, one input channel and one bias per filter. How many trainable parameters are there?
- A. 150.
- B. 26.
- C. 78.
- D. 75.
通式:
知识点:W08 卷积层参数
English answer (Official): C — CNN parameters. Each filter has 5×5×1 = 25 weights plus one bias. Three filters contain 3×26 = 78 parameters.
Q23 训练损失降、验证损失升 → A 保留验证最好的检查点
Original question (English) · [2 marks] A network's training loss keeps decreasing while validation loss has begun to increase. Which action is consistent with early stopping?
- A. Retain the checkpoint with the best validation performance.
- B. Choose the final epoch using the reserved test labels.
- C. Delete the validation set and report training loss as generalisation performance.
- D. Always keep training until training loss is exactly zero.
早停:监控验证损失,在它开始上升(过拟合开始)时停,并回到验证最好的那个 epoch 的权重。B 用测试集调参会造成泄漏;C、D 都只看训练损失。
知识点:W07 早停与正则化
English answer (Official): A — Early stopping. Early stopping treats validation performance as a guide to training duration. A later checkpoint with lower training loss may generalise worse.
Q24 凝聚式层次聚类的基本操作 → D 按链接方式合并最近的两个簇
Original question (English) · [2 marks] An agglomerative hierarchical algorithm begins with each observation in its own cluster. What is its basic next operation?
- A. Split the largest cluster into two equal-sized subsets.
- B. Fit a sigmoid output to each cluster label.
- C. Assign each observation an independent new random class.
- D. Merge the closest pair of current clusters according to the selected linkage rule.
凝聚式(自底向上):每轮合并距离最近的两个簇,簇间距离由链接方式(single / complete / average)定义。A 是分裂式(自顶向下)的思路;B、C 无关。
知识点:W09 层次聚类
English answer (Official): D — Agglomerative clustering. Agglomerative methods repeatedly merge clusters. The linkage definition determines how distances between the current clusters are calculated.
Q25 完全链与单链距离 → C(10 和 3)
Original question (English) · [2 marks] Clusters A = {1, 5} and B = {8, 11} contain one-dimensional points. Using absolute point-to-point distance, what are complete-link and single-link distances, respectively?
- A. Complete-link 3; single-link 10.
- B. Complete-link 10; single-link 6.5.
- C. Complete-link 10; single-link 3.
- D. Complete-link 6.5; single-link 3.
跨簇点对距离:
- 完全链 = 最大 = 10;单链 = 最小 = 3。
- 6.5 是平均链
,B、D 用它混淆;A 顺序反了。 - 知识点:W09 链接方式
English answer (Official): C — Complete and single linkage. Cross-cluster distances are 7, 10, 3 and 6. Complete-link takes the maximum, 10, while single-link takes the minimum, 3.
Q26 一阶马尔可夫假设 → D 已知当前状态后,更早的状态不再提供信息
Original question (English) · [2 marks] In a first-order Markov chain, what does conditioning on the current state imply about earlier states when predicting the next state?
- A. The chain must remain in its current state forever.
- B. All possible next states become equally probable.
- C. The next state becomes independent of the current state as well.
- D. Earlier states add no predictive information once the current state is known.
C 说反了:下一状态依赖当前状态;A、B 与转移概率无关。
知识点:W11 马尔可夫假设
English answer (Official): D — Markov assumption. The first-order Markov assumption makes the next-state distribution conditionally independent of the more distant past given the current state.
Q27 HMM 前向算法一步 → D(0.12)
Original question (English) · [2 marks] Forward probabilities at time 1 are f₁(A) = 0.2 and f₁(B) = 0.3. Transitions into A are P(A|A) = 0.6 and P(A|B) = 0.4. The next observation has emission probability 0.5 in A. What is f₂(A)? (a_jk is the transition from j to k; e_k(o_t) is the emission likelihood in state k.)
- A. 0.06.
- B. 0.25.
- C. 0.24.
- D. 0.12.
- C 0.24 忘了乘发射概率;A 0.06 只算了从 A 来的一条路径(
),没有求和。 - 知识点:W11 前向算法
English answer (Official): D — Forward algorithm. Forward sums predecessor contributions: 0.2×0.6 + 0.3×0.4 = 0.24. Multiplying by the emission probability 0.5 gives 0.12.
Q28 ε-greedy 为什么要随机选动作 → C 探索
Original question (English) · [2 marks] Under an epsilon-greedy action rule, why does the agent sometimes choose a random action?
- A. To guarantee the greedy action has a known optimal value.
- B. To make all Q-values remain constant during training.
- C. To explore actions that may otherwise be overlooked by the current value estimates.
- D. To remove the need to observe any rewards.
以概率 ε 随机选(探索),以
知识点:W12 探索与利用
English answer (Official): C — Exploration. Exploration collects information about actions beyond the one currently estimated to be best. Epsilon-greedy balances such exploration with exploitation.
Q29 DQN 的两种稳定技巧 → D
Original question (English) · [2 marks] Which pairing correctly matches two standard DQN stabilisation techniques to their roles?
- A. Replay sampling fixes the target weights; a target network samples stored transitions.
- B. Both techniques guarantee that training loss decreases after every update.
- C. Both techniques replace Q-values with class probabilities.
- D. Replay sampling reduces temporal correlation; a target network slows changes in bootstrap targets.
| 技巧 | 解决的问题 |
|---|---|
| 经验回放(experience replay) | 连续样本高度相关 → 从回放池随机抽小批量,打破时间相关性 |
| 目标网络(target network) | 目标 |
A 把两者的作用对调了;B「guarantee」错;C 无关。
知识点:W12 DQN
English answer (Official): D — Replay versus targets. Replay and target networks address distinct sources of training instability: correlated data and rapidly moving bootstrap targets.
Q30 终止转移的 Q 更新 → B(3.50)
Original question (English) · [2 marks] A transition ends the episode. Q_old(s,a) = 4, reward r = 2 and α = 0.25. The terminal state has zero future return. What is the updated Q-value?
- A. 4.50.
- B. 3.50.
- C. 1.50.
- D. 2.00.
终止状态没有后续回报,目标就是
- A 4.5 是把误差符号弄反了;D 2.0 是直接用奖励替换(相当于 α = 1)。
- 知识点:W12 Q-learning 更新
English answer (Official): B — Terminal Q-learning. For a terminal transition the target is just r = 2. Hence Q_new = 4 + 0.25(2−4) = 3.5; there is no bootstrap contribution.
Part B:计算题
Q31 比较两个划分的信息增益(10 分)
Original question (English) · Question 31. Comparing two tree splits [10 marks]
A parent node contains ten examples: five positive and five negative. Split X gives children containing (5 positive, 0 negative) and (0 positive, 5 negative). Split Y gives children containing (4 positive, 1 negative) and (1 positive, 4 negative). Use 0 log₂0 = 0. Entropy is measured in bits.
- [5 marks] Calculate the parent entropy and the information gain for split X.
- [5 marks] Calculate the information gain for split Y and select the split preferred by information gain. Round non-integer results to three decimal places.
| 划分 | 子节点 1 | 子节点 2 |
|---|---|---|
| 父节点 | 5+ / 5− | |
| X | 5+ / 0− | 0+ / 5− |
| Y | 4+ / 1− | 1+ / 4− |
(a) 父节点熵与 IG(X)(5 分)
X 的两个子节点都是纯的,
(b) IG(Y) 与选择(5 分)
Y 的每个子节点比例都是 0.8 / 0.2:
两个子节点各占一半样本,加权熵仍是 0.7219:
评分:(a) 父节点熵 1 分、纯子节点熵 2 分、增益 2 分;(b) 子节点熵 2 分、加权与增益 2 分、选择 1 分。
知识点:W05 熵与信息增益
图解
flowchart TB
P["父节点 5+ / 5−<br/>H = 1"] -->|"划分 X"| X1["5+ / 0−<br/>H = 0"]
P -->|"划分 X"| X2["0+ / 5−<br/>H = 0"]
P -.->|"划分 Y"| Y1["4+ / 1−<br/>H = 0.7219"]
P -.->|"划分 Y"| Y2["1+ / 4−<br/>H = 0.7219"]
X1 --> GX["IG(X) = 1 − 0 = 1 ✓"]
X2 --> GX
Y1 --> GY["IG(Y) = 1 − 0.7219 ≈ 0.278"]
Y2 --> GY
English answer (Official)
H(parent) = −2 × 0.5 log₂ 0.5 = 1 bit. Both children in split X are pure, so H = 0 for each. Weighted child entropy is 0 and IG(X) = 1 bit.
Each Y child has proportions 0.8 and 0.2, so H = −(0.8×(−0.3219) + 0.2×(−2.3219)) = 0.7219 bits. Each child has weight 0.5, leaving the same weighted entropy. IG(Y) = 1 − 0.7219 = 0.2781 ≈ 0.278 bits. Prefer split X, whose gain is 1 bit.
Q32 感知机两步学习(10 分)
Original question (English) · Question 32. Two perceptron learning steps [10 marks]
A perceptron has initial weights w = (0.2, −0.1), bias b = −0.1 and learning rate η = 0.2. Its output is 1 when the net input is at least zero and 0 otherwise. Process the two examples in the listed order, updating immediately after each example: first x = (1,0), target t = 0; then x = (0,1), target t = 1.
- [5 marks] For the first example, calculate the net input, actual output, updated weights and updated bias.
- [5 marks] Using the updated parameters, repeat these calculations for the second example.
规则:
(a) 第一个样本 x = (1, 0),t = 0(5 分)
预测错了,
(b) 第二个样本 x = (0, 1),t = 1(5 分)
用更新后的参数:
又错了,
易错点:第二步必须用第一步更新后的
评分:每小问净输入与输出 2 分、参数更新 3 分。
知识点:W07 感知机学习规则
图解
flowchart LR
S0["初始<br/>w = (0.2, −0.1)<br/>b = −0.1"] -->|"x = (1,0), t = 0<br/>u = 0.1 → a = 1 ✗<br/>η(t−a) = −0.2"| S1["w = (0, −0.1)<br/>b = −0.3"]
S1 -->|"x = (0,1), t = 1<br/>u = −0.4 → a = 0 ✗<br/>η(t−a) = +0.2"| S2["w = (0, 0.1)<br/>b = −0.1"]
English answer (Official)
u = 0.2×1 + (−0.1)×0 − 0.1 = 0.1, so a = 1. The correction is η(t−a) = 0.2(0−1) = −0.2. New weights are (0.2, −0.1) − 0.2(1, 0) = (0, −0.1); new bias is −0.1 − 0.2 = −0.3.
Now u = 0×0 + (−0.1)×1 − 0.3 = −0.4, so a = 0. The correction is 0.2(1−0) = 0.2. Final weights are (0, −0.1) + 0.2(0, 1) = (0, 0.1); final bias is −0.3 + 0.2 = −0.1.
Q33 K-means 一轮迭代与簇内 SSE(10 分)
Original question (English) · Question 33. K-means update and within-cluster error [10 marks]
Run one complete K-means iteration with k = 2 on the points A = (0,0), B = (0,4), C = (6,0), D = (6,4), starting from μ₁ = A = (0,0) and μ₂ = D = (6,4). Assign every point using these initial centroids before updating either centroid.
- [5 marks] Calculate each point's two initial squared distances and give the cluster assignments.
- [5 marks] Calculate both updated centroids and the total within-cluster SSE for these assignments using the updated centroids.
(a) 平方距离与分配(5 分)
| 点 | 坐标 | 到 μ₁ = (0,0) | 到 μ₂ = (6,4) | 分配 |
|---|---|---|---|---|
| A | (0,0) | 0 | 36 + 16 = 52 | 簇 1 |
| B | (0,4) | 0 + 16 = 16 | 36 + 0 = 36 | 簇 1 |
| C | (6,0) | 36 + 0 = 36 | 0 + 16 = 16 | 簇 2 |
| D | (6,4) | 52 | 0 | 簇 2 |
簇 1 = {A, B},簇 2 = {C, D}。
(b) 更新质心与 SSE(5 分)
每个点到所属新质心都是竖直方向 2 个单位,平方距离为 4:
易错点:题目要求先用初始质心把四个点全部分完,再一起更新,不能分一个更新一个。
评分:(a) 距离 4 分、分配 1 分;(b) 两个均值 2 分、各点平方误差与求和 3 分。
知识点:W09 K-means 算法
图解
flowchart LR
subgraph C1["簇 1:μ₁ (0,0) → (0,2)"]
A["A (0,0)<br/>d² = 0 vs 52"]
B["B (0,4)<br/>d² = 16 vs 36"]
end
subgraph C2["簇 2:μ₂ (6,4) → (6,2)"]
C["C (6,0)<br/>d² = 36 vs 16"]
D["D (6,4)<br/>d² = 52 vs 0"]
end
C1 --> S["每点到新质心距离 2<br/>SSE = 4 × 4 = 16"]
C2 --> S
English answer (Official)
Squared-distance pairs (to μ₁, to μ₂) are A: (0, 52), B: (16, 36), C: (36, 16), D: (52, 0). Thus cluster 1 is {A, B} and cluster 2 is {C, D}.
The updated means are μ₁,new = (0, 2) and μ₂,new = (6, 2). Each of the four points is 2 units vertically from its assigned mean, so each squared distance is 4. Total SSE = 4 + 4 + 4 + 4 = 16.
Q34 HMM:Viterbi 解码与 Forward 评估(10 分)
Original question (English) · Question 34. Viterbi decoding and Forward evaluation [10 marks]
Use the HMM probabilities below for the observed sequence (x, y). In the transition table, rows are current states and columns are next states. For Viterbi decoding, keep the predecessor that attains each maximum. Use f₁(k) = V₁(k). a_jk is the transition from j to k. Give final probabilities to four decimal places.
- [5 marks] Calculate V₁(A), V₁(B), V₂(A) and V₂(B). Give the most probable complete hidden-state path and its joint probability with (x, y).
- [5 marks] Use the Forward algorithm to calculate f₂(A), f₂(B) and the total likelihood P(x, y). State why this likelihood differs from the probability of the single best path.
| 状态 | 先验 π | e(x) | e(y) | → A | → B |
|---|---|---|---|---|---|
| A | 0.6 | 0.7 | 0.3 | 0.6 | 0.4 |
| B | 0.4 | 0.4 | 0.6 | 0.3 | 0.7 |
(a) Viterbi(5 分)
初始化(观测 x):
递推(观测 y),取最大并记住前驱:
终止时
(b) Forward(5 分)
把 max 换成求和(
为什么不同:Forward
把所有隐状态路径(AA、AB、BA、BB)的概率加起来,得到观测序列的总似然;Viterbi
只取概率最大的那一条路径。所以
可以验算:四条路径概率 AA = 0.42×0.6×0.3 = 0.0756,AB = 0.42×0.4×0.6 = 0.1008,BA = 0.16×0.3×0.3 = 0.0144,BB = 0.16×0.7×0.6 = 0.0672,总和 0.2580,最大的是 AB。
评分:(a) 初始值 1 分、两个递推值 2 分、回溯与概率 2 分;(b) 两个前向值 2 分、求和 1 分、解释求和与取最大 2 分。
图解
flowchart LR
A1["t = 1(x)<br/>A: 0.6×0.7 = 0.42"] -->|"×0.6 = 0.252"| A2["t = 2(y)<br/>A: V = 0.3×0.252 = 0.0756<br/>f = 0.3×0.300 = 0.0900"]
B1["t = 1(x)<br/>B: 0.4×0.4 = 0.16"] -->|"×0.3 = 0.048"| A2
A1 ==>|"×0.4 = 0.168(最优)"| B2["t = 2(y)<br/>B: V = 0.6×0.168 = 0.1008<br/>f = 0.6×0.280 = 0.1680"]
B1 -->|"×0.7 = 0.112"| B2
B2 --> R["Viterbi:A→B,0.1008<br/>Forward:0.0900 + 0.1680 = 0.2580"]
A2 --> R
English answer (Official)
V₁(A) = 0.6×0.7 = 0.42 and V₁(B) = 0.4×0.4 = 0.16. V₂(A) = 0.3 × max(0.42×0.6, 0.16×0.3) = 0.0756, with predecessor A. V₂(B) = 0.6 × max(0.42×0.4, 0.16×0.7) = 0.1008, also with predecessor A. The best ending state is B, so the best path is A → B with joint probability 0.1008.
f₂(A) = 0.3(0.42×0.6 + 0.16×0.3) = 0.0900. f₂(B) = 0.6(0.42×0.4 + 0.16×0.7) = 0.1680. Thus P(x, y) = 0.0900 + 0.1680 = 0.2580. Forward sums contributions from all possible hidden paths, whereas Viterbi selects the largest single path contribution.
三套卷对比
| 题型 | Paper 1 | Paper 2 | Paper 3 |
|---|---|---|---|
| 距离 / kNN | 标准化参数从哪来、不加权 vs 1/d² 加权 | 曼哈顿 vs 欧氏、预测代价 | 增大 k 的效果、1/d² 加权投票 |
| 规则学习 | PRISM 加条件的目的 | 1R | PRISM 分离-征服 |
| 回归 / 正则化 | MAE 抗离群、L1 稀疏、最小二乘截距 | MAE/MSE 计算、Ridge | 欠拟合诊断、缩放与惩罚 |
| 逻辑回归 | — | 输出 0.83 的含义 | z = 0 时 σ = 0.5 的边界 |
| 朴素贝叶斯 | Laplace 平滑 | 条件独立分解 | 未归一化得分可直接比较 |
| 评估 | 调参时保留独立估计、Precision/Recall | CV 中的标准化、Recall/F1 | 不平衡数据、Accuracy/F1 计算 |
| 树与集成 | 两个划分比较、Bagging、梯度提升 | 树路径即规则、随机森林、AdaBoost | 剪枝、集成多样性、Boosting vs Bagging |
| SVM | 间隔 2/‖w‖、核技巧 | 多项式核计算、软间隔 C | 线性打分、支持向量定义 |
| PCA | 缩放改变 PC1、85% 方差 | PCA 不是挑原始列、90% 方差 | PCA 不看标签、80% 方差 |
| 神经网络 | ReLU 负输入、感知机更新、Dropout 目的 | 小批量梯度下降、梯度下降一步、Dropout 推断 | 无激活多层 = 仿射、感知机更新、早停 |
| CNN / RNN | 权重共享、循环隐状态、卷积参数 76 | 最大池化、输出尺寸、LSTM | 层级特征、卷积参数 78、RNN 权重共享 |
| 聚类 | 簇代表点 = 均值、GMM 后验 | GMM、单链/平均链 | 凝聚式操作、单链/完全链 |
| HMM | Viterbi 定义、两步转移 | 学习问题、Viterbi 一步 | 马尔可夫假设、前向一步 |
| RL | 经验回放、目标网络、Q 更新 | 折扣因子、DQN、期望回溯 | ε-greedy、DQN 两技巧配对、终止状态 Q 更新 |
| Part B | 信息增益 / 前向传播 / K-means / HMM Forward | 朴素贝叶斯 / 最小二乘 / 层次聚类 / 前向传播 | 信息增益 / 感知机两步 / K-means + SSE / Viterbi + Forward |
规律:
- Part B 每套都有一道神经网络计算(前两套是前向传播 + 把 ReLU 换成恒等,这套换成感知机两步更新)和一道聚类计算(K-means 或层次聚类)。
- 信息增益、K-means、HMM 在三套里各出现两次,HMM 这次把 Viterbi 和 Forward 放在同一题对比,两个算法的「max vs sum」要能一句话讲清。
- 选择题里 PCA 累计方差三套都考;kNN 加权投票、PRISM、感知机一步更新、卷积层参数量、Q-learning 更新、经验回放与目标网络都至少考过两次。这些是送分题,计算一定要稳。