11.7 ML clustering
Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §11.6. Rewritten in original wording — no
KmeansCluster.py/Perceptron.py/ Pandas listing dumps. Continues 11.6b. Next: 11.7b.
Grouping data by shared features reveals structure, outliers, and (for nets) useful training signals. Labeled groups ⇒ supervised learning; no labels ⇒ unsupervised. Clustering is computationally hard in general (NP-hard): expect heuristics, not guaranteed global optima in poly-time.
-means and linear classifiers
Pick clusters (centroids = means that minimize squared distance to members). Initialize, then iterate assign → update until centroids barely move; sklearn’s KMeans Loss is within-cluster sum of squares (inertia). Supervised linear / perceptron models score and step weights with a learning rate. Walk assign, centroid update, linear score, and the weight step — pick each matching equation among lookalikes.
Particle-mass demo
Eighteen PDG-style masses (MeV/; treated as for the toy): , , , , , , , , , , , , , , , , , .
With you typically see a low-mass clump (leptons / light mesons), a medium band (heavier mesons ± nucleons depending on init), and a baryon / heavy clump. Exact membership can shift with initialization — another reason to try several seeds.
Pandas for tables
Hard-coding arrays fails at scale. Pandas reads whitespace / CSV tables into dataframes (columns = named series). Drop unused name columns, feed the mass column into -means. (Sandbox labs keep a fixed Python list; use Pandas locally.)
Perceptron / SGD boundaries
Fire if . Sklearn’s Perceptron / SGDClassifier scale features (zero mean, unit variance), split train/test, and report accuracy. Boundaries are hyperplanes in feature space. A decaying shrinks steps late in training (picked above).
SGD clustering / classification
Same particle table, supervised on (mass, type): shuffle each epoch to avoid cycles, descend the Loss stochastically. Regions resemble the perceptron’s but need not match exactly — randomness and loss details matter.
Takeaway
| Method | Labels? | Idea |
|---|---|---|
| -means | No | Nearest centroid; update means |
| Perceptron | Yes | Linear threshold; weight updates |
| SGD classifier | Yes | Stochastic Loss descent; hyperplanes |
Next: pure-Python assign / update / standardize / locks.
ML clustering
1 / 4Unsupervised clustering means…
Pick an answer to see if you are right.
Next: 11.7b Clustering labs.