Quick Start#
Welcome to the Quick Start section. Here you’ll find everything needed to get started directly embedded from their respective sections.
Installation#
Official releases of NNSOM can be installed from PyPI:
pip install NNSOM
Dependencies#
Supported Python versions#
Python 3.8+
Quick Start Guide for NNSOM#
This guide will help you get started with the NNSOM library, a tool for training Self-Organizing Maps (SOMs).
Basic Usage#
Here’s a quick overview of how to set up and train an SOM model using NNSOM.
Import the necessary libraries and prepare your data as a NumPy matrix.
import numpy as np
np.random.seed(42)
data = np.random.rand(3000, 10) # Random data for demonstration
Define the normalizing function for the data.
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler(feature_range=(-1, 1))
norm_func = scaler.fit_transform()
Set the SOM grid and training parameters.
SOM_Row_Num = 4
SOM_Col_Num = 4
Dimensions = (SOM_Row_Num, SOM_Col_Num)
Epochs = 200
Steps = 100
Init_neighborhood = 3
Initialize and train the SOM.
from NNSOM.plots import SOMPlots
som = SOMPlots(Dimensions)
som.init_w(data, norm_func=norm_func) # data is normalized based on user specific normalized function
som.train(data, Init_neighborhood, Epochs, Steps)
Save and load the trained model.
file_name = "my_som_model.pkl"
model_path = "/path/to/models/"
som.save_pickle(file_name, model_path)
som = som.load_pickle(file_name, model_path)
Visualizing Results#
After training, you can visualize the SOM using the built-in plotting functions.
import matplotlib.pyplot as plt
fig, ax, patches = som.plot('neuron_dist')
plt.show()
For more details on the NNSOM package and its functionalities, refer to the official documentation or the GitHub repository.
Getting help#
If you think you’ve encountered a bug in NNSOM, please report it on the GitHub issue tracker. To be useful, bug reports must include the following information:
A reproducible code example that demonstrates the problem
The output that you are seeing (an image of a plot, or the error message)
A clear explanation of why you think something is wrong
The specific versions of NNSOM that you are working with