03 Text Classification - Cheat Sheet
Up: 03 Text Classification - Index | 03 Text Classification - Mind Map
Core definitions
- Bayes rule (s.13): : posterior = likelihood x prior / evidence. Concept - Bayes Rule
- MLE vs MAP ; equal for a uniform prior (s.18-19). Concept - Maximum Likelihood Estimation, Concept - Maximum A Posteriori
- Naive Bayes (s.23): , assuming attributes are independent given the class. Often violated, still works well. Concept - Naive Bayes, Concept - Conditional Independence
- Parameter estimate (s.28): from a per-class mega-document.
- Zero probability / OOV: an unseen word zeroes the whole product. Fix: additive smoothing ( is Laplace; add a pseudo-count to every word). Concept - Zero Probability Problem, Concept - Additive Smoothing, Concept - Laplace Smoothing, Concept - Out of Vocabulary (OOV)
- Underflow: multiplying many small numbers; use the sum of logs instead. Concept - Underflow
- Why “naive” yet good: ignores word order (bag of words); high bias, low variance.
- Logistic regression: sigmoid on a linear score; trained with cross-entropy loss by gradient descent; linear decision boundary. Concept - Logistic Regression, Concept - Sigmoid Function, Concept - Cross-Entropy Loss, Concept - Gradient Descent, Concept - Decision Boundary
- Generative (NB: models ) vs discriminative (LR: models ). Concept - Generative vs Discriminative Models
Key comparison
| Method | Input features | Model of | Notes |
|---|---|---|---|
| Concept - Multinomial Naive Bayes | word counts / TF-IDF | $p(w | class)$ per word occurrence |
| Concept - Bernoulli Naive Bayes | binary presence/absence | presence prob. per word | Also penalizes absent words |
| Concept - Gaussian Naive Bayes | continuous values | one Gaussian per feature per class | Use log scores |
| Concept - Logistic Regression | any vector (e.g. BoW) | $p(y | x)$ directly |
| Concept - Decision Tree | attributes | recursive splits | Easy to read, prone to overfit |
Evaluation formulas
- Accuracy (misleading on imbalanced data); Precision ; Recall ; . Concept - Confusion Matrix, Concept - Precision and Recall, Concept - F1 Score
- ROC plots TPR vs FPR over thresholds; AUC = area under it. Concept - ROC Curve and AUC
- Multiclass: Concept - One-vs-All Classification or Concept - Softmax Classifier.
Decision trees
- ID3 greedily picks the attribute with the highest information gain , with entropy . Concept - ID3, Concept - Entropy, Concept - Information Gain
- IG favours many-valued attributes; gain ratio corrects this. Gini is the alternative criterion. Concept - Gain Ratio, Concept - Gini Impurity
- Continuous attributes: threshold splits. Concept - Splitting Continuous Attributes
- Overfitting is limited by pruning (pre: stopping criteria; post: validation set). Concept - Decision Tree Pruning, Concept - Overfitting
Ensembles
- Concept - Bagging: bootstrap samples + majority vote (Concept - Bootstrapping, Concept - Majority Voting); Concept - Random Forest = bagged trees with random feature choice. Reduces variance; helps unstable learners.
- Concept - Boosting: sequentially focus on errors of weak learners. Concept - Stacking: a meta-learner combines base models.
- Concept - Bias-Variance Tradeoff, Concept - No Free Lunch Theorem.
Worked numbers to remember
- Likes/dislikes: 300 of 1000 like, so , (s.27).
- Spam example: , ; “Dear Friend” scores 0.09 (normal) vs 0.01 (spam), so normal; “Lunch Money Money Money Money” gives spam 0 until smoothing (s.65-135).
- Gaussian NB Troll 2: log scores about -124 (loves) vs -48 (does not love), so “Does not love” (s.211-238).
Likely exam questions (across the deck)
- Explain Naive Bayes, the independence assumption and why it is “naive”. (s.21-23, 136-145)
- Describe the zero-probability problem and how smoothing fixes it. (s.29-30, 119-135)
- MLE vs MAP. (s.19)
- Multinomial vs Bernoulli vs Gaussian NB: when to use each. (s.146-181)
- Why use logs in NB? (s.204-214)
- Why is linear regression a poor classifier; what does the sigmoid fix? (s.253-263)
- Naive Bayes vs logistic regression (generative vs discriminative). (s.292-295)
- Define precision, recall, F1; why accuracy fails on imbalanced data. (s.272-283)
- ID3: compute entropy / information gain / Gini on a small table. (s.311-327)
- Overfitting, pruning, and how bagging/boosting/stacking differ. (s.331-360)
- Inter-annotator agreement and getting labels. (s.374-381)
See also Past Exam - Question Bank & Style Guide for the exam style.