Machine learning with Python: your first models · Lesson 1 of 5

Data, features and labels

Today you will

  • Name the features and the label in a data set.
  • Tell a prediction of a number (regression) from a choice of category (classification).
  • Store a small data set in Python lists.

Before you start: Programming with Python: first steps (lists, loops and functions).

Machine learning in one sentence

Machine learning is writing a program that finds a rule from examples, instead of you writing the rule. The AI foundations course showed the idea; this course makes you do it, in Python.

Features and labels

Every example in a data set has:

  • Features: what you know. Size of a flat, number of rooms, distance to town.
  • Label: what you want to predict. The monthly rent.
Size (m²)RoomsRent
201100
402170
603230

Here size and rooms are features; rent is the label.

Two kinds of problem

  • Regression: the label is a number. Rent, temperature, sales next week.
  • Classification: the label is a category. Spam or not spam, ripe or unripe, which crop disease.

Data in Python

Plain lists are enough to start:

sizes = [20, 30, 40, 50, 60]      # feature
rents = [100, 130, 170, 190, 230] # label

for size, rent in zip(sizes, rents):
    print(size, "m² rents for", rent)

zip() walks through two lists side by side, giving one pair each time.

Look before you learn

Before any model, look at the data. Here, as size goes up by 10, rent goes up by roughly 30 to 40. A straight line should fit well. That is the next lesson.

Guided practice

A farmer records rainfall (mm), fertiliser (kg) and harvest (bags), and wants to predict the harvest. What are the features and the label, and which kind of problem is it?

Features: rainfall and fertiliser. Label: harvest. The label is a number, so it is regression.

Practice

Marked as you go. Get 75% right to complete the lesson.

Getting your desk ready…

Build status · Flash Infinity AI™ is a trademark of AI-Flash Inc. WorldClass is not affiliated with, approved or accredited by any exam board, curriculum provider or university unless a page says so.