Summary by TwinMind · 8m 30s

Summary by TwinMind · 8m 30s

StatQuest: K-means clustering

StatQuest: K-means clustering

StatQuest with Josh Starmer

StatQuest with Josh Starmer

K-Means Clustering Introduction

  • Tutorial by Josh Stormer covering k-means clustering fundamentals
  • Topics: clustering samples on line, XY graph, heat map data
  • Focus on selecting optimal K value

K-Means Algorithm Steps (1D Example)

  • Step 1: Select number of clusters (K) - example uses K=3 for three tumor/cell types
  • Step 2: Randomly select 3 distinct data points as initial clusters
  • Step 3: Measure distance from first point to all 3 initial clusters
    • Distance to blue cluster
    • Distance to green cluster
    • Distance to orange cluster
  • Step 4: Assign point to nearest cluster (blue in example)
  • Step 5: Calculate mean of each cluster, repeat clustering process
  • Continue until clustering doesn't change between iterations

Algorithm Quality Assessment

  • Assess quality by summing variation within each cluster
  • K-means tracks clusters and total variance
  • Algorithm runs multiple times with different starting points
  • Returns clustering with lowest total variation

Optimal K Selection Methods

  • K=1: Worst case scenario, highest total variation
  • K=2: Better, lower total variation than K=1
  • K=3: Even better, further reduced variation
  • K=4: Continues reducing variation but diminishing returns
  • Elbow Plot Method:
    • Plot reduction in variance per K value
    • Huge reduction at K=3, slower reduction after
    • Select K at "elbow" point where improvement levels off

2D Data Clustering (XY Graph)

  • Same process as 1D but uses Euclidean distance in 2 dimensions
  • Euclidean distance = Pythagorean theorem
  • Pick 3 random points, assign to nearest cluster
  • Calculate cluster centers, re-cluster until convergence

Multi-Dimensional Data (Heat Maps)

  • 2 samples: Rename as x,y coordinates, plot in XY graph
  • Distance calculations:
    • 2D: √(x² + y²)
    • 3D: √(x² + y² + z²)
    • 4D: √(x² + y² + z² + a²)
    • Pattern continues for higher dimensions
  • No plotting required - only distance calculations needed

K-Means vs Hierarchical Clustering

  • K-means: Puts data into specified number of clusters (K)
  • Hierarchical: Shows pairwise similarity without predetermined cluster count