Artificial Intelligence: A Visual Learner's Series
Part 6: Machine learning
Instead of handing an agent its knowledge, let it learn from data, and check whether what it learned holds up.
Learning from examples
In one line: Show the computer many examples with the right answers and let it find a rule that reproduces them.
Past transactions + labels (fraud / ok) ──▶ learner ──▶ model
New transaction ──▶ model ──▶ "likely fraud"
| Type | Learns from | Example |
|---|---|---|
| Supervised: classification | Labeled examples, category answers | Fraud or not |
| Supervised: regression | Labeled examples, number answers | House price |
| Unsupervised | Unlabeled data | Customer groups |
| Reinforcement | Rewards over time | Game playing (Part 8) |
Watch out: A model learns whatever its labels encode, including human mistakes and bias.
Generalization and overfitting
In one line: The goal is predicting new cases well, and fitting the training data too closely is a common way to fail.
Train / validation / test: fit on the first, tune on the second, touch the third once at the end.
Regularization penalizes complexity; cross-validation rotates the held-out data.
Watch out: Every peek at the test set makes the final score more optimistic than reality.
Two classic models
In one line: Decision trees ask yes/no questions; linear models weigh each feature and add them up.
Decision tree Linear model
Income > $50k? score = 3×income + (−2)×debt + 1×years
├─ no → decline approve if score > threshold
└─ yes → Debt < $10k?
├─ yes → approve
└─ no → decline
Trees are easy to audit; random forests and boosted trees combine many of them.
Linear models learn weights by gradient descent, stepping downhill on the error:
Watch out: Too large a learning rate α bounces around; too small crawls.
Finding structure without labels
In one line: Even with no right answers, a computer can find natural groups or a simpler description of the data.
k-means: place k centers, assign each point to the nearest, move centers to their group's average, repeat.
PCA compresses many features into a few that keep most of the variation.
Watch out: k-means returns k groups whether or not the data truly has them.
Measuring honestly
In one line: One accuracy number can mislead; look at the kinds of mistakes a model makes.
Precision: of what you flagged, how much was right. Recall: of what was there, how much you caught.
Data leakage: training data secretly contains the answer, giving great test scores and useless real-world results.
Watch out: A sudden jump to near-perfect scores more often means leakage than a breakthrough.
Self-test
Sketch the three fit panels from memory and label which has the lowest training error.
Draw a confusion matrix for a spam filter of your own and compute precision and recall.
Draw two clusters that k-means would split wrongly (hint: try long, curved shapes).