← Machine learning with Gradio

Machine learning with Gradio: recap

For after the lessons: one card per lesson, to check what you remember. Answer each question in your head or on paper first, then check it. Nothing here is marked.

Models by hand

1. Rules by hand

Try firstWhat does it mean that the rules are 95% accurate on the penguins?

Check your answer

They give the right species for 95 of every 100 penguins in the data (324 of 342).

  1. A model takes measurements and gives an answer: here, if rules on bill and flipper length.
  2. Accuracy is how many it gets right out of all: 324 of 342 penguins, 95%.
  3. A person chose the rule's numbers; machine learning finds them from the data.
Open the lesson →

2. The nearest penguin

Try firstHow does a nearest-neighbour model guess a new penguin's species?

Check your answer

It finds the penguin in its data with the closest measurements and gives that penguin's species.

  1. The distance between two penguins is Pythagoras on their bill and flipper lengths.
  2. nearest() finds the penguin in the data with the smallest distance to the mystery one.
  3. The guess is that penguin's species; a small distance means a confident guess.
Open the lesson →

3. A fair test

Try firstWhy does a model need a test set it has never seen?

Check your answer

On data it learned from it can just remember the answers; only new data shows how well it will do on penguins it meets later.

  1. Shuffle the penguins, then split them: a training set to learn from and a test set to check with.
  2. On its own training penguins the model scores 100%: each one's nearest match is itself.
  3. The test set shows how good it really is: about 95% on penguins it has never seen.
Open the lesson →

Real tools

4. The same model in scikit-learn

Try firstWhat does model.fit(X_train, y_train) do?

Check your answer

It gives the model the training examples to learn from (for nearest neighbour, it keeps them to compare with later).

  1. train_test_split shuffles the penguins and keeps a quarter back for testing.
  2. fit learns from the training penguins; score tests on the held-back ones.
  3. predict guesses a new penguin's species from its measurements.
Open the lesson →

5. A model behind an app

Try firstWhy does the app say 60% sure for some penguins?

Check your answer

Only 3 of the 5 most similar penguins in the data are that species, so the measurements sit between two species.

  1. The model is trained on every penguin, then wrapped in a function the app calls.
  2. The sliders become a one-row table with the same columns as training, and the model predicts.
  3. predict_proba gives the share of the 5 nearest penguins voting for the answer: how sure it is.
Open the lesson →