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.
pip install randommachineOr install from source:
git clone https://github.com/ghiffaryr/randommachine.git
cd randommachine
pip install -e .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)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)LightGBM-based:
RandomLGBMRegressor- Regression with random LightGBM base learnersRandomLGBMClassifier- Classification with random LightGBM base learners
CatBoost-based:
RandomCatBoostRegressor- Regression with random CatBoost base learnersRandomCatBoostClassifier- Classification with random CatBoost base learners
XGBoost-based:
RandomXGBRegressor- Regression with random XGBoost base learnersRandomXGBClassifier- Classification with random XGBoost base learners
Generic (user-defined pool):
RandomRegressor- Mix any sklearn-compatible regressors with custom probabilitiesRandomClassifier- Mix any sklearn-compatible classifiers with custom probabilities
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.ipynbThe tutorial includes side-by-side comparisons showing RandomMachine's improvement over fixed-family baselines.
Run tests:
make test # Run all tests
make test-cov # With coverage reportFormat code:
make format # Black formatting
make lint # Flake8 lintingMIT License - see LICENSE