Skip to main content

A PySpark MLOps library for simplified model training and optimization

Project description

smallaxe

CI

A PySpark MLOps library that simplifies model training, evaluation, and optimization for PySpark DataFrames.

Why smallaxe?

PySpark MLlib has a steep learning curve and verbose API. smallaxe provides a clean, scikit-learn-like interface for common ML workflows while leveraging the distributed power of Spark.

Features

  • Simple API - Train models with familiar fit()/predict() patterns
  • Multiple Algorithms - XGBoost, LightGBM, CatBoost, and Random Forest
  • Preprocessing Pipeline - Imputer, Scaler, Encoder with chainable pipelines
  • Hyperparameter Optimization - Built-in hyperopt integration with early stopping
  • Automated Training - Train all algorithms and compare with one call
  • Visualization - Plotly-based charts for model evaluation
  • Cross-Validation - Train/test split and k-fold with stratified sampling

Installation

pip install smallaxe

Install with optional algorithm dependencies:

pip install smallaxe[xgboost]    # XGBoost support
pip install smallaxe[lightgbm]   # LightGBM support
pip install smallaxe[catboost]   # CatBoost support
pip install smallaxe[all]        # All algorithms

Quick Start

from smallaxe.training import Regressors
from smallaxe.datasets import load_sample_regression

# Load sample data
df = load_sample_regression(spark)

# Train a model
model = Regressors.random_forest()
model.fit(df, label_col='price', exclude_cols=['id'])

# Make predictions
predictions = model.predict(df)

Usage Examples

Training with Cross-Validation

from smallaxe.training import Classifiers

model = Classifiers.xgboost(task='binary')
model.fit(
    df,
    label_col='churn',
    validation='kfold',
    n_folds=5,
    stratified=True
)

print(model.validation_scores)

Preprocessing Pipeline

from smallaxe.pipeline import Pipeline
from smallaxe.preprocessing import Imputer, Scaler, Encoder
from smallaxe.training import Regressors

pipeline = Pipeline([
    ('imputer', Imputer(numerical_strategy='median')),
    ('scaler', Scaler(method='standard')),
    ('encoder', Encoder(method='onehot')),
    ('model', Regressors.xgboost())
])

pipeline.fit(
    df,
    label_col='target',
    numerical_cols=['age', 'income'],
    categorical_cols=['city', 'category']
)

predictions = pipeline.predict(new_df)

Hyperparameter Optimization

from smallaxe.search import optimize
from hyperopt import hp

param_grid = {
    'max_depth': hp.choice('max_depth', [3, 5, 7, 10]),
    'learning_rate': hp.uniform('learning_rate', 0.01, 0.3)
}

best_model = optimize.run(
    model=Regressors.xgboost(),
    dataframe=df,
    label_col='target',
    param_grid=param_grid,
    metric='rmse',
    max_evals=50
)

print(best_model.best_params)

Automated Training

from smallaxe.auto import AutomatedTraining

auto = AutomatedTraining(model_type='classification', metrics=['f1_score', 'auc_roc'])
auto.fit(
    df,
    label_col='churn',
    numerical_cols=['tenure', 'monthly_charges'],
    categorical_cols=['contract'],
    n_folds=5
)

# Compare all models
auto.metrics.show()

# Use best model
predictions = auto.predict(new_df)

Supported Algorithms

Algorithm Regressor Classifier Dependencies
Random Forest Yes Yes None (native PySpark)
XGBoost Yes Yes smallaxe[xgboost]
LightGBM Yes Yes smallaxe[lightgbm]
CatBoost Yes Yes smallaxe[catboost]

Requirements

  • Python 3.8 - 3.12
  • PySpark 3.3+

License

MIT 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

smallaxe-0.6.1.tar.gz (77.0 kB view details)

Uploaded Source

Built Distribution

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

smallaxe-0.6.1-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file smallaxe-0.6.1.tar.gz.

File metadata

  • Download URL: smallaxe-0.6.1.tar.gz
  • Upload date:
  • Size: 77.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for smallaxe-0.6.1.tar.gz
Algorithm Hash digest
SHA256 f20004da31e32dabfc286eccc77a0e0118e75cf3a50e32b16fd5eae00489b1fa
MD5 af795d864f555b93a41808d6626f2cfc
BLAKE2b-256 abec819c8b84cc070f94cac8e9336e90894922941f378240d812acb97f6d431b

See more details on using hashes here.

File details

Details for the file smallaxe-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: smallaxe-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for smallaxe-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8334cf8d5f6becce9cc65dccffbcfad7a3e0121217eb1dc986139b34f3c8bde9
MD5 25ccfd515cbe3594ccc8d44c338ee233
BLAKE2b-256 0aa2f4a0b45b0a3d7598d0c05f6ec316250f1a15968fada85a273dc9b58feaf0

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