Menu
CoddyTech

Learning from Examples

Part of the Supervised Learning section of Coddy's Machine Learning journey. Lesson 1 of 58.

Time for real models. A model studies labelled rows, features plus a label, and learns to label new ones: supervised learning. Labelled seeds in, a map out:

Two charts of 180 wheat seeds, area across and groove length up. Left, the labelled seeds in three groups, Kama, Rosa and Canadian. Right, the same seeds on a map shaded into three regions, one per variety

A variety is a category, so this is classification: the model draws borders. A number label, like a melon's weight, is regression: the model learns a line.

30 watermelons as green dots, length in cm across and weight in kg up, with a rising orange line through them. A new 32 cm melon sits on the line at about 6.2 kg

Which kind? .nunique() counts a label's different values: a category repeats a few, a number rarely repeats.

seeds = pd.read_csv("seeds.csv")
print(seeds["variety"].nunique())

This prints 3: a classification.

challenge icon

Challenge

Easy

A shop for used e-scooters could predict any column of scooters.csv. Which would be classification, which regression? The program reads a column name into label.

  1. Count the column's different values.
  2. Print them as below, with the number of scooters.
  3. Print A category: classification for at most 10 different values, otherwise A number: regression.

For another shop and the column brand:

brand: 7 different values in 50 scooters
A category: classification

Try it yourself

import pandas as pd

scooters = pd.read_csv("scooters.csv")
label = input()

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Supervised Learning

Practice on your own: Online Python compiler