Skip to main content

Serverlex ⚡

The Production-Safe Machine Learning Preprocessing, Diagnostics, & Serving Platform

Python Version PyPI version PyPI Downloads License: MIT Code Style

Serverlex is an end-to-end Python library that takes raw, dirty data and transforms it into model-ready features, baseline benchmarks, tuned algorithms, and live production endpoints—all without data leakage or boilerplate code.


📦 Installation

Install the official release directly from PyPI:

pip install serverlex

Or Install From Source / GitHub:

# Latest development branch from GitHub:
pip install git+https://github.com/Uwais-ML/Serverlex.git

# Or clone and install in editable mode:
git clone https://github.com/Uwais-ML/Serverlex.git
cd Serverlex
pip install -e .

🏗️ Architecture

flowchart TD
    subgraph 1. Ingestion & Quality
        A["Raw CSV / JSON"] --> B["DataCheck (DataGuard)"]
        B --> C["Clean (Sanitation Engine)"]
        C <--> D["Visualization (Live EDA)"]
    end

    subgraph 2. Preprocessing & Selection
        C --> E["MLPipeline (fit/transform)"]
        E --> F["FeatureSelector (Mutual Info)"]
    end

    subgraph 3. Modeling & Optimization
        F --> G["Baseline Evaluator (.add_model)"]
        G --> H["ModelHyperparameter (Nested CV)"]
        G --> I["EnsembleBuilder (Stacking/Voting)"]
    end

    subgraph 4. Diagnostics & Deployment
        H & I --> J["Evaluation (ModelEvaluator)"]
        H & I --> K["Explainability (ModelExplainer)"]
        E & H --> L["ModelDeployer (Joblib Bundle)"]
        L --> M["Live Raw Inference (1-line predict)"]
        L --> N["DriftDetector (Production Shift Alert)"]
    end

⚡ 60-Second Quickstart

import pandas as pd
from serverlex import (
    DataGuard,
    MLPipeline,
    ModelHyperparameter,
    ModelExplainer,
    ModelDeployer
)

# 1. Load Raw Messy Data
df = pd.read_csv("customers.csv")

# 2. Automated Quality Audit (catches ID columns, target leakage, class imbalance)
guard = DataGuard(df)
guard.run_audit(target="churn")

# 3. Fit Pipeline on Training Data (Zero Data Leakage)
train_df = df.iloc[:800].copy()
test_df = df.iloc[800:].copy()

pipeline = MLPipeline()
pipeline.fit(
    train_df,
    target="churn",
    encode="onehot",
    scale="standard",
    data_time=["signup_date", "%Y-%m-%d"],
    numeric_string_cols=["monthly_bill"]
)

X_train, y_train = pipeline.transform(train_df)
X_test, y_test = pipeline.transform(test_df)

# 4. Benchmark Baseline Models (+ add custom ones)
pipeline.evaluate_baseline_models(X_train, y_train, cv=5)

# 5. Tune Best Model with Unbiased Nested Cross-Validation
from sklearn.ensemble import RandomForestClassifier
tuner = ModelHyperparameter()
param_grid = tuner.get_default_param_grid("random_forest")

tune_res = tuner.tune_nested_cv(
    estimator=RandomForestClassifier(random_state=42),
    param_grid=param_grid,
    X=X_train,
    y=y_train,
    outer_cv=5,
    inner_cv=3
)
best_model = tune_res["best_estimator"]

# 6. Model Explainability
explainer = ModelExplainer(best_model, X_train.columns)
print(explainer.get_feature_importances().head(5))

# 7. Bundle & Deploy for Production Serving
deployer = ModelDeployer(pipeline=pipeline, model=best_model)
deployer.save("churn_deployer.joblib")

# Later in production: Predict directly on raw incoming JSON / dict!
loaded_deployer = ModelDeployer.load("churn_deployer.joblib")
raw_input = {"signup_date": "2026-04-01", "monthly_bill": "$89.50", "device": "laptop"}
print("Predicted Churn:", loaded_deployer.predict(raw_input)[0])

