Unsupervised Learning: Clustering and Autoencoders
Unsupervised Learning
Unsupervised learning techniques like clustering and autoencoders are used to find patterns in data without labeled outputs.
Clustering
Clustering aims to group similar objects together while ensuring that they are dissimilar to objects in other groups. The goal is to minimize intra-cluster distances and maximize inter-cluster distances.
Applications of Cluster Analysis
- Understanding: Clustering can help in grouping related documents for browsing, genes and proteins with similar functionality, and stocks with similar price fluctuations.
- Summarization: It reduces the size of large datasets by grouping similar data points.
Clustering Techniques
Various clustering techniques include:
- Partitioning Methods: k-Means, k-Medoids, k-Modes, Fuzzy c-means.
- Hierarchical Methods: Agglomerative and Divisive methods like AGNES, BIRCH, CURE, ROCK, Chamelon, DIANA, PAM, CLARA, CLARANS.
- Density-Based Methods: STING, DBSCAN, CLIQUE, DENCLUE, OPTICS, Wave Cluster.
- Graph-Based Methods: MST Clustering, OPOSSUM, SNN Similarity Clustering.
- Model-Based Clustering: EM Algorithm, Auto class, COBWEB, ANN Clustering.
Types of Clusterings
- Partitional Clustering: Divides data objects into non-overlapping subsets, where each object belongs to exactly one subset.
- Hierarchical Clustering: Organizes clusters as a hierarchical tree.
K-Means Clustering
K-means is a partitional clustering approach where the number of clusters, , must be specified. Each cluster is associated with a centroid, and each point is assigned to the cluster with the closest centroid.
K-Means Algorithm Details
The algorithm iteratively assigns each point to the nearest centroid and re-computes the cluster centroids until the centroids stop changing.
- Initial centroids are often chosen randomly, leading to varying cluster results.
- The centroid is typically the mean of the points in the cluster.
- K-means converges for common proximity measures.
- Complexity: , where is the number of points, is the number of clusters, is the number of iterations, and is the number of attributes.
K-Means Objective Function
The Sum of Squared Error (SSE) is a common objective function used with the Euclidean distance measure.
SSE =
\sum{i=1}^{K}
\sum{x \in Ci} dist^2(mi, x)
Where is a data point in cluster and is the centroid for cluster . SSE improves in each iteration until it reaches a local or global minimum.
Importance of Choosing Initial Centroids
The choice of initial centroids significantly impacts the resulting clusters. Poor initial centroids can lead to suboptimal clusterings.
Solutions to Initial Centroids Problem
- Multiple Runs: Running the algorithm multiple times with different initial centroids.
- Strategic Selection: Selecting initial centroids that are widely separated (K-means++).
- Hierarchical Clustering: Using hierarchical clustering to determine initial centroids.
K-Means++
- Select an initial point at random to be the first centroid.
- For steps:
- For each of the points, , , find the minimum squared distance to the currently selected centroids, , , i.e.,
- Randomly select a new centroid by choosing a point with probability proportional to
Pre-processing and Post-processing
- Pre-processing: Normalize the data and eliminate outliers before clustering.
- Post-processing: Eliminate empty clusters, split loose clusters, and merge close clusters.
Handling Empty Clusters
Strategies for handling empty clusters include:
- Choosing the point that contributes most to SSE and making it a new centroid.
- Choosing a point from the cluster with the highest SSE and making it a new centroid.
Limitations of K-Means
- Problems when clusters have differing sizes, densities, or non-globular shapes.
- Sensitivity to outliers.
Overcoming K-Means Limitations
Using many clusters to find parts of clusters and then putting them together.
Hierarchical Clustering
Hierarchical clustering produces a set of nested clusters organized as a hierarchical tree, visualized as a dendrogram.
Strengths of Hierarchical Clustering
- No need to assume a particular number of clusters; any desired number can be obtained by cutting the dendrogram at the proper level.
- Meaningful taxonomies can be derived.
Types of Hierarchical Clustering
- Agglomerative: Start with individual points as clusters and merge the closest pairs at each step until one or clusters are left.
- Divisive: Start with one all-inclusive cluster and split a cluster at each step until each cluster contains an individual point or there are clusters.
Traditional algorithms use a similarity or distance matrix to merge or split clusters.
Agglomerative Clustering Algorithm
- Compute the proximity matrix.
- Let each data point be a cluster.
- Repeat:
- Merge the two closest clusters.
- Update the proximity matrix.
- Until only a single cluster remains.
Defining Inter-Cluster Distance
Methods include:
- MIN (Single Linkage)
- MAX (Complete Linkage)
- Group Average
- Distance Between Centroids
- Ward’s Method (uses squared error)
MIN or Single Link
Proximity between two clusters is based on the two closest points in the different clusters.
MAX or Complete Linkage
Proximity between two clusters is based on the two most distant points in the different clusters.
Group Average
Proximity between two clusters is the average of pairwise proximity between points in the two clusters.
proximity(Clusteri, Clusterj) =
\frac{\sum{p \in Clusteri}
\sum{p' \in Clusterj} proximity(p, p')}{|Clusteri| * |Clusterj|}
Cluster Similarity: Ward’s Method
Similarity of two clusters is based on the increase in squared error when two clusters are merged.
Hierarchical Clustering: Time and Space Requirements
- Space:
- Time: , which can be reduced to with cleverness.
Hierarchical Clustering: Problems and Limitations
- Once a decision is made to combine two clusters, it cannot be undone.
- No global objective function is directly minimized.
- Sensitivity to noise and outliers.
- Difficulty handling clusters of different sizes and non-globular shapes.
- Breaking large clusters.
Density-Based Clustering
Clusters are regions of high density separated by regions of low density.
DBSCAN
DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is a density-based algorithm.
- Density: Number of points within a specified radius (Eps).
- Core Point: A point with at least a specified number of points (MinPts) within Eps.
- Border Point: Not a core point but within the neighborhood of a core point.
- Noise Point: Any point that is not a core point or a border point.
DBSCAN Algorithm
- Label all points as core, border, or noise points.
- Eliminate noise points.
- Put an edge between all core points within a distance Eps of each other.
- Make each group of connected core points into a separate cluster.
- Assign each border point to one of the clusters of its associated core points.
When DBSCAN Works Well
- Resistant to noise.
- Can handle clusters of different shapes and sizes.
When DBSCAN Does NOT Work Well
- Varying densities.
- High-dimensional data.
DBSCAN: Determining EPS and MinPts
Plot sorted distance of every point to its nearest neighbor to determine suitable values.
Cluster Validity
Evaluating the “goodness” of the resulting clusters is essential to avoid finding patterns in noise, compare clustering algorithms, and compare different sets of clusters.
Measuring Cluster Validity Via Correlation
Correlation of ideal similarity and proximity matrices for the K-means clusterings.
Internal Measures: SSE
SSE (Sum of Squared Error) measures the goodness of a clustering structure without respect to external information. It is useful for comparing two clusterings or clusters and estimating the number of clusters.
Autoencoders
Autoencoders are neural networks used for representational learning, aiming to learn a compressed, encoded representation of input data.
Neural Networks as Function Approximation
Given an input and output , there exists a mapping from input space to output space as , where . The goal is to find an estimate of , denoted as .
Representational Learning
Autoencoders learn the function , aiming to reconstruct the input.
Self-Supervised Learning
Train two networks to minimize the reconstruction loss function:
Simplest Autoencoder
Encode with a fully connected network (FCN).
Bottleneck
Autoencoders compress the input into a smaller representation (bottleneck) and then reconstruct it.
Latent Variables and Latent Layer
Autoencoders perform semi-supervised or self-supervised learning, using the input data as the target output.
Autoencoders in Action
Training with a variety of images is crucial for good generalization.
A Better Autoencoder
MNIST data can be used to train a simple autoencoder with a one-layer FCN encoder and decoder.
Exploring Autoencoders
Exploring the latent space helps understand the information it contains. If it does not contain any information, then changing the values randomly won’t change the output.
Applying to Novel Input
Check if the trained autoencoder works with new, unseen images.
Convolutional Autoencoders
Use convolutional layers for image data to improve performance.
Over-Complete Autoencoders
An over-complete autoencoder has latent space with greater dimension than the input. It helps balance sensitivity and insensitivity to the inputs, avoiding memorization or overfitting.
Variational Autoencoders (VAE)
Variational Autoencoders improve upon standard autoencoders by keeping track of means and standard deviations in the latent space, preserving details better.
A History of Generative AI Models
- 2014-2017: VAE and GAN era.
- 2018-2019: Transformer era.
- 2020-Now: The Big Model Era, including large language models and multimodal models.