Unsupervised Machine Learning
Unsupervised learning finds hidden patterns or intrinsic structures in input data. Unlike supervised learning, there are no labeled outputs. Common tasks include clustering and dimensionality reduction.
The K-Means demo loads a tiny ONNX model trained on real Iris petal measurements (see scripts/export_tutorial_onnx.py).
K-Means Clustering
K-Means groups data into 'k' non-overlapping subgroups (clusters) distinct from each other. It tries to make the intra-cluster data points as similar as possible while keeping the clusters as different as possible.
Python Implementation
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3)
kmeans.fit(X)
labels = kmeans.predict(X)
Live Demo: Iris Sort
ONNXSorts Iris flowers into clusters based on petal dimensions.
K-Means Step-by-Step
Watch K-Means converge step by step. Initialize centroids, then step through assignment and update phases. Choose a preset dataset or draw your own points by clicking on the canvas.
Principal Component Analysis (PCA)
PCA finds the directions of maximum variance in high-dimensional data and projects it onto a lower-dimensional subspace β preserving as much information as possible. It's used for visualisation, noise reduction, and speeding up downstream models.
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X) # PCA needs normalised data
pca = PCA(n_components=2)
X_2d = pca.fit_transform(X_scaled)
print(pca.explained_variance_ratio_) # % variance per component
Live Demo β Iris 4D β 2D Projection
Enter all four Iris measurements and see where they land in 2D principal component space.
Hidden Markov Models
A Hidden Markov Model (HMM) is a statistical model in which the system being modeled is assumed to be a Markov process with unobserved (hidden) states.
Knowledge Check
Test your understanding β pick the best answer, then click Check.
1. What quantity does K-Means minimise?
2. What does PCA's first principal component represent?
3. What is the elbow method used for in K-Means?