WEEK 8
CHAPTER 8

Rational Decisions & Classical ML

Data → prediction → utility → action. A model that predicts well is not automatically a system that decides well.

Manga page: Taldykorgan. / Your account will be blocked! Verify your password! / Spam? Or real? / If I delete a real one, Aru misses her exam! / Two questions: how LIKELY is spam, and what does each MISTAKE cost?

Part 1: Choosing under uncertainty

Recall: a rational agent maximises expected performance using the evidence available before acting. A bad outcome doesn't prove a bad decision. Probability alone isn't enough either: 90% success can be unattractive if failure is catastrophic. We need a utility, a number for how much we prefer each outcome.

EU(a) = Σᵢ P(oᵢ | a) · U(oᵢ) a* = argmaxₐ EU(a) (Maximum Expected Utility, MEU)
SuccessFailureExpected utility
Project A90% · (+100)10% · (−20)90 − 2 = 88
Project B60% · (+200)40% · (−50)120 − 20 = 100 ★

B has a lower success probability but a higher expected utility, so a risk-neutral agent picks B. A risk-averse agent (concave utility for money) might still prefer A. Utility encodes preferences; it isn't the same as money.

From belief to action: the maintenance threshold

Bayesian inference tells us what to believe; decision theory tells us what to do. If continuing costs p·C_failure in expectation and maintenance costs C_maint (and fully prevents failure):

maintain if p_failure > C_maint / C_failure e.g. 2,000 / 10,000 = 0.20

The threshold of 20% follows from costs, not from model accuracy. Practice: p = 15%, failure = $20,000, maintenance = $2,000. Continuing costs 0.15·20,000 = $3,000 in expectation, more than $2,000, so maintain and save $1,000 in expectation.

The spam decision (lecture example)

Suppose P(Spam) = 0.8. Deleting a legitimate message costs 100, delivering spam costs 5, and a quarantine folder costs 2 either way.

ActionExpected costEU
Delete0.8·0 + 0.2·100 = 20−20
Deliver0.8·5 + 0.2·0 = 4−4
Quarantine0.8·2 + 0.2·2 = 2−2 ★

An "80% spam" prediction still shouldn't be deleted! Deleting beats delivering only when P(Spam)·5 > (1 − P)·100, which means P(Spam) > 100/105 ≈ 95.2%.

Part 2: Machine learning

Classical programming: humans write the rules (IF temperature > 80: alarm). Real data are noisy, classes overlap and patterns are nonlinear. Machine learning takes examples with outcomes and learns a model ŷ = fθ(x) with parameters θ that predicts new cases.

Workflow: collect labelled examples → split into training and test sets → fit → evaluate on unseen data → deploy. Avoid data leakage: test information must never influence training.

Supervised

Learn from labelled examples (input → known answer). Failure detection, spam filtering. Algorithms: regression, trees, Naive Bayes.

Unsupervised

Find structure without labels. Customer segments, operating modes. Algorithms: K-Means, PCA.

Reinforcement

Learn a policy from rewards by trial and feedback (Chapter 5). Robot control, maintenance timing.

Regression: predict a number

ŷ = w·x + b e.g. consumption = 5·temperature + 100 → at 30 °C: 250 kWh MSE = (1/n) Σ (yᵢ − ŷᵢ)² an error of 10 costs 100, an error of 2 costs only 4

Training finds w and b that minimise the mean squared error (MSE). Other metrics: MAE, RMSE, R².

Classification: predict a class or a probability

Logistic regression squeezes a linear score into a probability with the sigmoid:

P(y = 1 | x) = σ(wᵀx + b), σ(z) = 1 / (1 + e^(−z)) σ(0) = 0.5, σ(2) ≈ 0.881, σ(−2) ≈ 0.119

A class decision still needs a threshold τ. The default 0.5 is not always right: when missed failures are expensive, τ might be 0.2 or lower. The threshold is a decision policy, not a property of the model.

