- The blue hexagons represent the neurons.
- The red lines connect neighboring neurons.
- The colors in the regions containing the red lines indicate the distances between neurons.
- The darker colors represent larger distances.
- The lighter colors represent smaller distances.
How to interpret and determine clusters in SOM Neighbour Distance Plot
9 views (last 30 days)
Show older comments
I need help interpreting and identifying clusters in the attached SOM Neighbour Distance plot. I am not sure how to determine the samples from my data which belong to the clusters as well. Is there a code to use to identify the samples?
Thank You
0 Comments
Accepted Answer
Karan Singh
on 30 Aug 2023
Hey NCA, I saw your attached image to what is “SOM neighbour Distance Plot” which is plotted using MATLAB’s “deep learning toolbox”. This figure uses the following color coding:
With the understanding of the figure, we can move onto your next question of classification of your data into the clusters. Here's an example with sample data to demonstrate the MATLAB code for identifying clusters using a “Self-Organizing Map (SOM)”:
% Sample SOM grid (3x3 grid with 2D codebook vectors)
som_grid = [1 1; 2 2; 3 3; 4 4; 5 5; 6 6; 7 7; 8 8; 9 9];
% Sample data (5 samples with 2D features)
data = [1.2 1.3; 2.5 2.7; 4.1 4.4; 7.2 7.5; 8.9 8.8];
% Calculate Euclidean distances between each sample in 'data' and each neuron in 'som_grid'
distances = pdist2(data, som_grid);
% Find the index of the BMU neuron for each sample
[~, bmu_indices] = min(distances, [], 2);
% Assign samples to clusters based on the BMU indices
clusters = containers.Map;
for i = 1:length(bmu_indices)
bmu_index = num2str(bmu_indices(i)); % Convert to string
if ~isKey(clusters, bmu_index)
clusters(bmu_index) = [];
end
clusters(bmu_index) = [clusters(bmu_index), i];
end
% Print the samples belonging to each cluster
keys = clusters.keys;
for i = 1:length(keys)
cluster_index = keys{i};
samples = clusters(cluster_index);
disp(['Cluster ', cluster_index, ': ', num2str(samples)]);
end
In this example, the “SOM grid” is a “3x3” grid with “2D” codebook vectors, and the data consists of “5” samples with “2D” features. You can modify the SOM grid and data according to your specific dataset.
Running this code will calculate the Euclidean distances between the data samples and the SOM grid, find the BMU neuron index for each sample, assign the samples to clusters based on the BMU indices, and print the samples belonging to each cluster.
Feel free to replace the sample SOM grid and data with your own data to observe the cluster assignments based on the SOM.
Here is some of the documentation for you to have more information on the topic Cluster with Self-Organizing Map Neural Network - MATLAB & Simulink (mathworks.com)
Hope it helps!
0 Comments
More Answers (0)
See Also
Categories
Find more on Pattern Recognition and Classification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!