RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /MLOps for Local AI
  6. /Ch. 12
MLOps for Local AI

12. Model Validation

Chapter 12 of 24 · 20 min
KEY INSIGHT

Single-metric validation is insufficient. A model can have high accuracy but poor recall for minority classes. Thorough validation examines precision, recall, F1, ROC-AUC, and confusion matrices. Your threshold should reflect business costs of false positives vs. false negatives. Fairness validation catches demographic bias: ```python # Fairness validation def validate_fairness(model, X_test, y_test, sensitive_feature, threshold=0.1): """Check for demographic parity in predictions.""" groups = X_test[sensitive_feature].unique() metrics_by_group = {} for group in groups: mask = X_test[sensitive_feature] == group y_pred = model.predict(X_test[mask]) metrics_by_group[group] = accuracy_score(y_test[mask], y_pred) max_diff = max(metrics_by_group.values()) - min(metrics_by_group.values()) return { "metrics_by_group": metrics_by_group, "max_difference": max_diff, "fair": max_diff <= threshold } ``` Regression model validation differs: ```python # Regression validation def validate_regression(model, X_test, y_test): from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score y_pred = model.predict(X_test) return { "rmse": np.sqrt(mean_squared_error(y_test, y_pred)), "mae": mean_absolute_error(y_test, y_pred), "r2": r2_score(y_test, y_pred), "mape": np.mean(np.abs((y_test - y_pred) / (y_test + 1e-10))) * 100 } ```

Model validation evaluates trained models against defined criteria. Unlike data validation (inputs), model validation assesses outputs: predictions, performance, and behavior. It answers: "Does this model work well enough to deploy?"

The foundational check is holdout validation. Training data splits into train, validation, and test sets. The test set is never seen during training—it's the unbiased measure of performance.

# model_validation.py
import numpy as np
from sklearn.model_selection import cross_val_score, StratifiedKFold
from sklearn.metrics import (
    accuracy_score, precision_score, recall_score, 
    f1_score, roc_auc_score, confusion_matrix
)

def validate_model(model, X_test, y_test, threshold_accuracy=0.90):
    """Thorough model validation."""
    y_pred = model.predict(X_test)
    y_prob = model.predict_proba(X_test)[:, 1]
    
    metrics = {
        "accuracy": accuracy_score(y_test, y_pred),
        "precision": precision_score(y_test, y_pred, zero_division=0),
        "recall": recall_score(y_test, y_pred, zero_division=0),
        "f1": f1_score(y_test, y_pred, zero_division=0),
        "roc_auc": roc_auc_score(y_test, y_prob)
    }
    
    cm = confusion_matrix(y_test, y_pred)
    
    passed = metrics["accuracy"] >= threshold_accuracy
    
    return {
        "passed": passed,
        "metrics": metrics,
        "confusion_matrix": cm.tolist(),
        "threshold": threshold_accuracy
    }

# Cross-validation for reliability
def cross_validate(model, X, y, cv=5):
    """K-fold cross validation."""
    skf = StratifiedKFold(n_splits=cv, shuffle=True, random_state=42)
    
    scores = cross_val_score(
        model, X, y, 
        cv=skf, 
        scoring="accuracy",
        n_jobs=-1
    )
    
    return {
        "scores": scores.tolist(),
        "mean": scores.mean(),
        "std": scores.std(),
        "min": scores.min(),
        "max": scores.max()
    }

Course A007: MLOps for Local AI (Operator Track)

Chapters 13–24

EXERCISE

Implement thorough validation for a model you're training. Run holdout validation, cross-validation, and at least one fairness check. Generate a validation report documenting all metrics and whether thresholds are met.

Course A007: MLOps for Local AI (Operator Track)

Chapters 13–24

← Chapter 11
Data Validation
Chapter 13 →
Drift Detection