Course materials · Introduction to Machine Learning

Unsupervised Learning

English translation

Changing the number of clusters and the scale can change how the same data are grouped. Interpret the structure without assigning meaning to cluster numbers themselves.

Run import numpy as np and import matplotlib.pyplot as plt in a code cell before the practice code. Use np for array operations and plt for plots.

Before practice

01 Does cluster number 0 have a special meaning?

Description

Numbers are arbitrary identifiers, so compare clusters using their centers and assignment structure.

02 Do different feature units change distances?

Description

Features with larger ranges can dominate distances, so compare results before and after Standardization.

Practice

Preview practice notebookDownload practice notebook

1. Cluster Count and Inertia

Starting conditions

Use make_blobs(n_samples=180,centers=3,cluster_std=.8,random_state=7) and K∈{2,3,4}K\in\{2,3,4\}.

Procedure

  1. Train KMeans(random_state=7,n_init=10) for each K.
  2. Plot cluster centers and assignments, and record Inertia and Silhouette.

Results to retain

Items to record and points to check
K
Inertia
Silhouette
Observations by cluster count

Points to check

  • Did you avoid interpreting cluster numbers themselves as ground truth classes?

2. Changing Feature Units

Starting conditions

Multiply only X's first column by 10, and compare the original data, modified data, and results of column-wise standardization.

Procedure

  1. Prepare the original X, X2 with its first column multiplied by 10, and X2 standardized column by column.
  2. Retrain KMeans with K∈{2,3,4}K\in\{2,3,4\} on each dataset. Keep random_state=7 and n_init=10 unchanged.
  3. Plot cluster assignments and centers for each data condition, and record Inertia and Silhouette by K in tables with the same format. Use the plots to judge whether scaling up the first column changed assignments and centers, and explain your evidence.

Results to retain

Items to record and points to check
Data condition and K
Cluster plot and centers
Inertia
Interpretation of Silhouette and Cluster Direction

Points to check

  • Did you use the same K and Seed for all three data conditions?

3. Checking Other Inputs

Starting conditions

Compare the same K values on data with cluster_std=1.6.

Procedure

  1. In make_blobs, change only cluster_std to 1.6. Keep the sample count, number of centers, and Seed unchanged.
  2. Train KMeans for the same three K values and obtain cluster plots, Inertia, and Silhouette. Record results for each K alongside the corresponding cluster_std=.8 results.
  3. Distinguish the fact that the data were generated with three centers from whether the scatter plot visibly shows three clearly separated groups.

Results to retain

Items to record and points to check
cluster_std·K
Cluster plot
Inertia·Silhouette
Separation patterns in the two datasets

Points to check

  • Did you compare overlap between datasets at the same K?