sevamoo / SOMPY

A Python Library for Self Organizing Map (SOM)
Apache License 2.0
532 stars 241 forks source link

SOMPY basic usage #8

Open dcaled opened 8 years ago

dcaled commented 8 years ago

I tried this example: http://bit.ly/1eZvaCM And it does not seems to be up to date. I made some fixes, but, I can not run it yet.

I changed:

sm = SOM.SOM('sm', Data, mapsize = [msz0, msz1],norm_method = 'var',initmethod='pca')
sm.train(n_job = 1, shared_memory = 'no',verbose='final')

to:

sm = SOM.SOM(data = Data, neighborhood = neighborhood, mapsize = [msz0, msz1], initialization ='pca') #, norm_method = 'var')
sm.train(n_job = 1, shared_memory = False, verbose='info')

Neighborhood is a required attribute. So, I have to instantiate an object of the type NeighborhoodFactory, right? So, I created it and used it as a parameter of SOM.SOM method.

neighborhood = NeighborhoodFactory.build('gaussian')

I don't know if this is the right choice. And, also, I can not visualize the resulting data as the example because of the changes made in the visualization methods.

Is it possible to assign labels to data and to verify in which group they were grouped in? I also tried this code below (according to this) and it raises a TypeError.

sm = SOM.SOM(data = Data, neighborhood = neighborhood, mapsize = [msz0, msz1], initialization ='pca') 
labels = ['a','b','c'] 
sm.data_labels(labels)

Is there another basic usage example?

melgor commented 8 years ago

Hi. I have manage to translate most of the code, which you were using into new version of code

About you second question, I can not figure it out too. I am working on that

oliviaguest commented 8 years ago

I also would be curious to know if labels can be assigned I tried writing to the _dlabel attribute directly, but I assume it gets overwritten?

I have a working version of the basic stuff (which seems different (at least by a little) to @melgor), see: https://github.com/oliviaguest/my-sompy/blob/master/basic_uses.py

oliviaguest commented 8 years ago

OK, got the labels done if anybody is interested: https://github.com/oliviaguest/SOMPY/commit/bb7a0c023b66035e45e03c775a2298256897b910

@sevamoo if you want I can request a pull?

sevamoo commented 8 years ago

@oliviaguest thanks. yes. plz

oliviaguest commented 8 years ago

Done! And tidier: https://github.com/sevamoo/SOMPY/commit/2256b07a48ada0386513ad810232744b016c3d09 :smile:

oliviaguest commented 8 years ago

That allows both custom labels and those generated within the object itself. I'm using custom labels. So value for labels can be Boolean or a list of strings. Pull request: https://github.com/sevamoo/SOMPY/pull/13

sergiohzlz commented 6 years ago

Hi, thanks for the library. @oliviaguest I need to write specific labels to neurons ¿how can I do this?

oliviaguest commented 6 years ago

IIRC you pass the labels to the constructor when you create the object.

sergiohzlz commented 6 years ago

Mmm no, at least there's no attribute to do this, nevertheless there is an attribute in the instance called sm = sompy.SOMFactory.build(data, mapsize=size, mapshape='planar', lattice='rect', normalization='var', initialization='random', neighborhood='gaussian', training='batch') sm.data_labels

sergiohzlz commented 6 years ago

Here's how: Once the som is trained som.data_labels = np.arrray(somelistofvalues)

Hope it is useful