A simple implementation of Self Organizing Map written in Python.
Get the dataset as a Scipy array NxM, where N is the number of samples and M is the number of features for each sample.
dataset = import_data(N, M)
Import Som class
from ossom.som import Som
Instantiate a new SOM, specifying the width and the height of the grid and the input size.
som = Som(W, H, M)
Newly created SOMs can be tweaked by setting parameters like learning rate, radius of the neighborhood function etc.
Train the model, iterating through the samples for E epochs:
for epoch in range(1, E):
for x in dataset:
som.train(x, epoch)
Use the trained map to classify data: given an input, find the unit of the map that better fits with it and get back its value -- or weight -- and its position within the grid.
row, column, weight, distance = som.classify(x)
A full running sample is available here. It does use a SOM to classify randomly generated data... not very useful indeed.