Skip to main content

A Python implementation of Online Sequential Extreme Machine Learning (OS-ELM) for online machine learning

Project description

A Python implementation of Online Sequential Extreme Machine Learning (OS-ELM) for online machine learning

CI Pipeline Documentation Status Coverage Status

Description

pyoselm is a Python library for machine learning models with Extreme Machine Learning (ELM) and Online Sequential Machine Learning (OS-ELM). It allows to fit models for regression and classification tasks, both in batch and online learning (either row-by-row or chunk-by-chunk).

This library offers a scikit-learn like API for easy usage. For more details about setup and usage, check the documentation.

IMPORTANT: This library was developed as a research project. It may not be production-ready, so please be aware of that.

Setup

The easiest way to install this library is using pip:

$ pip install pyoselm

Usage

Here a simple but complete example of usage.

from pyoselm import OSELMRegressor, OSELMClassifier
from sklearn.datasets import load_digits, make_regression 
from sklearn.model_selection import train_test_split

print("Regression task")
# Model
oselmr = OSELMRegressor(n_hidden=20, activation_func='sigmoid', random_state=123)
# Data
X, y = make_regression(n_samples=1000, n_targets=1, n_features=10, random_state=123)   
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)
n_batch = 40

# Fit model with chunks of data
for i in range(20):
    X_batch = X_train[i*n_batch:(i+1)*n_batch]
    y_batch = y_train[i*n_batch:(i+1)*n_batch]
    oselmr.fit(X_batch, y_batch)
    print("Train score for batch %i: %s" % (i+1, str(oselmr.score(X_batch, y_batch))))

# Results
print("Train score of total: %s" % str(oselmr.score(X_train, y_train)))
print("Test score of total: %s" % str(oselmr.score(X_test, y_test)))  
print("")


print("Classification task")
# Model 
oselmc = OSELMClassifier(n_hidden=20, activation_func='sigmoid', random_state=123)
# Data
X, y = load_digits(n_class=5, return_X_y=True) 
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)

# Sequential learning
# The first batch of data must have the same size as n_hidden to achieve the first phase (boosting)
batches_x = [X_train[:oselmc.n_hidden]] + [[x_i] for x_i in X_train[oselmc.n_hidden:]]
batches_y = [y_train[:oselmc.n_hidden]] + [[y_i] for y_i in y_train[oselmc.n_hidden:]]

for b_x, b_y in zip(batches_x, batches_y):
    oselmc.fit(b_x, b_y)

print("Train score of total: %s" % str(oselmc.score(X_train, y_train)))
print("Test score of total: %s" % str(oselmc.score(X_test, y_test)))

Development

For development, this project uses Poetry for dependency management:

# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies
poetry install

# Activate environment
poetry shell

# Run tests
make test           # Unit tests
make test-system    # System tests

# Check code quality
make lint

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

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

pyoselm-1.2.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

pyoselm-1.2.0-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file pyoselm-1.2.0.tar.gz.

File metadata

  • Download URL: pyoselm-1.2.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.13.4 Darwin/24.6.0

File hashes

Hashes for pyoselm-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4eb8079bdd07359cde432f6e1fa34ae1f7f5f8cd2aa118dbf2ded8efb6fd47df
MD5 d038d8b227257d983ec52c94f7d7df59
BLAKE2b-256 d2998b37da76daf90f975124b176cd669ce852a51fbaa086825f2a614737eb4b

See more details on using hashes here.

File details

Details for the file pyoselm-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyoselm-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.13.4 Darwin/24.6.0

File hashes

Hashes for pyoselm-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f63696915d8ab5f437ab4c5388e0d71e28d9a51089cd9147239db8b86a386166
MD5 83b502e4dbb65bce597f395732d9a918
BLAKE2b-256 a2ed7818fa4ac62d38d7585d29ea2fb35e5a0263369a312b0bdd863015ebc59d

See more details on using hashes here.

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