📖 用法:每个知识点都是中文 + English 对照。中文理解概念,英文用于考场表达(考卷是英文)。绿框=举例,黄框=易错陷阱。 Each point is bilingual: Chinese to understand, English for the exam. Green = examples, yellow = common traps.
Q1 · 选择题 40分(覆盖全部主题)
Week 1 · 数据科学导论 (Introduction to Data Science)
1. 数据科学工作流 (Data Science Workflow)
数据科学是一个循环迭代的过程,真题考过让你给步骤排序。 Data science is an iterative pipeline; past papers ask you to put the steps in order.
Data Acquisition 数据获取 — 从数据库、API、网页爬取、传感器收集原始数据。 Collect raw data from databases, APIs, web scraping, sensors.
Data Storage 数据存储 — 把数据存进数据库或数据仓库。 Store the data in a database or data warehouse.
Data Cleaning & Transformation 清洗与转换 (ETL) — 去重、补缺失、统一格式与单位。 Remove duplicates, fill missing values, standardise formats and units.
Exploratory Data Analysis (EDA) 探索性分析 — 画图、看分布、找规律和异常。 Plot charts, inspect distributions, find patterns and anomalies.
Unstructured 非结构化 无固定结构。 No fixed format. 例 e.g.:文本、图片、音频、视频
高频对比 (Relational vs Semi-structured):
关系模型:每个属性必须有名字和类型、基于同质 tuple 集合、必须先定义 schema。 Relational: every attribute has a name & type; based on homogeneous tuples; schema must be defined first.
JSON/XML:可树状嵌套、自描述、无 schema 也能解析。 JSON/XML: tree-like nested, self-describing, can be parsed without a predefined schema.
3. Big Data 的判定 (When is it "Big Data"?)
课程定义:当数据量大到需要在多个处理节点(分布式)上处理时,才算 Big Data。 Course definition: a problem is "Big Data" when the volume is so large it must be processed on multiple nodes.
常用 3V 描述:Volume 体量、Velocity 速度、Variety 多样性。 Often described by the 3 Vs: Volume, Velocity, Variety.
❌ 错误说法 / Wrong claims:装不进内存就是大数据 (fitting in memory)、属于大公司就是大数据 (owned by a big company)、涉及隐私就是大数据 (privacy)。这些都不是课程定义。
4. 监督 vs 无监督学习 (Supervised vs Unsupervised)
Supervised 监督
Unsupervised 无监督
是否需要标签 Needs labels?
需要 Yes
不需要 No
任务 Task
分类 Classification、回归 Regression
聚类 Clustering、降维 Dim. reduction
例 Example
预测是否患病(有"患病/健康"标签) predict disease (labels given)
把客户分群(无预设群) segment customers (no preset groups)
考点 Exam point:若训练数据已知 class label → 既能做监督(用label)也能做无监督(忽略label)。答案常是 "either supervised or unsupervised"。 If labels are known, the data can be used for either supervised or unsupervised learning.
颜色(红/绿/蓝)无大小 → Nominal;学历(本科<硕士<博士)有高低 → Ordinal。 Colours have no order → nominal; education levels have a rank → ordinal.
Interval vs Ratio:看有没有 absolute zero (0 是否=没有)
关键:0 这个值是否代表"完全没有这个量"。是→Ratio;只是参考点→Interval。 Key: does 0 mean "none of the quantity"? Yes → ratio; just a reference point → interval.
关键举例 Examples:
摄氏 °C = Interval:0°C 不是"没有温度"(只是水冰点),所以 20°C 不是 10°C 的两倍热。 0°C is not "no temperature", so 20°C is not twice as hot as 10°C.
开尔文 Kelvin = Ratio:0K = 绝对零度(真没热能),200K 确实是 100K 的两倍。 0K is absolute zero, so 200K really is twice 100K.
年份 Year = Interval;重量 kg = Ratio(0kg=没有重量)。
口诀:能说"X 是 Y 的几倍"的就是 Ratio。 / Rule: if "X is N times Y" makes sense, it's ratio.
2. 适用的描述统计 (Which statistic for which type?)
统计量 Statistic
Nominal
Ordinal
Interval
Ratio
Mode 众数
✓
✓
✓
✓
Median 中位数
✗
✓
✓
✓
Mean 均值
✗
✗
✓
✓
Std/Variance 标准差/方差
✗
✗
✓
✓
逻辑:统计量需要的运算,data type 得支持才有意义。 Logic: a statistic is only meaningful if the data type supports the maths it needs.
举例 Example:5 人满意度 1,2,3,4,5 (ordinal)。算 mean=3 没意义,因为"1→2"和"4→5"的差距不一定相等。 Mean is meaningless for ordinal because gaps between ranks aren't equal.
工资 3,4,5,6,100万 (ratio,有 outlier):mean=23.6万被老板拉高,median=5万更代表典型值。 With an outlier, the median (5) represents the typical value better than the mean (23.6).
必记 Must remember:Nominal 只能 mode;Ordinal 用 mode/median,不能 mean;要算 std 必须先能算 mean → 只有 Interval/Ratio 能算 std。
3. 集中趋势 vs 离散程度 (Central Tendency vs Dispersion)
Central Tendency 集中趋势 中心在哪里 / where the centre is Mean 均值 · Median 中位数 · Mode 众数
Dispersion 离散程度 数据多分散 / how spread out Min · Max · Range 极差 · Variance 方差 · Std 标准差 · IQR
真题考点 Exam:哪些是 dispersion?答案 = Min, Max, Range, Variance, Std。Mode/Median/Count 不是。 Range = Max − Min;IQR = Q3 − Q1 (不受 outlier 影响 / robust to outliers)。
4. 分布形状 / 偏态 (Skewness)
形状 Shape
长尾在 Tail
三量关系 Relation
例 Example
对称 Symmetric
无 none
mean ≈ median ≈ mode
身高 height
右偏(正偏) Right-skewed
右 right
mean > median > mode
工资、房价 income, house price
左偏(负偏) Left-skewed
左 left
mean < median < mode
很容易的考试分数 easy-exam scores
口诀 Rule:尾巴在哪边就是哪边偏;mean 被尾巴拽走。判定:mean > median → 右偏;mean < median → 左偏。 The tail decides the skew; the mean is pulled towards the tail.
Week 5 · 数据库查询 (SQL)
1. 语句结构 & 执行顺序 (Clauses & Execution Order)
SELECT col / agg -- 5 选哪些列 which columns
FROM table -- 1 哪张表 which table
WHERE row filter -- 2 行过滤(聚合前,不能用聚合) filter rows
GROUP BY col -- 3 分组 group
HAVING group filter -- 4 组过滤(聚合后,可用聚合) filter groups
ORDER BY col [DESC] -- 6 排序 sort
LIMIT n -- 7 取前 n 行 top n
GROUP BY 黄金法则 Golden rule:SELECT 里出现的列,要么在 GROUP BY 里,要么被聚合函数包住,否则报错。 Every column in SELECT must be in GROUP BY or wrapped in an aggregate.
3. WHERE vs HAVING (高频考点)
WHERE
HAVING
过滤对象 Filters
行 rows (聚合前)
组 groups (聚合后)
能用聚合? Aggregate?
✗ 不能 No
✓ 能 Yes
位置 Position
GROUP BY 之前 before
GROUP BY 之后 after
举例 Example:找"总额>100 的客户" / customers with total > 100:
SELECT CustomerID, SUM(Amount)
FROM Orders
GROUP BY CustomerID
HAVING SUM(Amount) > 100; -- 用 HAVING (SUM 是聚合)
❌ 不能写 WHERE SUM(Amount)>100 (WHERE 不能用聚合 / can't use aggregates)。
4. DISTINCT / JOIN / ORDER BY+LIMIT 模板 (2017 冰淇淋题)
-- a) 3月有销售的 unique 门店 / unique stores with March sales
SELECT DISTINCT store_id FROM Tx WHERE month = 3;
-- b) 3月卖出的 unique 冰淇淋名 (多表 JOIN) / multi-table join
SELECT DISTINCT i.name
FROM Tx t
JOIN Tx_IceCream ti ON t.tx_id = ti.tx_id
JOIN IceCream i ON ti.icecream_id = i.icecream_id
WHERE t.month = 3;
-- c) 每月 total / avg / count
SELECT month, SUM(value), AVG(value), COUNT(*)
FROM Tx GROUP BY month;
-- d) 平均售价>=5 的 top-3 门店(按总销售降序)
SELECT store_id, SUM(value) AS total
FROM Tx
GROUP BY store_id
HAVING AVG(value) >= 5
ORDER BY total DESC
LIMIT 3;
5. 日期/时间运算 (Date/Time arithmetic, 24S1真题)
SELECT event_timestamp + INTERVAL '36 hours' AS new_ts,
event_date + INTERVAL '1 day' AS new_date
FROM EventSchedule;
把高维数据投影到少数主成分(principal components),保留最大方差方向,去冗余。用途:可视化、加速、降噪、缓解维度灾难。 Project to few principal components keeping max variance; for visualisation, speed, denoising.
Week 9 · 线性回归与逻辑回归 (Linear & Logistic Regression)
1. 简单线性回归 (Simple Linear Regression)
在因变量 Y 与一个自变量 X 之间找最佳拟合直线。 Finds the line of best fit between Y and ONE independent variable X.
模型 Y = α + βX,学 α 截距(交 y 轴) 和 β 斜率。 Learns intercept α and slope β.
✗ 不属于 cleansing Data anonymization 匿名化(那是隐私保护,不是清洗) Anonymisation is privacy protection, NOT cleansing.
3. 七大数据质量问题 (7 Data Quality Issues) — Sample Q2 大题必考
#
类型 Issue (术语)
长什么样 Looks like
清洗 Cleaning
1
Missing value 缺失值
"missing"/"unknown"/空/NaN
替换 NaN,数值→median,类别→mode
2
Duplicate 重复
整行出现两次 (D009)
drop_duplicates()
3
Invalid value 无效值
PackageWeight=-1.2 (负重量)
→NaN 再 median 填
4
Out-of-range 超范围
Rating=6 但范围1–5
→NaN,删或 mode 填
5
Inconsistent format 格式不一
2024-04-01 vs 01/04/2024
统一成 YYYY-MM-DD
6
Inconsistent labels 标签不一
Metro/metro/REG/Regional
转小写+字典映射统一
7
Outlier 异常值
DeliveryTime=999, Weight=30
先调查真伪,再删/保留
答题三段式 (3-part format for full marks):
① Issue: Row X, column Y is [value] → this is a [issue type 术语].
② Why: It is a problem because [影响:让统计/模型出错 distorts stats/model].
③ Cleaning: [方法 method], because [理由 reason: median is robust to outliers / rating is ordinal so use mode].
范例 Sample answer: Issue: In row D005, PackageWeight is the text "missing" — a missing value encoded as text. Why: Python won't treat it as NaN, so numeric operations (mean/std) will fail. Cleaning: Replace "missing" with NaN, then impute with the median, because the median is robust to outliers.
4. 关系型数据库好处 (Benefits of RDBMS) + 键 (Keys)
Declarative querying 声明式查询:只说"要什么结果",不写"怎么算"(SQL)。 Specify WHAT result you want, not HOW to compute it.
Schema + 约束保证数据一致性 integrity;减少冗余 redundancy。
PK vs FK:Primary Key 主键 唯一标识本表一行(如 CustomerID);Foreign Key 外键 在另一张表引用该 PK,用来 JOIN。 Primary key uniquely identifies a row; foreign key references another table's PK to join.
Week 3 · 探索性数据分析与可视化 (EDA & Visualization)
1. EDA 是什么、为什么 (What & Why)
EDA = 建模前"先看一眼数据"。目的:① 了解分布 distribution;② 找变量间关系 relationships;③ 发现异常 anomalies (outlier/missing/错误)。 EDA = look at the data before modelling: understand distribution, find relationships, detect anomalies.
分析层级 Levels
Univariate 单变量:只看一列 / one variable (e.g. DeliveryTime 的分布)。
Bivariate 双变量:两列关系 / two variables (e.g. Distance vs Time)。
最易混 Most confused:看"分布"用 Histogram(一个变量);看"关系/A越…B越…"用 Scatter plot(两个变量)。 Distribution → Histogram (1 var); relationship → Scatter plot (2 vars).
3. 坏图诊断 (What's wrong with this chart?) — 真题简答
2017真题:对 5 种口味的 1–5 评分(ranking)画"Sum of Rankings vs Flavour",问哪里错?
答:评分是 ordinal 数据,对 ranking 求和(sum)没有统计意义(间距不等);应展示分布/median/mode。 Ratings are ordinal; summing rankings is meaningless because gaps aren't equal. Use distribution / median / mode instead.
易错 (24S1):support 与 confidence 相互独立——可高confidence低support、可低confidence高support、也可都低。 Support and confidence are independent; any combination is possible.
Training set 训练集:训练模型;用 cross-validation 交叉验证 做调参。 Train models; use cross-validation for tuning.
Development/Validation set 验证集:评估调参,但节制使用防过拟合。 Evaluate tuning, but use sparingly to avoid overfitting.
Held-out Test set 测试集:只用一次做最终评估;绝不放进训练,也不反复调参。 Use only ONCE for final evaluation; never include in training.
4. 过拟合 vs 欠拟合 (Overfitting vs Underfitting)
Overfitting 过拟合
Underfitting 欠拟合
训练集 Train
很好 good
差 poor
测试集 Test
差(泛化差) poor
差 poor
原因 Cause
学到噪声、太复杂、high variance
太简单、high bias
举例:Sample Q5 决策树 train acc=0.97 但 test acc=0.73 → 典型过拟合。高方差模型更易过拟合;增加数据/剪枝可缓解。 Train 0.97 vs test 0.73 = classic overfitting; more data or pruning helps.
5. 分类评估:混淆矩阵 (Confusion Matrix)
Predicted Yes
Predicted No
Actual Yes
TP 真阳
FN 假阴/漏报
Actual No
FP 假阳/误报
TN 真阴
Precision = TP / (TP + FP) ← 预测为正中真正是正的比例 (of predicted positives, how many right)
Recall = TP / (TP + FN) ← 真实正例中被抓到的比例 (of actual positives, how many caught)
F1 = 2·P·R / (P + R) ← P 和 R 的调和平均 (harmonic mean)
Accuracy = (TP + TN) / 全部 all
"最高 test acc/F1 ≠ 最该部署"理由 (why highest acc/F1 isn't enough):
① 类别不平衡时 accuracy 误导 (imbalanced → accuracy misleads);② 漏诊(FN)成本未体现,医疗需高 recall (cost of FN);③ 可解释性/部署成本/速度 (interpretability/cost);④ 单一测试集偶然性,需交叉验证 (single test set);⑤ 公平性与伦理 (fairness)。 不平衡举例:罕见病占1%,全猜"健康"也有99% accuracy 但 recall=0 → 必须看 recall/F1。
6. 模型横向对比 (Model Comparison) — Q5 必备
Q5 是 model comparison and evaluation,除了算指标,还要能横向比较不同模型的假设、优劣、适用场景。
模型 Model
假设 Assumption
优点 Pros
缺点 Cons
适用 When
Logistic 回归
线性决策边界,输出概率
可解释(系数/概率)、快
只能线性边界、需特征缩放、欠拟非线性
要可解释的二分类
决策树 Decision Tree
无分布假设,按信息增益贪心分裂
可解释(if-then规则)、处理非线性&类别、无需缩放
易过拟合、不稳定(数据小变树大变)
要规则可读
随机森林 Random Forest
多棵树投票(bagging)
准确率高、抗过拟合、稳健
可解释性差(黑盒)、计算重
要高准确率
朴素贝叶斯 Naive Bayes
给定类别下特征条件独立
极快、小数据好、天然多类、缺见组合仍可分
独立假设常不成立、0概率需 Laplace
文本/高维类别
kNN
近邻相似,惰性(无训练)
简单、非线性、无需训练
预测慢、需缩放、维度灾难、对k敏感
小数据低维
怎样公平比较 (how to compare fairly):用相同的 train/test 划分 + 相同指标(F1/AUC) + k-fold 交叉验证取平均,不要只看 accuracy(不平衡会误导)。 选哪个的 justify 句式:"I would use X because the data is/goal is ___"——要可解释→logistic/tree;要非线性&类别→tree/forest;高维/文本→NB;类别不平衡→看 F1 而非 accuracy;小数据→NB/kNN。
速查 · Cheat Sheet
📋 考前高频考点速查 (Cheat Sheet)
数据类型↔统计量 Data type ↔ stats:Nominal只mode,Ordinal加median但不能mean
Interval vs Ratio:绝对零点 absolute zero (Kelvin=Ratio, 摄氏/年份=Interval)