Skip to main content

Random ensemble learning

Project description

RandomMachine

PyPI Version License DOI

Random ensemble learning library that extends gradient boosting by randomly sampling base learners from a pool of LightGBM, CatBoost, XGBoost, and arbitrary scikit-learn-compatible estimators for improved ensemble diversity.

Installation

pip install randommachine

Or install from source:

git clone https://github.com/ghiffaryr/randommachine.git
cd randommachine
pip install -e .

Quick Start

Regression

from randommachine import RandomLGBMRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split

X, y = make_regression(n_samples=1000, n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = RandomLGBMRegressor(num_iterations=20, learning_rate=0.5, random_state=42)
model.fit(X_train, y_train, X_eval=X_test, y_eval=y_test)

predictions = model.predict(X_test)

Classification

from randommachine import RandomCatBoostClassifier
from sklearn.datasets import make_classification

X, y = make_classification(n_samples=1000, n_features=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = RandomCatBoostClassifier(num_iterations=20, learning_rate=0.5)
model.fit(X_train, y_train, X_eval=X_test, y_eval=y_test)

predictions = model.predict(X_test)
probabilities = model.predict_proba(X_test)

Available Models

LightGBM-based:

  • RandomLGBMRegressor - Regression with random LightGBM base learners
  • RandomLGBMClassifier - Classification with random LightGBM base learners

CatBoost-based:

  • RandomCatBoostRegressor - Regression with random CatBoost base learners
  • RandomCatBoostClassifier - Classification with random CatBoost base learners

XGBoost-based:

  • RandomXGBRegressor - Regression with random XGBoost base learners
  • RandomXGBClassifier - Classification with random XGBoost base learners

Generic (user-defined pool):

  • RandomRegressor - Mix any sklearn-compatible regressors with custom probabilities
  • RandomClassifier - Mix any sklearn-compatible classifiers with custom probabilities

Tutorial

An interactive Jupyter notebook is available in the /docs folder:

  • Tutorial - Getting started guide with performance comparison vs plain LightGBM, CatBoost, and XGBoost baselines
cd docs/
jupyter notebook tutorial.ipynb

The tutorial includes side-by-side comparisons showing RandomMachine's improvement over fixed-family baselines.

Development

Run tests:

make test          # Run all tests
make test-cov      # With coverage report

Format code:

make format        # Black formatting
make lint          # Flake8 linting

License

MIT License - see 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

randommachine-0.1.2.tar.gz (306.3 kB view details)

Uploaded Source

Built Distribution

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

randommachine-0.1.2-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file randommachine-0.1.2.tar.gz.

File metadata

  • Download URL: randommachine-0.1.2.tar.gz
  • Upload date:
  • Size: 306.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for randommachine-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a8698e66750ddbde132900a4492bd89841b90734d0d375721e0521ff49b1412c
MD5 776c168b7255b909fb457e579dacd467
BLAKE2b-256 dfb3ad9d44c9141f99d7c70d5d7c26abe6c1e2b1fec760ba7cf5423f281b8ce9

See more details on using hashes here.

File details

Details for the file randommachine-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: randommachine-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for randommachine-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c36525d86a8d802dec766e4f1c430ad2b447ed6c952b5f09f7fd61cf21c1f63b
MD5 f18e1818b7bcb3f9314388e509854e45
BLAKE2b-256 919ca16214b00f1649570e21a4f1f3306013ebb0612adced01f8c386d68ca40e

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