Menu
CoddyTech

Learning Without Labels

Part of the Unsupervised Learning section of Coddy's Machine Learning journey. Lesson 1 of 51.

Every row so far came with its answer, a label. Most data has none. Unsupervised learning finds structure in the rows alone, like these cafe visits:

Two charts of 240 cafe visits, arrival hour across and minutes stayed up. Left, gray dots with no labels in three clumps. Right, the same dots in three groups a model found, named quick coffee, lunch and laptop

Similar rows sit close together, and a group of them is a cluster. Nobody told the model about coffees or laptops. It found three groups; people named them.

Shops find kinds of customers this way; by this chapter's end, so will you. No y, only X: the model learns the data's own shape.

challenge icon

Challenge

Easy

A fish farm tells trout ages apart by length: each year's fish form a group. lengths holds 36 trout in cm, shortest first; the program reads gap.

  1. Walk the lengths. A trout more than gap cm longer than the one before starts a new group.
  2. Print how many groups, then each group's shortest and longest trout and its count.

For another pond and a gap of 2:

26 trout from another pond as dots along a length axis: 15 from 8.5 to 13.9 cm, an empty gap of 3.5 cm, then 11 from 17.4 to 22 cm

Groups: 2
  8.5 to 13.9 cm: 15 trout
  17.4 to 22.0 cm: 11 trout

Try it yourself

# 36 trout from one pond, length in cm, shortest first
lengths = [9.8, 10.4, 10.9, 11.3, 11.6, 12.0, 12.2, 12.7, 13.1, 13.4, 14.0, 14.6,
           18.2, 18.9, 19.3, 19.8, 20.1, 20.4, 20.6, 21.0, 22.8, 23.0, 23.3, 23.5, 23.7, 23.9,
           26.5, 27.1, 27.6, 28.0, 28.3, 28.9, 29.4, 29.8, 30.4, 31.0]
gap = float(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 Unsupervised Learning

Practice on your own: Online Python compiler