Joyous Brands

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"
TypeLearns fromExample
Supervised: classificationLabeled examples, category answersFraud or not
Supervised: regressionLabeled examples, number answersHouse price
UnsupervisedUnlabeled dataCustomer groups
ReinforcementRewards over timeGame 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.

Fit the pattern, not the noiseSame ten training points, three models of increasing flexibilityUnderfit: too simplemisses the arch entirelyGood fitcaptures the trend; works on new dataOverfit: memorized noiseperfect on training, poor on new data
  • 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 finds groups nobody labeledEach dot is a shopper placed by buying habits; each X is a cluster center (k = 3)New parentsGym regularsBulk shoppersNames added by people afterward
  • 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.

97% accurate, yet it misses 1 in 5 sick patients1,000 patients, 50 actually sickFlagged sickNot flaggedActually sickActually healthy40true positives10missed (false negatives)20false alarms930true negativesPrecision 67%of 60 flagged, 40 are sickRecall 80%of 50 sick, 40 are caughtAccuracy 97%970 of 1,000 correct
  • 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

  1. Sketch the three fit panels from memory and label which has the lowest training error.

  2. Draw a confusion matrix for a spam filter of your own and compute precision and recall.

  3. Draw two clusters that k-means would split wrongly (hint: try long, curved shapes).