Coder Social home page Coder Social logo

minisom's Introduction

MiniSom

MiniSom

Self Organizing Maps

MiniSom is a minimalistic and Numpy based implementation of the Self Organizing Maps (SOM). SOM is a type of Artificial Neural Networks able to convert complex, nonlinear statistical relationships between high-dimensional data items into simple geometric relationships on a low-dimensional display.

Installation

Download MiniSom to the directory of your choice, enter it and run (may require root privileges):

python setup.py install

How to use it

In order to use MiniSom you need your data organized as a Numpy matrix where each row corresponds to an observation or an as list of lists like the following:

data = [[ 5.1  3.5  1.4  0.2],
        [ 4.9  3.   1.4  0.2],
        [ 4.7  3.2  1.3  0.2], # <-- single observation
        [ 4.6  3.1  1.5  0.2],
        [ 5.   3.6  1.4  0.2],
        [ 4.1  3.3  1.4  0.2],
        [ 4.2  3.2  1.2  0.2]]         

Then you can run MiniSom just as follows:

from minisom import MiniSom    
som = MiniSom(6, 6, 4, sigma=0.3, learning_rate=0.5) # initialization of 6x6 SOM
print "Training..."
som.train_random(data, 100) # trains the SOM with 100 iterations
print "...ready!"

MiniSom implements two types of training. The random training (implemented by the method train_random), where the model is trained picking random samples from your data, and the batch training (implemented by the method train_batch), where the samples are picked in the order they are stored.

A data driven initialization of the weights is also provided by the method random_weights_init which initializes the weights picking random samples from the data.

Using the trained SOM

After the training you will be able to

  • Compute the coordinate assigned to an observation x on the map with the method winner(x).
  • Compute the average distance map of the weights on the map with the method distance_map().
  • Compute the number of times that each neuron have been considered winner for the observations of a new data set with the method activation_response(data).
  • Compute the quantization error with the method quantization_error(data).

Vector quantization

The data can be quantized by assigning a code book (weights vector of the winning neuron) to each sample in data. This kind of vector quantization is implemented by the method quantization that can be called as follows:

qnt = som.quantization(data)

In this example we have that qnt[i] is the quantized version of data[i].

Examples

In examples/example_iris.py you can find an example that shows how to train MiniSom and visualize the result using the Iris flower dataset. Here is the result of the script:

Iris example

For each observation we have a marker placed on the position of the winning neuron on the map. Each type of marker represents a class of the iris data. The average distance map of the weights is used as background (see the color bar on the right to associate the value).

In examples/example_digits.py there is an example of how to use MiniSom for images clustering. The example uses the scitkits-learn wrapper to the handwritten digits dataset. Here is one of the result that MiniSom can achieve in digits recognition:

handwritten digitts recognition

The graph above represent each image with the handwritten digit it contains. The position corresponds to the position of the winning neuron for the image. Here we also have a version of this graphs that shows the original images:

handwritten digitts recognition

In examples/example_color.py you can find an example of how to use MiniSom for color quantization. Here is one of the possible results:

Color quantization example

(the examples require matplotlib for the visualization of the results).

Who uses Minisom?

Compatibility notes

Minisom has been tested under python 2.7.3 and 3.2.3.

License

MiniSom by Giuseppe Vettigli is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/.

License

minisom's People

Contributors

justglowing avatar ph0ngp avatar mpoegel avatar tomage avatar

Watchers

Rodrigo Rivera avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.