faivor-ml-validator
The backend of the FAIRmodels-validator project
Science Score: 52.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
✓Institutional organization owner
Organization maastrichtu-biss has institutional domain (www.biss-institute.com) -
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.0%) to scientific vocabulary
Repository
The backend of the FAIRmodels-validator project
Basic Info
Statistics
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
- Releases: 0
Metadata Files
README.md
FAIRmodels Validator
Validator library for ML models (FAIRmodels).
This is the backend of the FAIRmodels-validator project. It is a library that validates FAIR models.
It is a REST API server built with FastAPI. The architecture of the project is shown in the following diagram:

Local development
Environment setup and service run
Clone the Repository
Clone the project repository to your local machine.Install Dependencies
In the root directory of the repository, run the following command to install dependencies (Python 3.11+ and Poetry 1.0+ required):
poetry install
- Activate the Virtual Environment
Activate the virtual environment created by Poetry with:
poetry shell
- Juptyer Notebook Kernel
To use this environment in Jupyter notebooks, install a custom kernel by running:
python -m ipykernel install --user --name=faivor-ml-validator --display-name "FAIVOR-ML-Validator"
This command makes the environment available in Jupyter Notebook under the kernel name FAIVOR-ML-Validator.
Run the REST API server
To run the REST API server, execute the following command:
bash
uvicorn src.FAIRmodels-validator.api_controller:app --reload
The server will be running on http://localhost:8000. You can access the API documentation at http://localhost:8000/docs.
Docker Requirements
Important: This service requires Docker access to validate ML models. When running in a container, you must mount the Docker socket. The service automatically handles Docker-in-Docker networking by detecting the environment and using the appropriate hostname. See DEPLOYMENT.md for detailed deployment instructions.
How to Implement New Metrics in FAIVOR-ML-Validator
This guide explains how to add new performance, fairness, or explainability metrics to the FAIVOR-ML-Validator framework. You can add metrics based on scikit-learn, PyTorch, or your own custom Python functions.
1. Decide the Metric Type and Location
- Classification metrics:
Place code inperformance.py,fairness.py, orexplainability.py. - Regression metrics:
Place code inperformance.py,fairness.py, orexplainability.py.
2. Implement the Metric Function
- For scikit-learn metrics:
You can reference them directly in the YAML config (see below). - For custom metrics:
Write a Python function with the signature:python def my_metric(y_true, y_pred, **kwargs): # ... your logic ... return resultExample (classification):python # filepath: src/faivor/metrics/classification/performance.py def my_custom_metric(y_true, y_pred): # Example: return the mean absolute error return np.mean(np.abs(np.array(y_true) - np.array(y_pred)))
3. Register the Metric in the YAML Config
- Classification:
Edit classification_metrics.yaml - Regression:
Edit regression_metrics.yaml
Add a new entry under the appropriate section (performance, fairness, or explainability):
yaml
- function_name: my_custom_metric
regular_name: My Custom Metric
description: Computes the mean absolute error as a custom metric.
func: faivor.metrics.classification.performance.my_custom_metric
is_torch: false
function_name: The Python function name.regular_name: Human-readable name.description: Short description.func: Full import path to your function (or scikit-learn function).is_torch: Set totrueif your function uses PyTorch tensors.
4. (Optional) Add Unit Tests
Add tests for your metric in the appropriate test file, e.g.: - testperformance.py - testperformance.py
Example:
python
def test_my_custom_metric():
y_true = [1, 0, 1]
y_pred = [1, 1, 0]
assert my_custom_metric(y_true, y_pred) == pytest.approx(0.666, rel=1e-2)
5. Use the Metric
Your new metric will now be available for automatic calculation and reporting in the FAIVOR-ML-Validator pipeline, including subgroup and threshold analyses.
6. Troubleshooting
- Import errors:
Ensure your function is imported in the module’s init.py if needed. - YAML path errors:
Thefuncpath must be correct and importable from the project root. - Signature mismatch:
Your function should accept at leasty_trueandy_predas arguments.
Example: Adding a Custom Regression Metric
- Implement:
python # filepath: src/faivor/metrics/regression/performance.py def mean_absolute_percentage_error(y_true, y_pred): y_true, y_pred = np.array(y_true), np.array(y_pred) return np.mean(np.abs((y_true - y_pred) / y_true)) * 100 - Register:
```yaml
# filepath: src/faivor/metrics/regression/regression_metrics.yaml
- functionname: meanabsolutepercentageerror regularname: Mean Absolute Percentage Error description: Computes the mean absolute percentage error. func: faivor.metrics.regression.performance.meanabsolutepercentageerror is_torch: false ```
- Test (optional):
python def test_mean_absolute_percentage_error(): y_true = [100, 200, 300] y_pred = [110, 190, 310] assert mean_absolute_percentage_error(y_true, y_pred) == pytest.approx(4.44, rel=1e-2)
7. Advanced: Metrics Requiring Extra Arguments
If your metric needs extra arguments (e.g., sensitive attributes or feature importances), add them as keyword arguments. The framework will pass them if available.
Example:
python
def fairness_metric(y_true, y_pred, sensitive_values=None):
# ... logic using sensitive_values ...
8. Reload and Validate
After adding your metric, restart the service or rerun your scripts to ensure the new metric is loaded and available.
For more details, see the existing metric implementations in the metrics directory.
Local development
To get started with this project, please follow these steps to set up the environment and configure Jupyter for notebook use:
Owner
- Name: Brightlands Institute of Smart Society
- Login: MaastrichtU-BISS
- Kind: organization
- Location: Heerlen, The Netherlands
- Website: https://www.biss-institute.com/
- Twitter: bissinstitute1
- Repositories: 7
- Profile: https://github.com/MaastrichtU-BISS
Citation (CITATION.cff)
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: FAIRmodels validator library
abstract: 'The backend library of the FAIRmodels-validator project'
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Saba
family-names: Amiri
email: s.amiri@esciencecenter.nl
affiliation: Netherlands eScience Center
- given-names: Vedran
family-names: Kasalica
email: v.kasalica@esciencecenter.nl
affiliation: Netherlands eScience Center
orcid: 'https://orcid.org/0000-0002-0097-1056'
- given-names: Jesus
family-names: Garcia González
email: j.g.gonzalez@esciencecenter.nl
affiliation: Netherlands eScience Center
- given-names: Sonja
family-names: Georgievska
email: s.georgievska@esciencecenter.nl
affiliation: Netherlands eScience Center
repository-code: 'https://github.com/MaastrichtU-BISS/FAIVOR-ML-Validator'
url: 'https://github.com/MaastrichtU-BISS/FAIVOR-ML-Validator'
license: Apache-2.0
GitHub Events
Total
- Issues event: 1
- Delete event: 7
- Issue comment event: 13
- Push event: 81
- Pull request review event: 29
- Pull request review comment event: 26
- Pull request event: 16
- Create event: 9
Last Year
- Issues event: 1
- Delete event: 7
- Issue comment event: 13
- Push event: 81
- Pull request review event: 29
- Pull request review comment event: 26
- Pull request event: 16
- Create event: 9
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 1
- Total pull requests: 11
- Average time to close issues: N/A
- Average time to close pull requests: 11 days
- Total issue authors: 1
- Total pull request authors: 4
- Average comments per issue: 0.0
- Average comments per pull request: 1.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 2
Past Year
- Issues: 1
- Pull requests: 11
- Average time to close issues: N/A
- Average time to close pull requests: 11 days
- Issue authors: 1
- Pull request authors: 4
- Average comments per issue: 0.0
- Average comments per pull request: 1.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 2
Top Authors
Issue Authors
- telegraphroad (1)
Pull Request Authors
- vedran-kasalica (5)
- telegraphroad (3)
- dependabot[bot] (2)
- ctwhome (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v4 composite
- actions/setup-python v5 composite
- python 3.11-slim build
- annotated-types 0.7.0
- anyio 4.7.0
- apscheduler 3.11.0
- attrs 24.3.0
- certifi 2024.12.14
- click 8.1.7
- colorama 0.4.6
- contourpy 1.3.1
- cycler 0.12.1
- fastapi 0.115.6
- fonttools 4.55.3
- h11 0.14.0
- httpcore 1.0.7
- httpx 0.28.1
- idna 3.10
- immutabledict 4.2.1
- importlab 0.8.1
- iniconfig 2.0.0
- jinja2 3.1.4
- joblib 1.4.2
- kiwisolver 1.4.7
- libcst 1.5.1
- markupsafe 3.0.2
- matplotlib 3.10.0
- msgspec 0.18.6
- networkx 3.4.2
- ninja 1.11.1.3
- numpy 2.2.0
- packaging 24.2
- pandas 2.2.3
- pillow 11.0.0
- pluggy 1.5.0
- pycnite 2024.7.31
- pydantic 2.10.3
- pydantic-core 2.27.1
- pydot 3.0.3
- pyparsing 3.2.0
- pytest 8.3.4
- pytest-asyncio 0.24.0
- pytest-datadir 1.5.0
- python-dateutil 2.9.0.post0
- pytype 2024.10.11
- pytz 2024.2
- pyyaml 6.0.2
- scikit-learn 1.6.0
- scipy 1.14.1
- six 1.17.0
- sniffio 1.3.1
- starlette 0.41.3
- tabulate 0.9.0
- threadpoolctl 3.5.0
- toml 0.10.2
- typing-extensions 4.12.2
- tzdata 2024.2
- tzlocal 5.2
- uvicorn 0.31.1
- pytest ^8.3.3 develop
- pytest-asyncio ^0.24.0 develop
- pytest-datadir ^1.3.1 develop
- apscheduler ^3.10
- fastapi ^0.115.2
- httpx ^0.28.1
- matplotlib ^3.9.2
- numpy ^2.1.2
- pandas ^2.2.3
- python >=3.11,<4.0
- pytype ^2024.10.11
- scikit-learn ^1.5.2
- uvicorn ^0.31.1