AI & Machine Learning Topic
Unsupervised Learning: Find Groups and Simpler Views of Data
Sometimes you have data but no answer label. You may want to explore groups of similar rows or reduce a large set of measurements. Unsupervised learning helps with those tasks. It does not automatically discover a true meaning for every group.
Clustering with K-means
K-means groups points around a chosen number of centres. You choose K, the number of groups. The algorithm repeatedly assigns points to centres and updates those centres. The result depends on the features, their scales and the structure of the data.
A cluster label such as zero is just an identifier. It does not mean low value or a permanent customer type. In another run, the same-looking group could have a different label. K-means also forces points into groups even when the data has no useful clusters.
Why scale the inputs?
If one measurement ranges into thousands and another ranges from zero to one, distances may be dominated by the larger numbers. Standard scaling can help, but it is still a modelling choice. Review outliers and whether ordinary distance makes sense for your fields.
Reduce dimensions with PCA
Principal component analysis, or PCA, creates new numeric directions that preserve as much variance as possible for the chosen number of components. Two components let you make a flat plot of a larger dataset. That view loses information.
Variance is not the same as importance for a business task. A feature with little variance may still be useful. PCA is not a label predictor and a two-dimensional picture does not prove that groups are separate in the original data.
A complete local experiment
Install scikit-learn and save this as unsupervised.py. It generates synthetic blobs, so the example was made to contain a simple group structure.
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
from sklearn.decomposition import PCA
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X, _ = make_blobs(n_samples=120, centers=3, n_features=4, random_state=42)
clusterer = make_pipeline(StandardScaler(), KMeans(n_clusters=3, n_init=10, random_state=42))
labels = clusterer.fit_predict(X)
print("Cluster sizes:", [(n, int((labels == n).sum())) for n in sorted(set(labels))])
scaled = StandardScaler().fit_transform(X)
pca = PCA(n_components=2)
coordinates = pca.fit_transform(scaled)
print("Reduced shape:", coordinates.shape)
print("Retained variance:", round(float(pca.explained_variance_ratio_.sum()), 3))
Run python unsupervised.py. It prints the number of points in each cluster, the reduced shape (120, 2), and the variance kept by two components. Group sizes and variance are observations, not an automatic quality grade.
Check whether a grouping helps
Inspect representative examples from each group. Try nearby K values and compare stability. A silhouette score can describe separation under a distance measure, but it cannot tell you whether the groups are fair, meaningful or useful to people.
For customer data, work with the people who understand the task. Avoid giving a group a negative personal label based on a pattern alone. Limit access to sensitive information and check whether the features are appropriate.
Other methods
DBSCAN can find dense areas and leave some points as noise. Its settings and distance choices matter too. Hierarchical clustering builds nested groups. Choose a method from the problem and data, not because one tool is fashionable.
Practice
Change K from three to two and four. Does the program still return groups? Yes: it follows your setting. Explain why that is not proof that each setting describes a real set of types. Then add a large-scale feature and compare results with and without scaling.
Official references
Reviewed on 25 October 2026. Use documentation for your installed versions.
Comments (0)
No comments yet. Be the first to comment!