GithubHelp home page GithubHelp logo

leferrad / pyoselm Goto Github PK

View Code? Open in Web Editor NEW
35.0 2.0 14.0 159 KB

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

License: Apache License 2.0

Python 95.51% Gherkin 4.49%

pyoselm's Introduction

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)))

pyoselm's People

Contributors

leferrad avatar pablo-davila avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyoselm's Issues

Ideas for layers

A BatchNormalization layer could be a good idea to avoid overflows. Also, Dropout could be something useful (to be checked)

pinv2 error


ImportError Traceback (most recent call last)
F:\TEMP\ipykernel_234664\765891537.py in <cell line: 1>()
----> 1 from pyoselm import OSELMRegressor, OSELMClassifier
2 from sklearn.datasets import load_digits, make_regression
3 from sklearn.model_selection import train_test_split
4
5 print("Regression task")

d:\env\conda\envs\money\lib\site-packages\pyoselm_init_.py in
1 from pyoselm.elm import *
2 from pyoselm.layer import *
----> 3 from pyoselm.oselm import *
4
5 version = "1.0.1"

d:\env\conda\envs\money\lib\site-packages\pyoselm\oselm.py in
10
11 import numpy as np
---> 12 from scipy.linalg import pinv2
13 from scipy.sparse import eye
14 from scipy.special import softmax

ImportError: cannot import name 'pinv2' from 'scipy.linalg' (d:\env\conda\envs\money\lib\site-packages\scipy\linalg_init_.py)

Add functional tests

This library needs testing regarding behavior to ensure the models are working fine in some given scenarios. A BDD testing approach is suggested to cover that with some functional tests.

Add a tutorial

A good option would be a simple Jupyter notebook, where it could show the main features to let the user understand how to completely use this library

Optimization module to tune hyper-parameters

This library could have a new feature: a module optimization with methods to try different hyper-parameters settings to get the best configuration of a model for a given dataset X, y.

Error when installing it via pip

If I try to install that package via pip.

pip install pyoselm

I get the following error:

ERROR: Command errored out with exit status 1:
     command: ...\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"....\\pyoselm\\setup.py'"'"'; __file__='
"'"'....\\pyoselm\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"
'"'exec'"'"'))' egg_info --egg-base '....\pyoselm\
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "....\setup.py", line 18, in <module>
        install_requires=open("requirements.txt").read().split()
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.