https://github.com/nicomignoni/som
PyTorch implementation of Kohonen's Self-Organizing Map.
https://github.com/nicomignoni/som
kohonen self-organizing-map som unsupervised-learning
Last synced: 6 months ago
JSON representation
PyTorch implementation of Kohonen's Self-Organizing Map.
- Host: GitHub
- URL: https://github.com/nicomignoni/som
- Owner: nicomignoni
- License: mit
- Created: 2020-05-03T13:07:15.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-11T19:06:52.000Z (almost 5 years ago)
- Last Synced: 2024-11-18T17:46:45.228Z (about 1 year ago)
- Topics: kohonen, self-organizing-map, som, unsupervised-learning
- Language: Python
- Homepage:
- Size: 1.2 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kohonen's Self-Organizing Map (SOM)
[](https://pypi.python.org/pypi/kohonen-som/)

## Installation
```
pip install kohonen-som
```
## Background
The original [paper](https://sci2s.ugr.es/keel/pdf/algorithm/articulo/1990-Kohonen-PIEEE.pdf) written by Teuvo Kohonen in 1990 was one of the first neural network model capable of unsupervised learning.
Out of the different implementations of the algorithm, this one follows almost entirely the original paper. The update function is defined as
where
and  is the current epoch.
Also, each neuron is connected to all the other ones, hence the map is a  complete graph, where  is the number of neurons.
## Example
```python
from sklearn.datasets import load_iris
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
import numpy as np
from som.mapping import SOM
dataset = load_iris()
train = dataset.data
# Reducing the dimensionality of the train set from
# 4 to 2 with PCA
pca = PCA(n_components=2)
train_pca = pca.fit_transform(train)
parameters = {'n_points' : 500,
'alpha0' : 0.5,
't_alpha' : 25,
'sigma0' : 2,
't_sigma' : 25,
'epochs' : 300,
'seed' : 124,
'scale' : True,
'shuffle' : True,
'history' : True}
# Load and train the model
model = SOM()
model.set_params(parameters)
model.fit(train_pca)
weights = model.get_weights()
# Plot the train dataset and the weights
fig, ax = plt.subplots()
fig.suptitle("Train set (PCA-reduced) and weights")
t = ax.scatter(train_pca[:,0], train_pca[:,1])
w = ax.scatter(weights[:, 0], weights[:, 1])
fig.legend((t, w), ("Train", "Weights"))
plt.show()
```