Framework Agnostic Cross-validation Trainer
Project description
factrainer
factrainer (Framework Agnostic Cross-validation Trainer) is a machine learning tool that provides a flexible cross-validation training framework. It addresses the limitations of existing cross-validation utilities in popular ML libraries by offering a unified, parallelized approach that retains models and yields out-of-fold predictions.
Why Use factrainer?
Modern ML frameworks have useful cross-validation functions, but they come with notable limitations:
scikit-learn:cross_val_score: cannot provide out-of-fold (OOF) predictions for each sample.cross_val_predict: cannot retain the trained model from each fold (only returns predictions).
LightGBM:lgb.cv: does not support parallelized training of cv.
These gaps make it cumbersome to get both OOF predictions and reusable trained models in a single workflow.
Key Features
- Unified Cross-Validation API – Provides a single, consistent interface to perform K-fold (or any CV) training, acting as a meta-framework that wraps around multiple ML libraries.
- Parallelized Training – Run cross-validation folds in parallel to fully utilize multi-core CPUs and speed up model training.
- Mutable Model Container – Access each fold’s trained model as a mutable object. This makes it easy to analyze models or create ensembles from the fold models.
- Out-of-Fold Predictions – Retrieve out-of-fold predictions for every training instance through a simple API.
Installation
To install with LightGBM support:
pip install "factrainer[lightgbm]"
At present, LightGBM is the primary supported backend. Support for additional frameworks will be added as the project evolves.
Get started
Code example: California Housing dataset
import lightgbm as lgb
from sklearn.datasets import fetch_california_housing
from factrainer.core import CvModelContainer
from factrainer.lightgbm import LgbDataset, LgbModelConfig, LgbTrainConfig
data = fetch_california_housing()
dataset = LgbDataset(
dataset=lgb.Dataset(
data.data, label=data.target
)
)
config = LgbModelConfig.create(
train_config=LgbTrainConfig(
params={"objective": "regression"},
callbacks=[lgb.early_stopping(100, verbose=False)],
),
)
k_fold = KFold(n_splits=4, shuffle=True, random_state=1)
model = CvModelContainer(config, k_fold, n_jobs_train=4)
model.train(dataset)
# trained models
model.raw_model
# OOF prediction
y_pred = model.predict(dataset)
print(r2_score(data.target, y_pred))
Project Status
factrainer is in active development. The goal is to expand support to more frameworks and make the tool even more robust. Contributions, issues, and feedback are welcome to help shape the future of factrainer.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file factrainer-0.1.16.tar.gz.
File metadata
- Download URL: factrainer-0.1.16.tar.gz
- Upload date:
- Size: 101.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
266f6383e1cbd2e68c2d5c666ef88fee03bde59349c9909bbf6136f597c1f724
|
|
| MD5 |
77c1c18fe4fe2a4b1c7866f92d776ee2
|
|
| BLAKE2b-256 |
6a0bccbf0863301591b0ac571d3012655a38556f85512869c4244b296d9ac4b1
|
Provenance
The following attestation bundles were made for factrainer-0.1.16.tar.gz:
Publisher:
cd-release.yaml on ritsuki1227/factrainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
factrainer-0.1.16.tar.gz -
Subject digest:
266f6383e1cbd2e68c2d5c666ef88fee03bde59349c9909bbf6136f597c1f724 - Sigstore transparency entry: 199877011
- Sigstore integration time:
-
Permalink:
ritsuki1227/factrainer@e246544b4f89e28a1ea3a44b4389abfe887f0283 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ritsuki1227
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd-release.yaml@e246544b4f89e28a1ea3a44b4389abfe887f0283 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file factrainer-0.1.16-py3-none-any.whl.
File metadata
- Download URL: factrainer-0.1.16-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5923476181240d568fe9a8756bf2a43094f1e6c8aa7c4617ca3848184363c9f
|
|
| MD5 |
bc1fdeb7a844cff9a04b2cf433b179d7
|
|
| BLAKE2b-256 |
237b8f17e31192264cc3802c2944bd8b4a0e45842491b34258972821a033a332
|
Provenance
The following attestation bundles were made for factrainer-0.1.16-py3-none-any.whl:
Publisher:
cd-release.yaml on ritsuki1227/factrainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
factrainer-0.1.16-py3-none-any.whl -
Subject digest:
b5923476181240d568fe9a8756bf2a43094f1e6c8aa7c4617ca3848184363c9f - Sigstore transparency entry: 199877015
- Sigstore integration time:
-
Permalink:
ritsuki1227/factrainer@e246544b4f89e28a1ea3a44b4389abfe887f0283 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ritsuki1227
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd-release.yaml@e246544b4f89e28a1ea3a44b4389abfe887f0283 -
Trigger Event:
workflow_run
-
Statement type: