Skip to main content

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, predict API.
  • 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. If None, defaults to max(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): if True, print progress during training.
  • use_tqdm (bool, default=False): if True, use tqdm progress 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 data X.

  • 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 for X.


License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scikit_learn_som-0.0.6.tar.gz (4.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scikit_learn_som-0.0.6-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

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

Hashes for scikit_learn_som-0.0.6.tar.gz
Algorithm Hash digest
SHA256 d90ccfbbaf9346e377104192477194d9e5d8862f90ef4c40e97654d5fefd8eaa
MD5 2322f20ba5066a1f321356abd8a28a94
BLAKE2b-256 42a773787cbe51ea287da25adb82a3794973e6fb5a2b8de62a60467265f6c105

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scikit_learn_som-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for scikit_learn_som-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a559498c7af6ce87873f679bbdb526f20a6965699863798048a3c88aa75fc0c7
MD5 b3c1715b3f4c740a88529a49c6e382af
BLAKE2b-256 2944a2dfe55bad1cf07ea923328279a946f5e71ce0c19bb91ab5f91c80cc1f46

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page