Menu
CoddyTech

Recap: Gym Members

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

challenge icon

Challenge

Easy

Remember the cafe visits that opened this chapter? A gym wants the same for its floor: what kinds of members come in? members.csv holds each member's average minutes of cardio and of weights per visit.

  1. Fit KMeans: 3 clusters, n_init=10, random_state=0.
  2. For each group, biggest first, print its size, its center and its most typical member: the one nearest the center.
  3. Scatter each group labelled with its size, like 55 members, then black stars labelled centers, a legend, and show.

For another gym:

Groups, biggest first:
45 members: 39 min cardio, 15 min weights (most typical: Rosa P.)
30 members: 20 min cardio, 47 min weights (most typical: Finn A.)
15 members: 56 min cardio, 46 min weights (most typical: Lu W.)

and its chart:

A scatter titled Gym Members, cardio minutes across and weights minutes up: 45 cardio members at the bottom, 30 weights members at the upper left, 15 members who do lots of both at the upper right, a black star in each group and a legend naming each group by its size

Then Coddy describes your chart.

Try it yourself

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans

# One row per member: average minutes of cardio and of weights per visit
members = pd.read_csv("members.csv")
X = members[["cardio_min", "weights_min"]]

fig, ax = plt.subplots()
ax.set_title("Gym Members")
ax.set_xlabel("Cardio (min per visit)")
ax.set_ylabel("Weights (min per visit)")

# Write your code below

All lessons in Unsupervised Learning

Practice on your own: Online Python compiler