Unsupervised learning
गेट DA240 मिनट में पढ़ें
What unsupervised learning does
Definition. In unsupervised learning the data has no labels: only feature vectors . The aim is to find structure, such as groups of similar points (clustering) or a few directions that capture most of the variation (dimensionality reduction).
Exam point. There is no "correct answer" to compare against, so results are judged by measures such as the within-cluster sum of squares or the share of variance explained.
k-means clustering
Definition. k-means splits the data into clusters by minimising the within-cluster sum of squared distances
where is the mean (centroid) of cluster .
Lloyd's algorithm.
- Choose initial centroids.
- Assign every point to its nearest centroid.
- Update every centroid to the mean of the points assigned to it.
- Repeat steps 2–3 until the assignments stop changing.
Each step can only lower , so the algorithm always stops, but it may stop at a local minimum that depends on the starting centroids. Running it from several random starts (or using k-means++ seeding) helps. Clusters are convex (roughly spherical); k-means is sensitive to outliers, because a mean is pulled by extreme values.
Choosing . always decreases as grows (with it is 0), so we look for an "elbow" where the decrease slows down, or use the silhouette score.
Solved examples
Example 1: one iteration. Points on a line: 1, 2, 3, 10, 11, 12. Start with centroids , .
- Assign: 1 and 2 are nearer 1; 3 is at distance 0 from ; 10, 11, 12 are nearer 3. Clusters {1, 2} and {3, 10, 11, 12}.
- Update: , .
- Assign again: 3 is at distance 1.5 from 1.5 and 6 from 9, so it moves to cluster 1. Clusters {1, 2, 3} and {10, 11, 12}.
- Update: , . Assigning again changes nothing, so the algorithm has converged with .
Example 2: why the start matters. With points 0, 2, 4 and , starting centroids 0 and 4 give clusters {0, 2} and {4} (or {0} and {2, 4}); both are stable. So k-means can end in different solutions from different starts.
k-medoids
Definition. k-medoids is like k-means but each cluster centre must be one of the data points (the medoid: the point with the smallest total distance to the others in its cluster). It works with any distance measure, and because it does not average coordinates it is more robust to outliers than k-means.
Example 3. Cluster {1, 2, 3, 50}. The mean is 14, dragged by the outlier 50. Total distances from each point: from 1: ; from 2: ; from 3: ; from 50: . The medoid is 2 (or 3), a representative point not pulled by the outlier.
Hierarchical clustering
Definition. Hierarchical clustering builds a tree of clusters (a dendrogram) instead of one fixed split.
- Bottom-up (agglomerative): start with every point as its own cluster and repeatedly merge the two closest clusters until one cluster remains.
- Top-down (divisive): start with one cluster and repeatedly split a cluster.
Cutting the dendrogram at a chosen height gives the clusters; does not have to be fixed in advance.
Linkage: the distance between two clusters and .
- Single linkage: , the closest pair. Tends to form long chains.
- Complete linkage: , the farthest pair. Gives compact clusters.
- Average linkage: the average of all pairwise distances.
- Centroid / Ward: distance between means, or the increase in within-cluster variance.
Solved example
Example 4. Points on a line: A = 0, B = 1, C = 4, D = 6.
- Closest pair: A–B (distance 1). Merge {A, B}.
- Single linkage distances now: {A,B}–C ; {A,B}–D ; C–D . Merge {C, D}.
- Finally merge {A,B} with {C,D} at single-linkage distance .
With complete linkage the last merge would happen at instead. The merge order can be the same while the merge heights differ.
Dimensionality reduction
Why. Many features are correlated or redundant. Reducing dimension speeds up learning, removes noise, and lets us plot data in 2 or 3 dimensions.
Principal component analysis (PCA)
Definition. PCA finds new orthogonal axes (principal components) ordered by how much variance of the data they capture.
- Centre the data: subtract the mean of every feature.
- Compute the covariance matrix (or ), a symmetric matrix.
- Find its eigenvectors with eigenvalues .
- The first principal component is ; the variance of the data along is .
- Keep the top components and project: .
The share of variance explained by the first components is , and = the total variance.
Exam points.
- Components are orthogonal (eigenvectors of a symmetric matrix) and the projected coordinates are uncorrelated.
- PCA is sensitive to scale: standardise features measured in different units first.
- PCA can also be computed from the SVD of the centred data matrix : the columns of are the components and the variances are .
- PCA is linear and unsupervised; it ignores labels.
Solved examples
Example 5: variance explained. A covariance matrix has eigenvalues 6, 3 and 1. The first component explains of the variance; the first two explain .
Example 6: from a 2×2 covariance matrix. . Eigenvalues: , so . For : gives . The first principal component is , capturing of the variance.
Distance and similarity: the input to every clustering method
Clustering groups points that are "close", so the result depends completely on how closeness is measured.
| Measure | Formula for | Notes |
|---|---|---|
| Euclidean () | default for k-means | |
| Manhattan () | city-block distance | |
| Chebyshev () | largest single difference | |
| Minkowski () | give the three above | |
| Cosine similarity | angle only, ignores length; used for text |
Example A: the same pair, three distances. , . Differences are 3 and 4.
- Euclidean: .
- Manhattan: .
- Chebyshev: .
Always .
Example B: cosine. , : , so the angle is . Scaling to does not change the cosine, but it changes the Euclidean distance a lot.
Scaling matters. If one feature is income in rupees (values near ) and another is age in years (values near 30), Euclidean distance is decided almost entirely by income. Standardise each feature first: . Min–max scaling to is the other common choice.
k-means in depth
Why the objective never increases
Write . Lloyd's algorithm alternates two steps, and each one minimises over one set of variables while the other is held fixed.
आपने इस नोट का मुफ़्त 29% हिस्सा पढ़ लिया
आगे पढ़ने के लिए Google से साइन इन करें। यह मुफ़्त है, एक टैप में होता है, और साथ में मिलता है:
- इस नोट से 12 अभ्यास सवाल
- हर नोट पूरा, साथ में PDF लाइब्रेरी
- आधिकारिक पिछले पेपर समय-सीमा वाले टेस्ट की तरह, व्याख्या के साथ
- डाउट के लिए AI ट्यूटर, हिंदी या अंग्रेज़ी में
- आपकी प्रगति, गलतियाँ और स्टडी प्लान हर डिवाइस पर सेव