DEV Community

Luiz Seabra de Marco
Luiz Seabra de Marco

Posted on

Your 94% accuracy model might still be a bad model: auditing ML across 7 dimensions

The problem

We usually judge a model by one number. But a classifier with great accuracy can be overconfident, collapse under small input noise, or perform much worse for one subgroup. Those failures rarely show up until production.

What I built

ai-critic is an open-source Python library that audits a model across seven dimensions: performance, robustness, explainability, calibration, data quality, fairness, and complexity.

The key idea is that it’s task-aware. An algorithm doesn’t determine its task: the same tree or neural net can do classification, anomaly detection, or clustering. So you declare the task, and the library picks the evaluation strategy.

Try it in 1 minute

import ai_critic
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split

X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, random_state=42
)

model = RandomForestClassifier(random_state=42).fit(
    X_train, y_train
)

report = ai_critic.audit(
    model,
    (X_test, y_test),
    task_type="classification"
)

print(report.overall_score, report.overall_verdict.value)
Enter fullscreen mode Exit fullscreen mode

Honest by design

If a dimension can’t be measured (no sensitive groups declared, no probabilities for calibration), it’s marked inconclusive or not_applicable and excluded from the overall score, instead of getting a flattering default.

The report records the protocol, weights, and score transformations, making the aggregate more transparent and auditable.

Ship it in CI

ai_critic.gate(report, min_score=0.75)  # Raises if below threshold
Enter fullscreen mode Exit fullscreen mode

Extend it

Write your own evaluator by subclassing BaseEvaluator and passing it to the pipeline.

Help me make it better

It’s young, and I want it battle-tested. If you try it:

  • ⭐ Star the repository if it’s useful.
  • 🐛 Open an issue if something breaks.
  • 💡 Tell me which evaluator or task type you’d like to see next.

What do you check besides accuracy before shipping a model? Let me know in the comments.


Hashnode version

Beyond accuracy: designing a task-aware model auditing library for Python

Most model evaluation tools focus on metrics. But choosing the right metrics is only part of the problem. A model can achieve excellent accuracy while being poorly calibrated, fragile under input perturbations, or unreliable across different subgroups.

I built ai-critic, an open-source Python library designed to audit machine learning models across seven dimensions: performance, robustness, explainability, calibration, data quality, fairness, and complexity.

The central design decision is simple: the task, not the model architecture, should determine the evaluation strategy.

Design principles

1. Task strategy, not model family

The algorithm alone does not define the task. A random forest can perform classification or regression, a decision tree can predict continuous values, and an isolation forest can detect anomalies.

Instead of inferring evaluation behavior exclusively from the model class, ai-critic uses an explicit task_type to select the appropriate evaluation strategy.

2. Explicit uncertainty

Not every dimension can be evaluated with the evidence available. Calibration requires suitable probability estimates, while fairness analysis may require explicitly identified sensitive groups.

ai-critic represents these limitations through statuses such as ok, not_applicable, and inconclusive. Missing evidence should not silently become a favorable score.

3. An inspectable aggregate

A single overall score is useful for comparisons, but it can also hide important details.

The report records aggregation information, including the dimensions included or excluded, their weights, and the score transformations used. This makes it possible to inspect not only the model evaluation but also how the final score was constructed.

Try it in 1 minute

import ai_critic
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split

X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, random_state=42
)

model = RandomForestClassifier(random_state=42).fit(
    X_train, y_train
)

report = ai_critic.audit(
    model,
    (X_test, y_test),
    task_type="classification"
)

print(report.overall_score, report.overall_verdict.value)
Enter fullscreen mode Exit fullscreen mode

This example uses a Random Forest classifier and a held-out test set to produce an audit report.

Architecture and extensibility

Under the hood, ai-critic uses an AuditPipeline architecture with a BaseEvaluator interface. Individual evaluators can focus on specific dimensions while the pipeline coordinates execution and report generation.

The design also supports dependency-aware execution and optional parallelism, where implemented and enabled by the pipeline configuration.

To extend the library, you can subclass BaseEvaluator and pass a custom evaluator into the pipeline. This makes it possible to add task-specific checks without rewriting the entire auditing workflow.

Ship it in CI

Model evaluation should not stop at a report. It can also become part of a development workflow.

ai_critic.gate(report, min_score=0.75)
Enter fullscreen mode Exit fullscreen mode

The gate raises an exception if the report falls below the configured threshold, allowing the evaluation to be integrated into continuous integration pipelines.

A threshold is not a universal definition of model quality, though. It should reflect the requirements of the particular application, and an aggregate score should never replace inspection of critical individual dimensions.

Help me make it better

ai-critic is still young, and I want to test it against real-world use cases and edge cases.

If you try it:

  • ⭐ Star the GitHub repository if you find it useful.
  • 🐛 Open an issue if you encounter a bug or unexpected result.
  • 💡 Suggest an evaluator, task type, or failure mode that should be supported next.

What do you consider essential when auditing a machine learning model beyond accuracy?

I'd especially like to hear about evaluation gaps you've encountered in production or research.


Before publishing, replace YOUR_USER with your actual GitHub username and verify that all API names, statuses, and aggregation details match the public version of your library.

Top comments (0)