Skip to main content

Lightweight ML utility for automated training, evaluation, and prediction with CLI and Python API support

Project description

mlforgex

PyPI Downloads
PyPI Version
License

mlforgex is an end-to-end machine learning automation package for Python.
It allows you to train, evaluate, and make predictions with minimal effort — handling data preprocessing, model selection, hyperparameter tuning, and artifact generation automatically.
It supports both classification and regression problems.


🚀 Features

  • Automatic Data Preprocessing
    • Handles missing values
    • Encodes categorical variables
    • Scales numeric features
  • Automatic Problem Detection
    • Detects whether task is classification or regression
  • Imbalanced Data Handling
    • Over-sampling (SMOTE)
    • Under-sampling
  • Model Training & Evaluation
    • Multiple algorithms tested
    • Best model selected automatically
  • Hyperparameter Tuning
    • Optional tuning via RandomizedSearchCV
  • Artifact Saving
    • Trained model (model.pkl)
    • Preprocessing pipeline (preprocessor.pkl)
    • Encoder (for classification)
  • Visualizations
    • Correlation heatmap
    • Confusion matrix
    • ROC curves
    • Learning curves
  • Command Line Interface (CLI)
    • Train and predict directly from the terminal

📦 Installation

Install via pip:

pip install mlforgex

📋 Requirements

  • Python >= 3.8
  • pandas
  • numpy
  • scikit-learn
  • seaborn
  • matplotlib
  • xgboost
  • imbalanced-learn
  • tqdm

Full list in requirements.txt.


📖 Usage

1️⃣ Train a Model

You can train a model using either CLI or Python code.

CLI Usage

mlforge-train \
    --data_path path/to/data.csv \
    --dependent_feature TargetColumn \
    --rmse_prob 0.3 \
    --f1_prob 0.7 \
    --n_jobs -1 \
    --n_iter 100 \
    --cv 3

Python API Usage

from mlforge import train_model

train_model(
    data_path="data.csv",
    dependent_feature="TargetColumn",
    rmse_prob=0.3,
    f1_prob=0.7,
    n_jobs=-1,
    n_iter=100,
    cv=3,
    artifacts_dir="artifacts",
    fast=False
)

Example Output:

Message: Training completed successfully
Problem_type: Classification
Model: AdaBoostClassifier
Output feature: Outcome
Categorical features: []
Numerical features: ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age']
Train accuracy: 0.8235
Train F1: 0.8245
Train precision: 0.8201
Train recall: 0.8289
Train rocauc: 0.9052
Test accuracy: 0.7576
Test F1: 0.6889
Test precision: 0.6263
Test recall: 0.7654
Test rocauc: 0.8284
Hyper tuned: False
Dropped Columns: []

2️⃣ Predict with a Trained Model

CLI Usage

mlforge-predict \
    --model_path path/to/model.pkl \
    --preprocessor_path path/to/preprocessor.pkl \
    --input_data path/to/input.csv \
    --encoder_path path/to/encoder.pkl

Python API Usage

from mlforge import predict

predictions = predict(
    model_path="model.pkl",
    preprocessor_path="preprocessor.pkl",
    input_data_path="input.csv",
    encoder_path="encoder.pkl"
)

print(predictions)

📂 Artifacts

After training, mlforgex generates the following files:

File Description
model.pkl Trained ML model
preprocessor.pkl Preprocessing pipeline (scaling, encoding, etc.)
encoder.pkl Label encoder (classification only)
Plots/ Visualization folder containing heatmaps, ROC curves, etc.

🛠 CLI Command Reference

Train Command

mlforge-train \
    --data_path <path> \
    --dependent_feature <column> \
    --rmse_prob <float> \
    --f1_prob <float> \
    [--n_jobs <int>] \
    [--n_iter <int>] \
    [--cv <int>] \
    [--artifacts_dir <path>] \
    [--fast <bool>]

Predict Command

mlforge-predict \
    --model_path <model.pkl> \
    --preprocessor_path <preprocessor.pkl> \
    --input_data <input.csv> \
    [--encoder_path <encoder.pkl>]

⚡ Example Workflow

# Step 1: Train the model
mlforge-train --data_path housing.csv --dependent_feature Price --rmse_prob 0.3 --f1_prob 0.7

# Step 2: Use the trained model for predictions
mlforge-predict --model_path artifacts/model.pkl --preprocessor_path artifacts/preprocessor.pkl --input_data new_data.csv

🧪 Testing

Run all tests with:

pytest test/

❗ Troubleshooting & Common Errors

  • "Target is multiclass but average='binary'"
    This happens when using binary metrics on a multiclass dataset.
    ✅ Fix: Use average='macro' or average='weighted' in metrics computation.

  • "FileNotFoundError"
    Ensure all file paths are correct and accessible.

  • "ModuleNotFoundError"
    Install missing dependencies with:

    pip install -r requirements.txt
    

📜 License

This project is licensed under the MIT License.


👨‍💻 Author

Priyanshu Mathur
📧 Email: mathurpriyanshu2006@gmail.com
🌐 Portfolio
📦 PyPI Package

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

mlforgex-1.0.12.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

mlforgex-1.0.12-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file mlforgex-1.0.12.tar.gz.

File metadata

  • Download URL: mlforgex-1.0.12.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mlforgex-1.0.12.tar.gz
Algorithm Hash digest
SHA256 45261e5ba1c4d1c842943c13911703d7faa2c47ec5976fa21761e4db428fb106
MD5 88667540458c49f7ac68c50ec6f32eab
BLAKE2b-256 16a263964f1bcc4022e7f789ee4d693110a99408f6e1a69485ad903b71c297fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlforgex-1.0.12.tar.gz:

Publisher: publish.yml on dhgefergfefruiwefhjhcduc/ML_Forgex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlforgex-1.0.12-py3-none-any.whl.

File metadata

  • Download URL: mlforgex-1.0.12-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mlforgex-1.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 cabedef238c907348ddb18bddacbb32f2c64e6b6322f488c2b09891df963da0a
MD5 e0e255a86529ca8d53b63837aedafba7
BLAKE2b-256 d0593edb87806799e3ad73af02360daa95e09d59d2996bd01c9f30b0e31750e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlforgex-1.0.12-py3-none-any.whl:

Publisher: publish.yml on dhgefergfefruiwefhjhcduc/ML_Forgex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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