Visualizing Handwritten Digits with Isomap Dimensionality Reduction
Step 1: Importing Libraries
Python
import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_digits from sklearn.manifold import Isomap from sklearn.preprocessing import StandardScaler from sklearn.pipeline import Pipeline |
Step 2: Dataset Loading and Preprocessing
Python
digits = load_digits() X, y = digits.data, digits.target scaler = StandardScaler() X_standardized = scaler.fit_transform(X) |
Step 3: Apply Isomap for Dimensionality Reduction
The code creates an Isomap model with 30 neighbors and 2 output dimensions, then fits the model to the standardized input data and transforms it into the lower-dimensional space.
Python
isomap = Isomap(n_neighbors = 30 , n_components = 2 ) X_transformed = isomap.fit_transform(X_standardized) |
Step 4: Plot the reduced-dimensional data
The code creates a scatter plot of the data points visualizing the 2D representation of handwritten digits from the MNIST dataset, with each digit class represented by a different color. The plot includes a color bar for reference.
Python3
plt.figure(figsize = ( 10 , 8 )) scatter = plt.scatter(X_transformed[:, 0 ], X_transformed[:, 1 ], c = y, cmap = 'viridis' , edgecolors = 'k' , s = 20 ) plt.title( 'Isomap - 2D Representation of Handwritten Digits (MNIST)' ) plt.xlabel( 'Component 1' ) plt.ylabel( 'Component 2' ) plt.colorbar(scatter, ticks = np.arange( 10 ), label = 'Digit Class' ) plt.show() |
Output:
Here, Each digit class is represented by a different color, revealing distinct clusters corresponding to the different digits. This visualization demonstrates the effectiveness of Isomap in preserving the underlying structure of the data while reducing its dimensionality.
Isomap for Dimensionality Reduction in Python
In the realm of machine learning and data analysis, grappling with high-dimensional datasets has become a ubiquitous challenge. As datasets grow in complexity, traditional methods often fall short of capturing the intrinsic structure, leading to diminished performance and interpretability. In this landscape, Isomap (Isometric Mapping) emerges as a potent technique designed explicitly to navigate the intricacies of complex, non-linear structures inherent in data. Dimensionality reduction is a crucial aspect of machine learning and data analysis, especially when dealing with high-dimensional datasets. One powerful technique for this purpose is Isomap, an algorithm designed to capture the underlying geometry of complex, non-linear structures. Isomap stands for Isometric Mapping, and its primary goal is to unfold intricate patterns in high-dimensional data into a lower-dimensional space while preserving the essential relationships between data points.