statable Statistics for study and research

How does a program learn from examples? (Supervised learning, classification, training and test data)

In brief

In supervised learning two things are known for many cases: features that can be measured, and the outcome that is to be predicted later. A method learns a rule from these examples. If the outcome is a category, such as female or male, this is called classification; if it is a number, regression. Whether the rule is any good shows only on cases the method did not see while learning. That is why the data are split into training data (for learning) and test data (only for checking).

An example with real data

For 333 Palmer penguins, bill depth, body mass and sex are known. Task: predict sex from the two measures. Drawn at random, 233 animals (70%) go into the training data and 100 into the test data; of the 100, 52 are female and 48 male. The method sees only the 233. Then it predicts sex for the 100 test animals, and only then is the comparison made.

When do I use it?

Requirements

How it works in Statable

  1. Open Understand > Learning lab > tab "Predicting (k-nearest neighbours)" (Ctrl+K: "predicting").
  2. Choose "Example: sex from bill depth and body mass". With seed 1 and 70% training data Statable splits the animals differently from R; the numbers in this article come from R and therefore differ a little. The picture stays the same.
  3. Move the slider k, switch "standardise measures" on and off and compare the sentences, the scatter plot, the confusion matrix and the error curve.

Reading and reporting the result

What to report: how the data were split (share, at random, seed), which method with which settings, and the error on the test data. One sentence is enough:

Sex was predicted from bill depth and body mass with k-nearest neighbours (k = 17, measures standardised); on 100 randomly held-out test animals the accuracy was 84%.

Limits

What is often misunderstood

Sources

James, G., Witten, D., Hastie, T. & Tibshirani, R. (2021). An Introduction to Statistical Learning (2nd ed.). Springer; free as PDF. Ch. 2.2 (classification, k-nearest neighbours, training and test error), ch. 4 (classification, confusion matrix, ROC), ch. 5.1 (cross-validation). Venables, W. N. & Ripley, B. D. (2002). Modern Applied Statistics with S (4th ed.). Springer (R package class, function knn). Data: Gorman, K. B., Williams, T. D. & Fraser, W. R. (2014). PLoS ONE, 9(3), e90081 (palmerpenguins, CC0).

Take away

  • Supervised learning: learn a rule for new cases from cases with a known outcome.
  • Training data for learning, test data only for checking, and nothing from the test data in the learning.

Related

Open in Statable