GithubHelp home page GithubHelp logo

Comments (11)

JustGlowing avatar JustGlowing commented on June 21, 2024

hi there, I'm afraid I can't replicate your errors. Make sure you're using Python3 and that MiniSom is installed correctly on your machine.

from minisom.

tomaszek0 avatar tomaszek0 commented on June 21, 2024

Hi, I updated my conda packages, and here's what I did:
Python 3.11.5 (conda 23.9.0) updated to Python 3.11.7 (conda 23.11.0)
numpy 1.24.3 upgraded to 1.26.3
pandas 2.0.3 upgraded to 2.1.4
matplotlib 3.7.2 upgraded to 3.8.2
scikit-learn 1.3.2

But these changes didn't result in the problem disappearing.
The attribute errors are still being generated:
'MiniSom' object has no attribute 'get_weights'
'MiniSom' object has no attribute 'labels_map'
'MiniSom' object has no attribute 'topographic_error_rectangular'

Since the MiniSom did not have large code snippets, I copied minisom.py directly to my Jupyter notebook. and deactivated entry "#from minisom import MiniSom". As a result, this fixes the problem, and the Attribute error 'MiniSom' object has no attribute 'get_weights' does not appear.

from minisom.

JustGlowing avatar JustGlowing commented on June 21, 2024

it looks like you're importing something wrong. Have you tried installing minisom using pip? It could be that something went wrong when you pasted the code.

from minisom.

tomaszek0 avatar tomaszek0 commented on June 21, 2024

The Attribution Errors were generated when executing the code importing the MiniSom library, i.e. after installing the MiniSom using pip. The pasted code from the minisom.py was used to bypass the problems and it worked fine.
Thus, today, I uninstalled minisom: pip uninstall minisom
and then I installed it again: pip install minisom
pip show minisom

Unfortunately, executing the code generates an error:AttributeError: 'MiniSom' object has no attribute 'get_weights'
However, when the code below is executed, it provides the output:
...
from minisom import MiniSom

dir(MiniSom)
['class',
'delattr',
'dict',
'dir',
'doc',
'eq',
'format',
'ge',
'getattribute',
'getstate',
'gt',
'hash',
'init',
'init_subclass',
'le',
'lt',
'module',
'ne',
'new',
'reduce',
'reduce_ex',
'repr',
'setattr',
'sizeof',
'str',
'subclasshook',
'weakref',
'_activate',
'_init_T',
'activate',
'activation_response',
'diff_gaussian',
'distance_map',
'gaussian',
'quantization',
'quantization_error',
'random_weights_init',
'train_batch',
'train_random',
'update',
'win_map',
'winner']

thus
dir(som) generates NameError: name 'som' is not defined
since the "som" is defined further in line: som = MiniSom(x, y, input_len, sigma, learning_rate)

from minisom.

JustGlowing avatar JustGlowing commented on June 21, 2024

I tried to replicate your issue by installing minisom via pip in a fresh Python 3.11 environment but everything worked as expected. I suggest the following actions:

  1. Create a clean virtual environment virtualenv <your_dir_of_choice>
  2. Activate it source <your_dir_of_choice>/bin/activate
  3. Install numpy and minisom in the environment pip install numpy minisom
  4. Try to run your code

from minisom.

tomaszek0 avatar tomaszek0 commented on June 21, 2024

Unfortunately, applying the 'som' code in the new environment failed to alter the situation.
I followed the steps below:
conda create --name som_env # to create the virtual environment.
conda activate som_env
"pip install packages"
Start Jupyter Notebook from within a new conda environment
!conda info # check env -> ok 'som_env'
Run code.

AttributeError: 'MiniSom' object has no attribute 'get_weights'

Additionally, I noticed that the generated U-matrix is not the same in both situations, i.e. the pasted minisom.py code generates a different pattern than the result obtained from the imported MiniSom function.

from minisom.

JustGlowing avatar JustGlowing commented on June 21, 2024

Do not install anything else apart from numpy and minisom in the new environment. Run a simple code snippet from the python terminal to test that minisom is working:

from minisom import MiniSom
som = MiniSom(2, 2, 3)
som.get_weights()

from minisom.

tomaszek0 avatar tomaszek0 commented on June 21, 2024

So, I removed the existing environment and created a new one. The installation of 'numpy' using pip displayed the message 'Requirement already satisfied'. I got this done by running the "conda install numpy" and 'pip install minisom. This time, both installations were successful. However, as Anaconda states (https://www.anaconda.com/blog/using-pip-in-a-conda-environment): Running conda after pip has the potential to overwrite and potentially break packages installed via pip. Similarly, pip may upgrade or remove a package which a conda-installed package requires.

conda activate som_env
(som_env): jupyter notebook
in jupyter:
-check env
!conda info
-ok som_env

from minisom import MiniSom
som = MiniSom(2, 2, 3)
som.get_weights()
AttributeError: 'MiniSom' object has no attribute 'get_weights'
dir(som)
['class',
'delattr',
'dict',
'dir',
'doc',
'eq',
'format',
'ge',
'getattribute',
'getstate',
'gt',
'hash',
'init',
'init_subclass',
'le',
'lt',
'module',
'ne',
'new',
'reduce',
'reduce_ex',
'repr',
'setattr',
'sizeof',
'str',
'subclasshook',
'weakref',
'_activate',
'_decay_function',
'_init_T',
'activate',
'activation_map',
'activation_response',
'diff_gaussian',
'distance_map',
'gaussian',
'learning_rate',
'neighborhood',
'neigx',
'neigy',
'quantization',
'quantization_error',
'random_generator',
'random_weights_init',
'sigma',
'train_batch',
'train_random',
'update',
'weights',
'win_map',
'winner']

from minisom.

JustGlowing avatar JustGlowing commented on June 21, 2024

The fact that you got a "Requirement already satisfied" means that the environment already had libraries installed. Please use virtualenv as suggested above rather than conda.

Also, check that you are actually using the python from the virtual environment by using:

import sys
print(sys.executable)

also check that the minisom you import is where you expect it to be:

import minisom
print(minisom.__file__)

from minisom.

tomaszek0 avatar tomaszek0 commented on June 21, 2024

I removed existing som_env (conda remove --name som_env –all) and then created virtual env using virtualenv. Now, there is no message "Requirement ..." and packages have been installed.
Testing:
from minisom import MiniSom
som = MiniSom(2, 2, 3)
som.get_weights()
Result: an array
import sys
print(sys.executable)
Result: ...\anaconda3\python.exe
import minisom
print(minisom.file)
Result: \anaconda3\Lib\site-packages\minisom.py

and my code works properly.

from minisom.

JustGlowing avatar JustGlowing commented on June 21, 2024

Great! You can keep using that environment. Not sure what's the problem with conda.

from minisom.

Related Issues (20)

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.