A lightweight Python package for validating machine-learning datasets, predictions, probabilities, metrics, confusion matrices, and generated reports.
The toolkit is used by the accompanying industrial image defect-detection and sensor predictive-maintenance projects. It provides reusable consistency checks; project-specific questions such as leakage, threshold selection, robustness, and external generalization remain the responsibility of each application.
- required-column checks
- missing- and infinite-value checks
- duplicate-row checks
- allowed categorical-value checks
- numerical range checks
- class-representation checks
- combined dataframe-validation workflows
- target and prediction length consistency
- allowed prediction-label checks
- probability-matrix shape and row-sum checks
- prediction-score range checks
- metric regression thresholds
- confusion-matrix consistency checks
- combined model-output validation workflows
- readable console summaries
- structured JSON reports
- flat CSV validation tables
- report metadata
ValidationFailureErrorfor failing automated pipelines
python -m venv .venv
source .venv/Scripts/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"The current package version is 0.1.0 and requires Python 3.10 or newer.
import pandas as pd
from ml_validation_toolkit import (
print_validation_summary,
run_data_checks,
validation_passed,
)
frame = pd.DataFrame(
{
"score": [0.1, 0.4, 0.9],
"label": ["normal", "normal", "defective"],
}
)
results = run_data_checks(
frame,
required_columns=["score", "label"],
allowed_values={"label": ["normal", "defective"]},
numeric_ranges={"score": (0.0, 1.0)},
target_column="label",
)
print_validation_summary(results, report_name="Example Validation")
print("Passed:", validation_passed(results))python examples/example_validation_workflow.pyThis combines reusable data and model checks and generates JSON and CSV reports.
python examples/validate_image_anomaly_outputs.pyThis self-contained example validates:
- image-record schema and duplicate paths
- binary labels and anomaly-score ranges
- binary probability rows
- accuracy, F1, and AUROC thresholds
- confusion-matrix consistency
- JSON and CSV report generation
Outputs are written to:
example_outputs/image_anomaly/
python examples/validate_sensor_classification.pyThis self-contained example validates:
- recording identifiers and operating-load metadata
- sensor-feature ranges
- four fault classes and predicted labels
- four-class probability rows and confidence scores
- accuracy and macro-F1 thresholds
- confusion-matrix consistency
- JSON and CSV report generation
Outputs are written to:
example_outputs/sensor_classification/
The package exports reusable functions for:
- data checks through
run_data_checks - model-output checks through
run_model_checks - pass/fail evaluation through
validation_passed - console summaries through
print_validation_summary - JSON and CSV reporting through
save_validation_jsonandsave_validation_csv - automated failure handling through
raise_for_validation_failures
The full exported API is defined in src/ml_validation_toolkit/__init__.py.
Run the complete suite with:
pytestGitHub Actions tests the toolkit on Python 3.10 and Python 3.12 for pushes and pull requests to main.
The test suite includes end-to-end checks for both industrial examples and verifies their generated JSON and CSV reports.
ml-testing-validation-toolkit/
├── .github/
│ └── workflows/
│ └── tests.yml
├── examples/
│ ├── __init__.py
│ ├── example_validation_workflow.py
│ ├── validate_image_anomaly_outputs.py
│ └── validate_sensor_classification.py
├── src/
│ └── ml_validation_toolkit/
│ ├── __init__.py
│ ├── data_checks.py
│ ├── model_checks.py
│ └── reporting.py
├── tests/
│ ├── test_project_examples.py
│ └── ...
├── pyproject.toml
└── README.md
This toolkit is integrated into:
The application repositories use the toolkit for reusable feature-table, prediction-output, metric, confusion-matrix, generated-report, and path-portability checks. Domain-specific invariants remain inside their respective projects.
Passing the configured checks confirms that the inspected data and model outputs are internally consistent. It does not by itself prove:
- model generalization
- production readiness
- robustness to distribution changes
- absence of project-specific data leakage
- appropriateness of an operating threshold
Those questions require project-specific experimental design, representative data, and domain validation.