Install the trustworthy cross-validation toolkit and start validating your machine learning models in minutes. Supports scikit-learn, PyTorch, TensorFlow, and MONAI out of the box.
The base package includes scikit-learn integration and all core cross-validation methods. Install optional extras for deep learning framework support.
| Command | Description |
|---|---|
| pip install trustcv[pytorch] | PyTorch support |
| pip install trustcv[tensorflow] | TensorFlow/Keras support |
| pip install trustcv[monai] | MONAI medical imaging |
| pip install trustcv[all] | All frameworks |
| pip install trustcv[dev] | Development tools |
git clone https://github.com/ki-smile/trustcv.git
cd trustcv
pip install -e .
Load a dataset and create a scikit-learn pipeline, then validate it with a single call using
TrustCVValidator.
from sklearn.datasets import load_breast_cancer
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
X, y = load_breast_cancer(return_X_y=True)
model = make_pipeline(StandardScaler(), RandomForestClassifier(random_state=42))
from trustcv import TrustCVValidator
validator = TrustCVValidator(
method="stratified_kfold",
n_splits=5,
metrics=["accuracy", "roc_auc", "f1"],
check_leakage=True,
check_balance=True,
return_confidence_intervals=True,
)
val_result = validator.validate(model=model, X=X, y=y)
print(val_result.summary())
For more control over the cross-validation strategy, use UniversalCVRunner with any
splitter from the library. It automatically detects your framework.
from trustcv import StratifiedKFold, UniversalCVRunner
cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
runner = UniversalCVRunner(cv_splitter=cv, framework="auto")
results = runner.run(model=model, data=(X, y), metrics=["accuracy", "roc_auc"])
print(results.summary())
Before training, detect potential data leakage and check class balance to ensure your evaluation is trustworthy.
from trustcv import DataLeakageChecker, BalanceChecker
leak_report = DataLeakageChecker().check(X=X, y=y, n_splits=5, random_state=42)
balance_report = BalanceChecker().check_class_balance(y)
print(leak_report.summary)
print(balance_report)
Now that you have trustcv installed, explore these resources to get the most out of the toolkit.