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.

Similar Reads

What is Isometric Feature Mapping (ISOMAP)?

Isomap, an abbreviation for Isometric Mapping, is a dimensionality reduction algorithm that transcends the limitations of linear approaches. Its primary objective is to unfold intricate patterns within high-dimensional data into a lower-dimensional space while meticulously preserving the essential relationships between data points. Unlike linear methods such as Principal Component Analysis (PCA), which assume a linear relationship between variables, Isomap excels at capturing the underlying non-linear structure, making it a go-to choice for a diverse array of applications....

Geodesic Distance vs. Euclidean Distance: Unveiling the Variance in Measurement

Euclidean Distance Geodesic Distance Definition Euclidean distance is the straight-line distance between two points in Euclidean space.It represents the length of the shortest path between two points in a flat, Cartesian space.Geodesic distance is the shortest path between two points on a curved surface, such as a manifold or graph.It accounts for the curvature or non-linearity of the space, providing a more accurate measure on non-flat surfaces.Measurement Basis Based on the straight-line distance formula derived from the Pythagorean theorem.Assumes a flat, linear space without considering any curvature or obstacles.Based on the shortest path along the curved surface.Reflects the intrinsic structure of the space, considering any bends or twists.Applicability Appropriate for flat, Euclidean spaces.Well-suited for measuring distances in traditional Cartesian coordinate systemsEssential for measuring distances on curved surfaces, manifolds, or graphs.Suitable for capturing distances in spaces with non-linear structures.Calculation Method Computed using the familiar straight-line distance formula in Euclidean space.For two points (x1 ,y1) and (x2 ,y2) the Euclidean distance is given bysquare root ((x2-x1)2+(y2-y1)2)Computed based on the shortest path along the curved surface.Often involves algorithms like Dijkstra’s algorithm on a graph or specialized methods for manifold spaces.Sensitivity to Structure Insensitive to the underlying structure of the space.Treats the space as flat and measures distances without considering bends or twists.Sensitive to the intrinsic structure of the space.Captures the true distances, accounting for the non-linearities present.Example On a flat map, the Euclidean distance between two cities is a straight-line measurement. On the surface of the Earth, the geodesic distance between two cities considers the curvature of the planet, providing a more accurate representation. Representation in Isomap Isomap, when using Euclidean distances, assumes a flat geometry. Isomap, utilizing geodesic distances (shortest paths on the neighborhood graph), captures the non-linear structure of the data. Impact on Dimensionality Reduction May lead to inaccurate representations when dealing with non-linear manifold data. Ensures a more accurate representation of the underlying structure, crucial for preserving relationships in non-linear spaces....

Applications of Isomap

Isomap can be used for a variety of tasks, including:...

Visualizing Handwritten Digits with Isomap Dimensionality Reduction

Step 1: Importing Libraries...

Conclusion

...