Skip to main content

Cross-validation summary tools for classifier evaluation.

Project description

crosseval

CI

crosseval summarizes machine-learning classifier performance across cross-validation folds. It stores per-fold predictions, probabilities, metadata, abstentions, feature importances, and sample weights, then aggregates them into model-level reports and model-comparison tables.

Installation

pip install crosseval

Core Types

Metric stores one score value plus its display name.

ModelSingleFoldPerformance stores the predictions and scores for one trained model on one fold.

ModelGlobalPerformance combines all folds for one model and produces per-fold aggregates, global scores, confusion matrices, and full text reports.

ExperimentSet stores many (model_name, fold_id) results and summarizes them into an ExperimentSetGlobalPerformance comparison.

Example

import crosseval
from sklearn.base import clone
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold

X, y = load_iris(return_X_y=True, as_frame=True)

models = {
    "logistic": LogisticRegression(max_iter=1000),
    "forest": RandomForestClassifier(n_estimators=100, random_state=0),
}

folds = StratifiedKFold(n_splits=3, shuffle=True, random_state=0)
per_fold = []

for fold_id, (train_idx, test_idx) in enumerate(folds.split(X, y)):
    X_train, X_test = X.iloc[train_idx], X.iloc[test_idx]
    y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]

    for model_name, estimator in models.items():
        clf = clone(estimator).fit(X_train, y_train)
        per_fold.append(
            crosseval.ModelSingleFoldPerformance(
                model_name=model_name,
                fold_id=fold_id,
                clf=clf,
                X_test=X_test,
                y_true=y_test,
                fold_label_train=f"fold-{fold_id}-train",
                fold_label_test=f"fold-{fold_id}-test",
            )
        )

experiment = crosseval.ExperimentSet(per_fold)
summary = experiment.summarize(abstain_label="Unknown")

print(summary.get_model_comparison_stats().to_string())
print(summary.get_model_comparison_stats(formatted=False).to_string())

By default, get_model_comparison_stats() returns display strings such as "0.973 +/- 0.025 (in 3 folds)" and "0.980". Use formatted=False when downstream code needs floats for sorting, thresholding, or further aggregation.

sklearn

crosseval works with fitted sklearn-style classifiers that expose predict() and classes_. If the classifier exposes predict_proba(), crosseval computes probability-based metrics such as ROC-AUC and au-PRC per fold. If the estimator exposes feature_importances_ or linear-model coef_, crosseval stores feature-importance tables; sklearn Pipeline objects are handled by inspecting the final estimator.

Development

uv sync
uv run pre-commit install

uv run pytest
uv run pre-commit run --all-files --show-diff-on-failure

When developing crosseval and genetools side by side, install the local checkout after syncing:

uv pip install -e ../genetools

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

crosseval-0.0.6.tar.gz (48.4 kB view details)

Uploaded Source

Built Distribution

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

crosseval-0.0.6-py3-none-any.whl (33.9 kB view details)

Uploaded Python 3

File details

Details for the file crosseval-0.0.6.tar.gz.

File metadata

  • Download URL: crosseval-0.0.6.tar.gz
  • Upload date:
  • Size: 48.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crosseval-0.0.6.tar.gz
Algorithm Hash digest
SHA256 7fafec7bc0f7b02f107f3cadf7de79e11467cb4b94128aa1a72ad46691647745
MD5 c976b1f2942f012f2d6c0f02c3ab3b00
BLAKE2b-256 1f380a33420b3e6b3dbbbcc11ab2645c4c85ad4cadf1c060f1d2358c2a3ec0b0

See more details on using hashes here.

File details

Details for the file crosseval-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: crosseval-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 33.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crosseval-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8342481a3e2f63120ffb4bdb2b796d076e719421401146c1eb9a0d1942b3ee86
MD5 6223fa85413a34bee5e7ed7e500ac85d
BLAKE2b-256 b7a88989ac274f1f42970b42a197a57ce1a38f6eb8cf0db75f7abd009b0d5ac3

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