sevamoo / SOMPY

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

View2DPacked.show() Exception: Data must be 1-dimensional #68

Open vferman opened 6 years ago

vferman commented 6 years ago

Hey, I'm not quite sure why it is trowing this error... Can anyone help?

The imported file is a 800 by 750 matrix (or something similar)

My code:

    data = pd.read_csv(filename, header=None, index_col=False)
    mapsize = [20,20]
    som = sompy.SOMFactory.build(data, mapsize, mask=None, mapshape='planar', lattice='rect', normalization='var', initialization='pca', neighborhood='gaussian', training='batch', name='sompy')
    som.train(n_job=1, verbose='info')
    v = sompy.mapview.View2DPacked(50, 50, 'test',text_size=8)
    v.show(som, what='codebook', which_dim=[0,1], cmap=None, col_sz=6)
    v.save('2d_packed_test.png')

I get the following:

Traceback (most recent call last):
  File "SOM-solve.py", line 21, in <module>
    v.show(som, what='codebook', which_dim=[0,1], cmap=None, col_sz=6)
  File "build/bdist.linux-x86_64/egg/sompy/visualization/mapview.py", line 120, in show
    axis_num) = self._calculate_figure_params(som, which_dim, col_sz)
  File "build/bdist.linux-x86_64/egg/sompy/visualization/mapview.py", line 14, in _calculate_figure_params
    codebook = som._normalizer.denormalize_by(som.data_raw, som.codebook.matrix)
  File "build/bdist.linux-x86_64/egg/sompy/normalization.py", line 49, in denormalize_by
    return n_vect * st + me
  File "/usr/lib/python2.7/dist-packages/pandas/core/ops.py", line 620, in wrapper
    dtype=dtype)
  File "/usr/lib/python2.7/dist-packages/pandas/core/series.py", line 225, in __init__
    raise_cast_failure=True)
  File "/usr/lib/python2.7/dist-packages/pandas/core/series.py", line 2885, in _sanitize_array
    raise Exception('Data must be 1-dimensional')
Exception: Data must be 1-dimensional
Ali11000000 commented 6 years ago

change the "som = sompy.SOMFactory.build(data, mapsize, ..." TO "som = sompy.SOMFactory.build(data.values, mapsize,..."

I think this now works!

beckrob commented 6 years ago

I believe this is related to https://github.com/sevamoo/SOMPY/issues/20.

It seems that if the training data is a pandas matrix (or Python array), many functions will throw this exception. However, if you convert to a numpy matrix (which is what .values gives you), it will work.

Sincerely, Robert