Skip to main content

LayerLearn — Flexible Model Library

layerlearn is a small Python package that makes it easy to build stacked estimators (regressors and classifiers) around scikit-learn models. this library is designed to provide a flexible and easy-to-use interface for building stacked models, allowing users to combine multiple models to improve performance. with this library you can stack any scikit-learn compatible models and also you can use the default models provided by the library.

Features

  • Flexible Stacking: Easily stack any scikit-learn compatible models.
  • Regression and Classification: Supports both regression and classification tasks.
  • Customizable: Allows customization of the base and meta models.
  • Easy to Use: Simple API for building and training stacked models.

Requirements

  • Python 3.8+
  • scikit-learn
  • numpy
  • xgboost
  • catboost
  • lightgbm

Installation

From PyPI:

pip install layeredlearning

From source (recommended for development):

git clone https://github.com/Mr-J12/newalgo.git
cd newalgo
pip install -e .

Examples & tests

See example scripts in the repository:

  • testing/regression_default_dataset.py
  • testing/classification_default_dataset.py
  • testing/instantiation_checking.py

Quick examples

Regression:

from layerlearn.flexiblestacked import FlexibleStackedRegressor
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split

X, y = make_regression(n_samples=200, n_features=10, noise=10)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

base = LinearRegression()
meta = RandomForestRegressor(random_state=0)
stack = FlexibleStackedRegressor(base, meta)
stack.fit(X_train, y_train)
preds = stack.predict(X_test)
print(preds[:5])

Classification:

from layerlearn.flexiblestacked import FlexibleStackedClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split

X, y = make_classification(n_samples=200, n_features=10, n_classes=2, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

base = LogisticRegression(max_iter=1000)
meta = RandomForestClassifier(random_state=0)
stack = FlexibleStackedClassifier(base, meta)
stack.fit(X_train, y_train)
preds = stack.predict(X_test)
print(preds[:5])

Visualization

Regression Default Dataset Report

Classification Default Dataset Report

Model-wise Testing Results

Regression Model Performance

The regression testing uses a synthetic dataset with 200 samples and 10 features. The following models are evaluated:

  • baseLinear Regressor: Baseline linear model providing initial predictions
  • baseForest Regressor: Ensemble of trees capturing non-linear patterns and reducing variance
  • baseXGBR Regressor: Regularized gradient boosting with strong performance on tabular data
  • baseLight Regressor: Fast, memory-efficient gradient boosting suited for large datasets
  • baseCat Regressor: Ordered boosting with robust handling of categorical features

Results and performance metrics are visualized in the regression default dataset report above, showing R² Score across all base models.

Regression Model Visualizations

Linear Regression Results

Random Forest Regressor Results

XGBoost Regressor Results

LightGBM Regressor Results

CatBoost Regressor Results

Classification Model Performance

The classification testing uses a synthetic binary classification dataset with 200 samples and 10 features. The following models are evaluated:

  • Logistic Regression : Standard logistic classification baseline
  • Random Forest Classifier : Ensemble method for combining predictions
  • XGBoost Classifier: Gradient boosting for improved classification accuracy
  • LightGBM Classifier: Fast classification with categorical feature support
  • CatBoost Classifier: Optimized for categorical data with robust performance

Results and performance metrics are displayed in the classification default dataset report above, showing Accuracy, Precision, Recall, and F1-Score across all base models.

Classification Model Visualizations

Logistic Regression Results

Random Forest Classifier Results

XGBoost Classifier Results

LightGBM Classifier Results

CatBoost Classifier Results

Development

  • Install development requirements (scikit-learn, numpy).
  • Run example scripts to verify behavior: python testing/regression_default_dataset.py

License

See LICENSE for details.

Metadata

Release files for layeredlearning 1.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for layeredlearning 1.7.2
File Size Uploaded Provenance Actions
layeredlearning-1.7.2.tar.gz 23.6 MB Without provenance Details for layeredlearning-1.7.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for layeredlearning 1.7.2
File Interpreter ABI Platform Actions
layeredlearning-1.7.2-py3-none-any.whl Python 3 none any Details for layeredlearning-1.7.2-py3-none-any.whl

Total release size: 23.6 MB

Release files / layeredlearning-1.7.2.tar.gz

Download URL layeredlearning-1.7.2.tar.gz
Size 23.6 MB
Tags Source
SHA-256 checksum
How to use checksums
3333ea2921da45eec3f0f8e389d6a2e8c5529213def4ae9a1f03ff45015fd281
BLAKE2b-256 checksum
How to use checksums
32fe12819e29243f009dbae3b9d5b2f49275f638ac027f4a0d58c8f2510d73ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / layeredlearning-1.7.2-py3-none-any.whl

Download URL layeredlearning-1.7.2-py3-none-any.whl
Size 40.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89c66afa4b474c3ddc1db4c360ad02fc16062deb7df94a30eae3a4e266267f56
BLAKE2b-256 checksum
How to use checksums
735d147b49d02365a7d40a93eb2e157899a5eb5424089b3f2aea09b8b58b01a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for layeredlearning 1.7.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page