📦 Core Module Reference

Module Core Class Primary Purpose
serverlex.preprocessing.clean Clean Headers, deduplication, IQR/Z-score outlier capping, format parsing.
serverlex.diagnostics.dataguard DataGuard Pre-training safety audit (ID detection, target leakage, class imbalance).
serverlex.visualization.eda Visualize EDA plots (missing, distribution, box, correlation) and real-time plt.ion().
serverlex.preprocessing.pipeline MLPipeline Leakage-free fit/transform, datetime extraction, encoding, scaling.
serverlex.modeling.selector FeatureSelector Mutual Information ranking, collinearity pruning, variance threshold.
serverlex.modeling.hyperparameter ModelHyperparameter Non-nested GridSearchCV and unbiased Nested Cross-Validation.
serverlex.modeling.ensemble EnsembleBuilder Soft/Hard Voting and Stacking ensembles with meta-learners.
serverlex.diagnostics.evaluation ModelEvaluator Confusion matrix, ROC-AUC, PR curves, and regression residuals.
serverlex.diagnostics.explainability ModelExplainer Native tree feature importances & permutation importance.
serverlex.serving.deployer ModelDeployer Pipeline-model artifact bundling, schema validation, and raw inference.
serverlex.diagnostics.drift DriftDetector KS-test, Chi-Square, PSI (Population Stability Index), and Wasserstein distance.

🧪 Running Unit Tests & Benchmarks

Run the complete test suite locally:

pytest -v tests/

Reproduce the exact Kaggle benchmarks:

python benchmarks/reproduce_benchmarks.py

🏆 Real-World Kaggle Benchmarks

Serverlex was verified on real-world Kaggle datasets without custom code changes:

  • Customer Churn (muhammadshahidazeem/customer-churn-dataset):

    • DataGuard detected CustomerID as 100% unique ID and recommended removal.
    • Leakage-free preprocessing reached 99.42% accuracy using Gradient Boosting.
  • Walmart Store Sales (mikhail1681/walmart-sales):

    • Automatically extracted year, month, day, dayofweek, and is_weekend from dates.
    • Achieved $R^2 = 0.9455$ and RMSE = 133,727 using Random Forest Regressor.
    • Baseline Gradient Boosting achieved 99.42% accuracy.
    • ModelExplainer identified support_calls (0.277) and total_spend (0.235) as top drivers.
  • Walmart Sales (mikhail1681/walmart-sales):

    • Extracted cyclical features from date strings (year, month, day, dayofweek).
    • Auto-detected regression and trained Random Forest Regressor to $R^2 = 0.9455$ ($\text{RMSE} = 133,727$).

🛠️ Installation

# Clone and install in editable development mode:
git clone https://github.com/your-username/Serverlex.git
cd Serverlex
pip install -e .

📖 In-Depth Manual

For mathematical concepts, parameter references, and output walkthroughs for every module, see DOCUMENTATION.md.

Metadata

Release files for serverlex 1.2.0

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

Source distribution (sdist)

Source distribution for serverlex 1.2.0
File Size Uploaded
serverlex-1.2.0.tar.gz 35.0 kB Details

Built distribution (wheel)

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

Total release size: 69.9 kB

Release files / serverlex-1.2.0.tar.gz

Download URL serverlex-1.2.0.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f4447e644ca889eb432ea79a2bd3f839532b1caa006e779cf1830e310ac1a92b
BLAKE2b-256 checksum
How to use checksums
03c03d280f657cf46886b87fd044fd9fb158d128eb7719462a23fd4f2d637796
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Release files / serverlex-1.2.0-py3-none-any.whl

Download URL serverlex-1.2.0-py3-none-any.whl
Size 34.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c78cc3113d52b35168eb3758ad0d24469453ccedf1d380b9d58bbe53019a0603
BLAKE2b-256 checksum
How to use checksums
e391814abdd0dd5f07285e28ea8aa7a924ae9541d03f095efe349db5ec568630
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Release history Release notifications | RSS feed

1.3.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

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