Comments (11)
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.
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.
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.
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.
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:
- Create a clean virtual environment
virtualenv <your_dir_of_choice>
- Activate it
source <your_dir_of_choice>/bin/activate
- Install numpy and minisom in the environment
pip install numpy minisom
- Try to run your code
from minisom.
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.
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.
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.
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.
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.
Great! You can keep using that environment. Not sure what's the problem with conda.
from minisom.
Related Issues (20)
- Question on the radius. HOT 2
- About how you efficiently calculate the winner and the neighbourhood function. HOT 1
- How can I get reproducible results? HOT 2
- Meaning of the position of winning nodes and distance map HOT 3
- considerations on the hexagonal neighborhood used in `distance_map()` HOT 6
- It seems the next run will be influenced by the former run. Will it be more rational to reset after every run? HOT 4
- Is there a way to create clusters of equal size? HOT 2
- What's the order of the coordinates returned by the winner method? HOT 2
- How to save and load trained model for cluster prediction on new data? HOT 1
- PCA initialization HOT 7
- Adjacent nodes in hexagonal distance do not have distance 1 HOT 2
- Question: Interest in a connectivity matrix? HOT 2
- errors in 'AdvancedVisualization.ipnyb' example HOT 2
- Help with clustering and visualization of neurons HOT 1
- There might be an index error in TimeSeries.ipynb HOT 1
- decay for sigma can be improved HOT 5
- Large Quantization Error with Spatio-Temporal Data? HOT 10
- error in clustering SST data
- Can i do SOM for multiple variables? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minisom.