No project description provided
Project description
scikit-learn-som
A pluggable Self-Organizing Map (SOM) implementation for scikit-learn, designed to integrate seamlessly with the scikit-learn API.
This package provides an efficient, NumPy-optimized implementation of the SOM algorithm with support for multiple distance metrics, learning rate schedules, and lattice structures.
Features
- Scikit-learn compatible: follows the
fit,transform,predictAPI. - Cluster & transformer mixin: usable for clustering, dimensionality reduction, or feature engineering.
- Square lattice support for grid-based maps.
- Hexagonal lattice support for topologically-aware maps.
- Configurable distance metrics: L2 (Euclidean) and L1 (Manhattan).
- Flexible learning rate schedules: exponential, inverse-time, cosine, step, and polynomial decay.
- Optimized NumPy implementation for efficient training on large datasets.
- Customizable training hyperparameters with scikit-learn style validation.
Installation
pip install scikit-learn-som
Quick Start
from som import SOM
import numpy as np
# Example data
X = np.random.rand(500, 10)
# Initialize SOM
som = SOM(
lattice_rows=20,
lattice_columns=20,
lattice_type="hexagonal", # "square" or "hexagonal"
distance_metric="euclidean", # "euclidean" (L2) or "manhattan" (L1)
max_iters=500,
initial_learning_rate=0.5,
learning_rate_type="cosine",
use_tqdm=True,
)
# Train SOM
som.fit(X)
# Assign each sample to its BMU (Best Matching Unit)
labels = som.predict(X)
# Transform data into SOM feature space
embedding = som.transform(X)
Parameters
lattice_rows(int, default=10): number of rows in the SOM lattice.lattice_columns(int, default=10): number of columns in the SOM lattice.neighbourhood_radius(int, optional): initial neighborhood radius. IfNone, defaults tomax(lattice_rows, lattice_columns) / 2.initial_learning_rate(float, default=1.0): initial learning rate.max_iters(int, default=300): maximum number of training iterations.learning_rate_type({"exponential", "inverse_time", "cosine", "step", "polynomial"}, default="exponential"): learning rate decay strategy.lr_decay_rate(float, default=1e-3): decay rate used in certain schedules.lr_decay_factor(float, default=0.5): multiplicative decay factor for step schedule.lr_step_size(int, default=100): number of iterations before each learning rate step (for step schedule).lr_power(float, default=2.0): power used in polynomial decay.random_state(int, RandomState instance, or None, default=None): seed for reproducibility.verbose(bool, default=False): ifTrue, print progress during training.use_tqdm(bool, default=False): ifTrue, usetqdmprogress bar for training loop.lattice_type({"square", "hexagonal"}, default="square"): type of SOM lattice structure.distance_metric({"euclidean", "manhattan"}, default="euclidean"): distance metric for BMU search.
API
-
fit(X, y=None)Train the SOM on input dataX. -
predict(X)Return the indices of the Best Matching Unit (BMU) for each sample. -
transform(X)Map input data into the SOM embedding space. -
fit_predict(X, y=None)Fit the SOM and return BMU assignments forX.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scikit_learn_som-0.0.6.tar.gz.
File metadata
- Download URL: scikit_learn_som-0.0.6.tar.gz
- Upload date:
- Size: 4.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d90ccfbbaf9346e377104192477194d9e5d8862f90ef4c40e97654d5fefd8eaa
|
|
| MD5 |
2322f20ba5066a1f321356abd8a28a94
|
|
| BLAKE2b-256 |
42a773787cbe51ea287da25adb82a3794973e6fb5a2b8de62a60467265f6c105
|
Provenance
The following attestation bundles were made for scikit_learn_som-0.0.6.tar.gz:
Publisher:
python-publish.yml on abbasidaniyal/scikit-learn-som
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scikit_learn_som-0.0.6.tar.gz -
Subject digest:
d90ccfbbaf9346e377104192477194d9e5d8862f90ef4c40e97654d5fefd8eaa - Sigstore transparency entry: 984579207
- Sigstore integration time:
-
Permalink:
abbasidaniyal/scikit-learn-som@05b1fd89db07606b29ce5afdeb319ba1a2afc04e -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/abbasidaniyal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@05b1fd89db07606b29ce5afdeb319ba1a2afc04e -
Trigger Event:
release
-
Statement type:
File details
Details for the file scikit_learn_som-0.0.6-py3-none-any.whl.
File metadata
- Download URL: scikit_learn_som-0.0.6-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a559498c7af6ce87873f679bbdb526f20a6965699863798048a3c88aa75fc0c7
|
|
| MD5 |
b3c1715b3f4c740a88529a49c6e382af
|
|
| BLAKE2b-256 |
2944a2dfe55bad1cf07ea923328279a946f5e71ce0c19bb91ab5f91c80cc1f46
|
Provenance
The following attestation bundles were made for scikit_learn_som-0.0.6-py3-none-any.whl:
Publisher:
python-publish.yml on abbasidaniyal/scikit-learn-som
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
scikit_learn_som-0.0.6-py3-none-any.whl -
Subject digest:
a559498c7af6ce87873f679bbdb526f20a6965699863798048a3c88aa75fc0c7 - Sigstore transparency entry: 984579210
- Sigstore integration time:
-
Permalink:
abbasidaniyal/scikit-learn-som@05b1fd89db07606b29ce5afdeb319ba1a2afc04e -
Branch / Tag:
refs/tags/v0.0.6 - Owner: https://github.com/abbasidaniyal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@05b1fd89db07606b29ce5afdeb319ba1a2afc04e -
Trigger Event:
release
-
Statement type: