Self-Organizing Maps (SOM) are a type of artificial neural network introduced by Teuvo Kohonen. SOMs are mainly used for dimensionality reduction and data visualization, especially for high-dimensional data.
Unlike supervised learning models, SOMs learn patterns without labels, organizing input data into a meaningful 2D map where similar inputs are grouped together. They’re ideal for clustering, pattern recognition, and visualization.
| Feature | Description |
|---|---|
| Topology Preservation | Similar data points map to nearby neurons |
| Dimensionality Reduction | High-dimensional data projected onto a 2D space |
| Unsupervised Learning | No labeled data required |
| Clustering & Visualization | Helps identify natural clusters and structure in data |
MiniSomWe’ll use the MiniSom package for a basic SOM implementation.
pip install minisomfrom minisom import MiniSom
from sklearn.datasets import load_iris
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
import numpy as np
# Load and normalize data
iris = load_iris()
X = iris.data
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)
# Initialize SOM: 7x7 grid, input_len = 4 (features)
som = MiniSom(x=7, y=7, input_len=4, sigma=1.0, learning_rate=0.5)
som.random_weights_init(X_scaled)
som.train_random(X_scaled, 100)
# Visualize SOM distance map (U-Matrix)
plt.figure(figsize=(7, 7))
plt.pcolor(som.distance_map().T, cmap='coolwarm') # distance map as heatmap
plt.colorbar()
plt.title("SOM - Distance Map (U-Matrix)")
plt.show()Output-
Self-Organizing Maps (SOM) are a powerful tool for unsupervised learning and visualization of complex data. They help you discover hidden structures and relationships, especially in high-dimensional datasets, making them a valuable tool for exploratory data analysis and clustering tasks.
Sign in to join the discussion and post comments.
Sign in