Skip to main content

An AutoML package by plantBrain with classification, regression, and forecasting support.

Project description

PlantBrain-FastML: Automated Machine Learning Framework

PlantBrain-FastML is a Python framework designed to accelerate the process of training, evaluating, and tuning machine learning models. It provides a high-level API to automate boilerplate code for model comparison, preprocessing, and hyperparameter optimization, allowing you to go from a dataset to a tuned model with just a few lines of code.


📚 Table of Contents


Key Features

  • Automated Model Comparison: Evaluate dozens of models for both regression and classification tasks simultaneously to find the best performer.
  • Integrated Preprocessing: Seamlessly apply feature elimination (e.g., using Lasso) and scaling as part of the evaluation pipeline.
  • Powerful Hyperparameter Tuning: Built-in support for Optuna to automatically find the best hyperparameters for your models.
  • Parallel Processing: Speed up model evaluation significantly by utilizing all available CPU cores.
  • Rich Reporting: Generates a comprehensive pandas DataFrame with cross-validation scores and test set metrics for easy analysis.
  • Extensible: Easily add your own custom model wrappers to expand the framework.

Installation

To install the library, clone this repository and install it in editable mode using pip.

git clone https://github.com/YOUR_USERNAME/plantbrain-fastml.git
cd plantbrain-fastml
pip install -e .

Quick Start Examples

1️⃣ Regression Example

import pandas as pd
from sklearn.datasets import load_diabetes
from plantbrain_fastml.managers.regressor_manager import RegressorManager

# Load Data
diabetes = load_diabetes()
X = pd.DataFrame(diabetes.data, columns=diabetes.feature_names)
y = pd.Series(diabetes.target, name='target')

# Initialize the Manager
reg_manager = RegressorManager()

# Evaluate All Models
results = reg_manager.evaluate_all(
    X,
    y,
    hypertune=True,
    hypertune_params={'n_trials': 25},
    n_jobs=-1,
    feature_elimination=True,
    fe_method='lasso',
    fe_n_features=5
)

# Get the Best Model
best_model_name, best_model_object = reg_manager.get_best_model(metric='rmse', higher_is_better=False)
all_hyperparams = reg_manager.get_hyperparameters()

print(f"--- Best Regressor: {best_model_name} ---")
print("Tuned Hyperparameters:")
print(all_hyperparams[best_model_name])

2️⃣ Classification Example

import pandas as pd
from sklearn.datasets import load_breast_cancer
from plantbrain_fastml.managers.classifier_manager import ClassifierManager

# Load Data
cancer = load_breast_cancer()
X = pd.DataFrame(cancer.data, columns=cancer.feature_names)
y = pd.Series(cancer.target, name='target')

# Initialize the Manager
cls_manager = ClassifierManager()

# Evaluate All Models
results = cls_manager.evaluate_all(
    X,
    y,
    hypertune=True,
    hypertune_params={'n_trials': 30},
    n_jobs=-1
)

# Get the Best Model
best_model_name, best_model_object = cls_manager.get_best_model(metric='roc_auc', higher_is_better=True)
all_hyperparams = cls_manager.get_hyperparameters()

print(f"--- Best Classifier: {best_model_name} ---")
print("Tuned Hyperparameters:")
print(all_hyperparams[best_model_name])

Detailed API Reference

RegressorManager & ClassifierManager

These are the main entry points to the library.

  • RegressorManager() — for regression tasks
  • ClassifierManager() — for classification tasks

evaluate_all() - Core Method

This method runs the entire evaluation pipeline.

Signature:

manager.evaluate_all(
    X, y, metrics=None, cv_folds=5, test_size=0.2,
    feature_elimination=False, fe_method=None, fe_n_features=None,
    hypertune=False, hypertune_params=None, hypertune_metrics=None,
    n_jobs=1
)

Key Parameters:

  • X: (pd.DataFrame) input features (numeric)
  • y: (pd.Series) target variable
  • metrics: Optional custom metric dictionary
  • cv_folds: Cross-validation folds
  • test_size: Size of test split
  • feature_elimination: Enable/disable feature selection
  • fe_method: 'lasso', 'tree', or 'correlation'
  • fe_n_features: Number of features to select
  • hypertune: Enable Optuna tuning
  • hypertune_params: Dict like {'n_trials': 50}
  • hypertune_metrics: Metric name for tuning
  • n_jobs: Parallel jobs (-1 = all cores)

Returns:
pd.DataFrame with CV scores and test set metrics for each model.


get_best_model()

Retrieve the best-performing model.

Signature:

manager.get_best_model(metric: str, higher_is_better: bool = True)

Returns:

  • str: Best model name
  • object: Fitted model instance

get_hyperparameters()

Get tuned hyperparameters after evaluate_all(hypertune=True).

Signature:

manager.get_hyperparameters()

Returns:
Dict[str, Dict] — model names mapped to their best parameter dicts.


How to Contribute

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create your branch:
    git checkout -b feature/my-new-feature
    
  3. Commit your changes:
    git commit -am 'Add some feature'
    
  4. Push to your branch:
    git push origin feature/my-new-feature
    
  5. Create a Pull Request

License

This project is licensed under the MIT License — see the LICENSE file for details.

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

plantbrain_fastml-0.4.5.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

plantbrain_fastml-0.4.5-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file plantbrain_fastml-0.4.5.tar.gz.

File metadata

  • Download URL: plantbrain_fastml-0.4.5.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for plantbrain_fastml-0.4.5.tar.gz
Algorithm Hash digest
SHA256 c6197c3189f7926c51e137ef4c35636381e05d2483b9ae20ca590843c9b40a41
MD5 dd642732ccc6c082a69aa8360fb3da9b
BLAKE2b-256 d7228530b4cfdf257a9e3b2cc90cb5b5fa4d5824998f309821fc2fddfbe98d88

See more details on using hashes here.

File details

Details for the file plantbrain_fastml-0.4.5-py3-none-any.whl.

File metadata

File hashes

Hashes for plantbrain_fastml-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a7eeea731eb360a042acc5eba3c7d4a00d1166b9c4e57934b28c587727ea2efa
MD5 44118b3cfed9edfd15ad1e015e211cb2
BLAKE2b-256 0e0e3c76fc0b5a805d05fe952681bae7394a7f582e7d2030e3b6adcc5645084d

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