Decision trees learn transparent IF–THEN splits ("Temperature > 70 °C? → Vibration > 3? → Failure"). They're easy to explain but deep trees overfit. Random forests train many trees on bootstrap samples with random feature subsets and vote, which lowers variance. k-nearest neighbours classifies a point by the majority label of its k closest training examples.

Naive Bayes: Bayes' theorem + a bold assumption

Assume the words are conditionally independent given the class (the "naive" part). Then:

P(Spam | words) ∝ P(Spam) · Π P(wordᵢ | Spam) lecture: Score(Spam) = (4/10)·(3/4)·(3/4) = 0.225 Score(Legit) = (6/10)·(1/6)·(2/6) ≈ 0.033 → Spam

The assumption is usually false (words come in phrases), yet Naive Bayes works well for text, trains in one pass and was the classic spam filter for years.

TRY IT! Bota's spam filter: Naive Bayes + an expected-cost decision

Trained on 12 tiny example messages (6 spam, 6 legitimate) with Laplace smoothing (+1 to every word count, so a known word missing from one class doesn't zero everything out). Words never seen in training are ignored.

P(Spam | message) = – → decision: –

Evaluating classifiers: accuracy is not enough

Predicted failure
Predicted normal
Actual failure
TP
FN (missed!)
Actual normal
FP (false alarm)
TN
Accuracy = (TP + TN) / N Precision = TP / (TP + FP) "how many alarms were real?" Recall = TP / (TP + FN) "how many failures did we catch?" F1 = 2·P·R / (P + R)

The 98% trap: if only 2% of machines fail, a model that always says "normal" is 98% accurate with 0% recall. Model A (95% accuracy, 60% recall) can be worse than Model B (92% accuracy, 90% recall) when missed failures are dangerous.

TRY IT! Move the threshold: the precision vs recall trade-off

20 machines sorted by the model's failure score (0 → 1). Red = actually failed, white = fine.

Unsupervised: K-Means clustering

No labels, only similarity. K-Means: choose K centroids → assign each point to the nearest → move each centroid to the mean of its points → repeat until stable. It minimises J = Σₖ Σx∈Cₖ ‖x − μₖ‖². Scale features first (spending in tenge would swamp purchase counts), and remember that cluster numbers have no meaning until a human interprets them.

Risks that break real systems

  • Overfitting: memorising noise. Great on training data, poor on new data.
  • Data leakage: using information that won't be available at prediction time.
  • Distribution shift: new conditions differ from the training data (a new machine model, winter instead of summer).
  • Calibration error: "70% risk" should come true about 70% of the time. For decisions, trustworthy probabilities can matter more than raw accuracy.
integrated rational ML: a* = argminₐ Σₒ P(o | x, a) · C(o, a)
REAL WORLD

Banks flag fraud with classifiers and then choose actions by cost: block the card, send an SMS check, or allow. Factories predict failure and maintain by threshold. Hospitals tune recall high for screening tests. The ML model provides the probability; the cost model provides the decision.

AI vs HUMAN

People struggle to combine many weak clues consistently; simple statistical models often beat expert intuition at that. Humans are far better at noticing when the situation is new and the model's assumptions no longer hold. Good systems keep both in the loop.

MINI-QUIZ

1. Route A: 80% success (+100) / 20% failure (−50). Route B: 95% (+80) / 5% (−20). MEU chooses…

EU(A) = 80 − 10 = 70; EU(B) = 76 − 1 = 75.

2. Only 2% of cases are failures. A model always predicting "normal" has accuracy…

98% accuracy, but 0% recall: it never finds a single failure. Accuracy hides the minority class, so check recall and precision.

3. Maintenance costs $2,000, failure costs $10,000. Maintain when P(failure) exceeds…

Threshold = C_maint / C_failure = 0.2.

4. Grouping customers with no labels is…

No target labels means unsupervised. K-Means is the classic example.
Manga page: Inbox clean! / Aru... how does my BRAIN learn?
8