
Let's build and fit the som: iris_som = SOM ( m = 3, n = 1, dim = 2 ) iris_som. We already know that there are 3 classes in the Iris Dataset, so we will use a 3 by 1 structure for our self organizing map, but in practice you may have to try different structures to find what works best for your data.

Now, just like with any classifier right from sklearn, we will have to build an SOM instance and call. We will also use only the first two features so our results are easier to visualize: from sklearn import datasets iris = datasets. But we are going to use it, so let's grab it. If you have data from another source, you will not need it.

For this part we will use sklearn's Iris Dataset, but you do not need sklearn to use SOM. Now you will have to create an instance of SOM to cluster data, but first let's get some data. First, import the SOM class from the sklearn_som.som module: from sklearn_som.som import SOM It has the advantage of only having one dependency (numpy) and if you are already familiar with Scikit Learn's machine learning API, you will find it easy to get right up to speed with sklearn-som. So why make another one? Well, sklearn-som, as the name suggests, is written to interface just like a clustering method you would find in Scikit Learn. There are already a handful of useful SOM packages available in your machine learning framework of choice.

For a brief, all-around introduction to self organizing maps, check out this helpful article from Rubik's Code. It is used for clustering data and performing dimensionality reduction. Sklearn-som is a minimalist, simple implementation of a Kohonen self organizing map with a planar (rectangular) topology. A simple, planar self-organizing map with methods similar to clustering methods in Scikit Learn.
