Which measurements matter

Plot sixty fruit using any two of four measurements and see which ones let a model tell apples from oranges.

NoviceExplained in Turning things into numbers

Which measurements tell apples from oranges?

Sixty fruit, measured four ways. Choose two measurements to plot and see how well a model can tell the fruit apart using only those.

Across
Up
Fruit a model gets right27 of 60 (45%)
VerdictAbout as good as guessing

Challenges

0 of 3 complete

  1. Try a few pairs, then come back to the worst one: the pair where the model gets fewer than half the fruit right. (not yet)
  2. Find two measurements that let the model get all 60 fruit right. (not yet)
  3. Without using Bumpiness, get at least 55 of the 60 right. (not yet)

Try this

  • Compare Weight and Width with Bumpiness and anything else.
  • Find the pair of measurements that works worst, then the pair that works best.
Optional: the same idea in codePython with NumPy
import numpy as np

# Ten made-up fruit. Each row is one fruit, measured three ways:
# weight (g), width (cm), skin bumpiness (0 to 10).
fruit = np.array([
    [175, 7.6, 0.6],   # the first five are apples
    [182, 7.6, 1.4],
    [169, 7.4, 0.9],
    [155, 7.1, 1.6],
    [165, 7.4, 1.6],
    [153, 7.3, 6.9],   # the last five are oranges
    [176, 7.3, 5.0],
    [204, 7.8, 6.6],
    [164, 7.1, 7.0],
    [161, 7.1, 7.1],
])
is_apple = np.array([True] * 5 + [False] * 5)

# The demo asks 5 neighbors out of 60 fruit; with only ten fruit, 3 is enough.
def fruit_right(columns, k=3):
    """Guess each fruit from its k nearest other fruit; count the right guesses."""
    x = fruit[:, columns]
    # Rescale each measurement to average 0 and spread 1, so grams
    # do not drown out the 0 to 10 bumpiness scale.
    x = (x - x.mean(axis=0)) / x.std(axis=0)
    right = 0
    for i in range(len(x)):
        distance = np.sqrt(((x - x[i]) ** 2).sum(axis=1))
        distance[i] = np.inf  # a fruit may not vote for itself
        # The k closest other fruit vote, and the majority wins.
        nearest = np.argsort(distance, kind="stable")[:k]
        apple_votes = is_apple[nearest].sum()
        guess_apple = apple_votes > k / 2
        right += guess_apple == is_apple[i]
    return right

print("weight and width:    ", fruit_right([0, 1]), "of 10 right")
print("weight and bumpiness:", fruit_right([0, 2]), "of 10 right")
weight and width:     5 of 10 right
weight and bumpiness: 10 of 10 right

Try "embedding", "softmax", "overfitting", or "backpropagation".