Harmony Virtual Lab

Digital Technologies · Artificial intelligence and machine learning

Train a simple AI

Teach a computer to tell ripe plantain from unripe by giving it labelled examples, then test how accurate it is.

Start this experimentAll Digital Technologies experiments

Aim

To show how a machine-learning model learns from labelled examples, and how the amount and quality of training data affect its accuracy.

Apparatus

  • This simulator
  • A set of plantains to label (as data points)

Theory

Many AI systems learn from examples instead of being given rules. Here each plantain is described by two features: how yellow it is and how soft it is (both scored 0 to 1).

The model uses k-nearest neighbours: to classify a new plantain, it finds the k training examples most like it and takes a vote. We then test it on 40 plantains it has never seen and measure its accuracy.

Good AI needs enough examples, correctly labelled, that cover all the cases. Careless labels teach the model mistakes.

Procedure

  1. Choose a label (Ripe or Unripe) and tap the chart to add an example, or collect 10 labelled examples at once.
  2. Watch the shading: it shows what the model would predict everywhere on the chart.
  3. Test the model on 40 new plantains and record its accuracy.
  4. Add more examples and test again. Then try with careless labelling turned on.
  5. Change k and see how the predictions change.

What you do in the virtual lab

Set up the apparatus on screen, take readings and record them in a table (Training examples; k; Careless labels; Test accuracy (%)), then plot Test accuracy (%) against Number of training examples and read the result from the graph. Simulated instruments give slightly different readings each time, as real ones do. Finish with a short quiz; every answer is explained.

Teachers can set the experiment for a class, see each student’s results and use it as a WAEC- or NECO-style practical paper in exam practice.

Practice questions

  1. In machine learning, the examples used to teach a model are called

    1. training data
    2. test data
    3. hardware
    4. output
    Show the answer

    A. training data The model learns patterns from training data, then is checked on separate test data.

  2. Why is the model tested on plantains it has never seen?

    1. To save time
    2. Because the training data is lost
    3. To find out how well it works on new cases, not just the ones it memorised
    4. To make it learn faster
    Show the answer

    C. To find out how well it works on new cases, not just the ones it memorised Testing on new data shows whether the model has really learned the pattern.

  3. If many training examples are labelled wrongly, the model will

    1. correct the labels itself
    2. refuse to work
    3. become faster
    4. learn the mistakes and become less accurate
    Show the answer

    D. learn the mistakes and become less accurate A model can only be as good as its data: “garbage in, garbage out”.

Do the experiment and the full quiz

Related Digital Technologies experiments

  • Logic gates and truth tablesDigital Technologies · SSS 1 – SSS 2Switch the inputs of AND, OR, NOT, NAND, NOR and XOR gates and build each truth table.
  • Binary, octal and hexadecimalDigital Technologies · JSS 2 – SSS 1Flip eight bit-switches to see how computers store numbers, then hit target values in binary.
  • Programming a robot: sequence and loopsDigital Technologies · JSS 1 – SSS 1Write a program of moves and turns to steer a robot to its goal, then shorten it with a loop.
  • How strong is a password?Digital Technologies · JSS 1 – SSS 2Test made-up passwords, measure their strength in bits and see how long an attacker would need to guess them.
  • Spreadsheet formulas and functionsDigital Technologies · JSS 2 – SSS 2Use cell references, SUM, AVERAGE, MAX and IF to complete a shop sales record and a class result sheet.
  • Coding in PythonDigital Technologies · SSS 1 – SSS 3Write real Python – print, variables, loops and if statements – and have each program checked automatically.