Introduction to Artificial Intelligence

Chapter 13
AI Evaluation, Engineering and Operations

Bachelors Program in AI & ML
Introduction to Artificial Intelligence   •   Bachelor

AI Evaluation, Engineering and Operations

Introduction

Building an artificial intelligence model is only one part of developing an AI system. A model may achieve high accuracy in a laboratory yet fail in production because its data change, its predictions are difficult to explain, its API is unreliable, or its use creates privacy and security risks. AI evaluation, engineering, and operations therefore connect statistical modelling with software engineering, cloud infrastructure, governance, and continuous improvement.

This chapter examines how to evaluate AI systems appropriately, engineer them as dependable applications, and operate them throughout their lifecycle. The discussion applies to supervised learning, computer vision, natural language processing, recommendation systems, and generative AI.

Learning Objectives

By the end of this chapter, you should be able to:

1. Select evaluation metrics that match an AI task and its consequences.

2. Diagnose data-quality problems, class imbalance, leakage, and distribution shift.

3. Explain robustness, fairness, interpretability, privacy, and security requirements.

4. Describe the architecture of a production AI system, including APIs and cloud components.

5. Explain the principles of MLOps, monitoring, deployment, and lifecycle management.

6. Apply these ideas to an AI implementation case and identify engineering trade-offs.

1. Evaluation as a Decision Process

Evaluation is not simply the calculation of a score. It is the systematic assessment of whether a system performs a defined task reliably, safely, fairly, and economically in its intended context.

A useful evaluation begins by specifying:

  • the prediction target;
  • the population and operating environment;
  • the consequences of different errors;
  • the acceptable latency, cost, and availability;
  • legal, ethical, and security constraints; and
  • the conditions under which the system must abstain or defer to a human.

A model should be evaluated at several levels:

1. Data level: Are the inputs accurate, representative, timely, and legally obtained?

2. Model level: Does the model generalize to unseen data?

3. System level: Does the complete application meet latency, availability, and integration requirements?

4. Impact level: Does its use produce acceptable outcomes for users and affected groups?

A single aggregate metric can hide serious failures. For example, a model may have excellent average performance but perform poorly for a minority population or during unusual operating conditions.

2. Classification Metrics

Consider a binary classifier that predicts a positive or negative class. Its results can be represented by a confusion matrix:

  • True positive (TP): a positive case correctly identified.
  • True negative (TN): a negative case correctly identified.
  • False positive (FP): a negative case incorrectly identified as positive.
  • False negative (FN): a positive case incorrectly identified as negative.

Accuracy

Accuracy is

Accuracy = (TP + TN) / (TP + TN + FP + FN)

It is the proportion of all predictions that are correct. Accuracy is appropriate when classes are reasonably balanced and the costs of false positives and false negatives are similar. It can be misleading for imbalanced data. If only 1% of transactions are fraudulent, a classifier that always predicts “not fraud” achieves 99% accuracy while detecting no fraud.

Precision and Recall

Precision = TP / (TP + FP)

Precision answers: among cases predicted positive, how many are truly positive? It matters when false alarms are costly, such as when every flagged transaction requires expensive investigation.

Recall = TP / (TP + FN)

Recall, also called sensitivity or true positive rate, answers: among all actual positive cases, how many were detected? It matters when missing a positive case is dangerous, such as failing to identify a serious disease.

The denominators must be non-zero. These measures are conditional on the chosen classification threshold.

Specificity and False-Positive Rate

Specificity = TN / (TN + FP)

Specificity measures the proportion of actual negative cases correctly rejected. The false-positive rate is:

FPR = FP / (FP + TN) = 1 − specificity

F1 Score

The F1 score is the harmonic mean of precision and recall:

F1 = 2 × (Precision × Recall) / (Precision + Recall)

It is useful when both precision and recall matter and a single summary is required. It does not include true negatives and therefore is not a complete measure of performance. The F1 score should not automatically replace metrics that reflect real operational costs.

Thresholds and the Precision–Recall Trade-off

Many classifiers produce a probability or score rather than a final class. A threshold converts that score into a decision. Lowering the threshold generally increases recall but may reduce precision; raising it often has the opposite effect. The threshold should be selected using validation data and a clearly stated business or safety objective, not chosen merely because 0.5 is conventional.

The receiver operating characteristic (ROC) curve plots true-positive rate against false-positive rate across thresholds. Its area under the curve (ROC-AUC) measures ranking ability across thresholds. Precision–recall curves are often more informative when the positive class is rare because they show performance in relation to positive predictions.

Worked Example: A Fraud Detector

Suppose a test set contains 1,000 transactions. The detector produces 40 true positives, 20 false positives, 10 false negatives, and 930 true negatives.

Accuracy = (40 + 930) / 1,000 = 0.97, or 97%.

Precision = 40 / (40 + 20) = 40/60 = 66.7%.

Recall = 40 / (40 + 10) = 40/50 = 80%.

F1 = 2 × (0.667 × 0.80) / (0.667 + 0.80) ≈ 0.727, or 72.7%.

The 97% accuracy appears impressive, but the precision result shows that approximately one-third of flagged transactions are false alarms. Whether this is acceptable depends on the cost of investigation and the cost of undetected fraud.

3. Regression, Ranking, and Generative-AI Evaluation

For regression, common measures include:

Mean absolute error (MAE) = (1/n) Σ |yᵢ − ŷᵢ|

Mean squared error (MSE) = (1/n) Σ (yᵢ − ŷᵢ)²

Root mean squared error (RMSE) = √MSE

Here, n is the number of observations, yᵢ is the observed value, and ŷᵢ is the prediction. MAE is expressed in the same units as the target and treats errors linearly. MSE and RMSE penalize large errors more strongly; RMSE has the target’s units, whereas MSE has squared units. These measures assume that the target values and predictions are comparable and that the evaluation sample represents intended use.

Mean absolute percentage error can be difficult when actual values are zero or close to zero, and percentage-based metrics may be inappropriate for quantities where relative error is not meaningful.

For ranking and recommendation, evaluation may use precision at k, recall at k, mean reciprocal rank, or normalized discounted cumulative gain. These measures recognize that the order of results matters and that users may inspect only the first few results.

Generative-AI systems require task-specific evaluation. Relevant dimensions include factual accuracy, relevance, coherence, toxicity, bias, citation correctness, instruction following, refusal behavior, latency, and cost. Automatic similarity scores can be useful but do not establish truthfulness or usefulness. Human evaluation, expert review, adversarial testing, and carefully designed benchmark sets are often necessary.

4. Data Quality and Experimental Validity

Model performance cannot exceed the usefulness of the information and labels on which it depends. Important data-quality dimensions include:

  • Completeness: required fields and cases are present.
  • Accuracy: values correctly represent the underlying phenomenon.
  • Consistency: formats and meanings agree across sources.
  • Timeliness: data reflect the current operating environment.
  • Validity: values follow permitted ranges and types.
  • Uniqueness: duplicated records do not distort learning.
  • Representativeness: the sample reflects the population in which the system will operate.

Labels may be noisy, subjective, or affected by historical decisions. A model trained on biased labels can reproduce institutional bias even when its code is technically correct. Labeling instructions, annotator training, disagreement analysis, and adjudication are therefore part of evaluation engineering.

Data Leakage

Data leakage occurs when information unavailable at prediction time influences training or evaluation. Examples include using a post-treatment medical result to predict treatment need, allowing duplicate records to appear in both training and test sets, or normalizing the full dataset before splitting it. Leakage produces an unrealistically optimistic estimate.

A robust process separates data temporally or by entity when appropriate, fits preprocessing steps only on training data, and preserves a final test set that is not repeatedly consulted during development.

Class Imbalance

Imbalance occurs when one class is much more common than another. Possible responses include collecting more minority examples, using class-weighted losses, resampling the training data, adjusting thresholds, and reporting precision, recall, specificity, and subgroup results. Resampling must be applied within the training partition; oversampling before the split can place near-duplicates in both training and test data.

No technique removes the need to inspect the underlying data-generating process. A rare class may represent a genuinely rare event, a missing-data problem, or a classification definition that needs revision.

5. Robustness, Fairness, Explainability, Privacy, and Security

Robustness and Reliability

A robust system maintains acceptable performance when inputs vary within plausible conditions. Testing may include noisy inputs, missing features, spelling variation, lighting changes, sensor failure, distribution shift, and deliberately manipulated examples. Reliability also includes calibrated confidence, graceful failure, fallback procedures, and the ability to abstain when evidence is insufficient.

Distribution shift may be:

  • Covariate shift: input distributions change while the relationship to the target is assumed stable.
  • Label or concept shift: the relationship between inputs and outcomes changes.
  • Prior-probability shift: class frequencies change.

Monitoring should detect these changes rather than assuming that a model remains valid indefinitely.

Fairness

Fairness is context-dependent and cannot be reduced to one universal metric. Evaluation may compare error rates, selection rates, calibration, or ranking quality across relevant groups. Important questions include whether groups are represented adequately, whether labels encode historical disadvantage, and whether the system’s use creates unequal access or burden.

Some fairness criteria cannot generally be satisfied simultaneously when groups differ in base rates. Consequently, fairness requires normative and institutional decisions in addition to statistical analysis. Sensitive attributes may be needed for auditing even when they are excluded from prediction, subject to legal and governance requirements.

Explainability

Interpretability concerns how understandable a model or decision is to an intended audience. Explanations may be:

  • Global: describing overall model behavior.
  • Local: explaining one prediction.
  • Example-based: showing similar or influential cases.
  • Counterfactual: describing what change might alter an outcome.

Feature importance is not automatically causal explanation. Post-hoc explanations can be unstable or misleading, particularly for complex models. Explanations should be tested with domain experts and should communicate uncertainty, limitations, and the fact that a correlation is not necessarily a cause.

Privacy

AI systems may expose personal or sensitive data through collection, storage, training, logs, outputs, or model interfaces. Responsible design includes data minimization, purpose limitation, access control, encryption, retention limits, de-identification where appropriate, consent or another lawful basis, and mechanisms for data-subject rights where applicable.

Differential privacy provides a formal framework for limiting the influence of any one individual on a released result. In practical settings, privacy protection involves a trade-off: stronger privacy usually reduces available statistical information. Federated learning can keep raw data at multiple sites, but it does not eliminate risks from model updates, inference, or compromised participants.

Security

AI security threats include data poisoning, adversarial examples, prompt injection, model extraction, membership inference, sensitive-data leakage, insecure dependencies, and denial-of-service attacks. Controls include authenticated APIs, authorization, rate limiting, input validation, secret management, network isolation, dependency scanning, secure logging, red-team testing, and incident-response procedures.

Security must cover the complete supply chain: datasets, labeling tools, code, pretrained models, containers, cloud services, and deployment pipelines.

6. AI System Architecture

A production AI system usually contains more than a model. A conceptual architecture includes:

1. Data sources: databases, sensors, documents, user events, or external services.

2. Ingestion and validation: pipelines that collect data and check schemas, ranges, quality, and permissions.

3. Storage: operational databases, object stores, data warehouses, or feature stores.

4. Training and experimentation: reproducible code, datasets, configurations, and compute resources.

5. Model registry: versioned models, metadata, evaluation results, approvals, and lineage.

6. Serving layer: batch jobs, online inference services, or edge deployment.

7. Application layer: business logic, user interfaces, workflow, and human review.

8. Observability: logs, metrics, traces, alerts, and audit records.

An online prediction service commonly exposes an API. A request may contain an authenticated user identifier and validated features; the response may contain a prediction, confidence information, model version, and an explanation or reason code. APIs should define schemas, error behavior, timeouts, versioning, authentication, and rate limits. Sensitive inputs should not be placed unnecessarily in logs.

Batch inference is appropriate when predictions can be generated periodically and low latency is unnecessary. Online inference is appropriate when a decision depends on current information and must be returned quickly. Edge inference can reduce latency and data transfer but introduces device-management and update challenges.

Cloud platforms provide scalable storage, compute, managed databases, container orchestration, model-serving services, identity management, and monitoring. Their benefits include elasticity and rapid deployment; their risks include vendor lock-in, unpredictable cost, configuration errors, data residency concerns, and shared-responsibility gaps. An organization remains responsible for appropriate access control and lawful use even when infrastructure is managed by a provider.

7. MLOps and Lifecycle Management

MLOps applies software engineering and operations practices to machine-learning systems. Its objective is not merely automatic deployment but reproducible, observable, governed, and maintainable delivery.

A typical lifecycle is:

1. Define the problem, users, risks, and success criteria.

2. Acquire, document, validate, and version data.

3. Establish a baseline and create reproducible experiments.

4. Train and evaluate candidate models using appropriate splits and metrics.

5. Review fairness, privacy, security, and operational readiness.

6. Package and deploy through a controlled pipeline.

7. Monitor performance, data quality, drift, cost, and incidents.

8. Retrain, roll back, retire, or replace the system when justified.

Useful practices include source control, automated tests, continuous integration, infrastructure as code, containerization, dataset and model versioning, experiment tracking, approval gates, and reproducible environments. A model registry should record who trained a model, on which data, with what code, metrics, dependencies, and intended use.

Deployment strategies include:

  • Shadow deployment: the new model receives live inputs but does not affect decisions.
  • Canary deployment: the new model serves a small proportion of traffic first.
  • A/B testing: different versions are compared under a defined experimental design.
  • Blue–green deployment: two production environments allow controlled switching and rollback.

A model should not be promoted merely because its offline score is higher. It must also satisfy latency, cost, fairness, security, and reliability requirements.

8. Monitoring and Incident Response

Monitoring should include both conventional software indicators and model-specific indicators.

Service indicators include availability, response latency, error rates, throughput, and resource utilization. Data indicators include missingness, schema changes, ranges, category frequencies, and distribution changes. Model indicators include prediction distributions, confidence, calibration, precision or recall when delayed labels become available, and subgroup performance. Business indicators include conversion, losses prevented, user complaints, or human-review workload.

Ground-truth performance is often delayed. In the interim, proxy indicators and drift measures can provide warnings but cannot prove that accuracy has changed. Alerts need owners, thresholds, severity definitions, and runbooks. Excessive alerts create fatigue; insufficient alerts allow silent failure.

An incident process should preserve relevant evidence, limit harm, communicate with stakeholders, investigate root causes, and document corrective action. Possible responses include disabling a feature, reverting to a previous model, increasing human review, restricting traffic, or retraining with corrected data.

Lifecycle management also includes retirement. A model should be withdrawn when its data sources are unavailable, its performance is unacceptable, its purpose is obsolete, its risks exceed its benefits, or a safer replacement exists. Retirement requires archiving records, disabling endpoints, updating documentation, and communicating the change.

9. Illustrative Case: AI-Assisted Loan Application Triage

Background

The following is a fictional illustrative case. A regional lender proposes an AI system to prioritize loan applications for human review. The system does not make final approval decisions; it predicts whether an application requires additional review based on documentation completeness, affordability indicators, and fraud-risk signals.

Problem

An initial prototype reports 94% accuracy. However, the positive class—applications requiring review—represents only 8% of applications. The compliance team is concerned about unequal error rates, privacy, and the possibility that historical decisions encode bias.

Analysis

The development team constructs a confusion matrix and reports precision, recall, specificity, and subgroup results rather than accuracy alone. It discovers that the prototype has high specificity but low recall: it misses many applications that should receive review. A random train–test split also places multiple applications from the same customer in both partitions, creating leakage.

The team replaces the split with a time-based split and an applicant-level grouping rule. It audits missing values, checks whether variables are available at the moment of triage, and removes a field that was recorded only after a review decision. Labels are reviewed because “manual review required” partly reflects historical staff practices rather than an objective risk.

Approach and Solution

The lender defines two operating objectives: high recall for regulatory or fraud-related review categories and a manageable review workload. Thresholds are selected using a validation period. The system is tested separately across relevant demographic groups, with legal and privacy specialists determining which audit attributes may be used. A human reviewer remains responsible for the final decision, and applicants receive a process explanation and an appeal route.

The model is deployed in shadow mode, then through a canary release. The API returns a model version and reason codes but excludes sensitive raw features from logs. Monitoring tracks missingness, score distributions, review workload, subgroup recall, latency, and delayed outcomes. A rollback mechanism is tested before full deployment.

Outcome

The revised system has lower overall accuracy than the original prototype but substantially higher recall for applications requiring review, fewer data-leakage risks, and a documented audit trail. The lender decides that the model is acceptable only as a prioritization aid, not as an autonomous approval mechanism.

Learning Points

The case demonstrates that evaluation metrics must follow the decision context; offline results can be invalidated by leakage; labels require institutional analysis; fairness and privacy must be designed into the system; and deployment controls are as important as model selection.

10. Professional Practice and Governance

AI engineers work across data science, software development, product management, legal compliance, cybersecurity, and domain expertise. Effective teams document intended use, prohibited use, assumptions, known limitations, data provenance, evaluation protocols, and escalation contacts.

Governance frameworks commonly require risk classification, impact assessment, human oversight, transparency, record keeping, access controls, and supplier management. Specific obligations depend on jurisdiction and application area. High-impact domains such as health, employment, education, finance, and public services require particular care because errors may affect rights and opportunities.

A practical governance document should answer:

  • What decision does the system support?
  • Who is affected, and who can challenge an outcome?
  • What data are used and why?
  • What evidence supports performance claims?
  • What happens when the system is uncertain or unavailable?
  • Who owns monitoring and incident response?
  • When will the system be reviewed or retired?

Challenges and Limitations

AI evaluation is limited by imperfect labels, changing environments, hidden confounders, incomplete subgroup data, and the difficulty of measuring social impact. Benchmark performance may not predict real-world usefulness. Explainability methods may provide plausible but non-causal accounts. Privacy protections can reduce utility, while excessive data collection creates additional risk. Cloud scalability does not guarantee economic sustainability, and automation can shift rather than remove human work.

Consequently, responsible AI engineering is an iterative socio-technical process. It combines quantitative testing with domain knowledge, user research, governance, security review, and continuous observation.

Contemporary Developments and Best Practices

Current practice increasingly emphasizes foundation-model evaluation, retrieval-augmented generation, model and data cards, software supply-chain security, confidential computing, automated policy checks, and evaluation of AI agents that use tools. These developments increase the need for traceability because a system may combine changing prompts, retrieved documents, external tools, and multiple models.

Best practices include:

  • define success and failure before training;
  • use task-appropriate metrics and report uncertainty where possible;
  • maintain representative, leakage-resistant evaluation sets;
  • evaluate important subgroups and realistic stress conditions;
  • separate development, validation, and final testing;
  • version data, code, configurations, and models;
  • protect sensitive data throughout the pipeline;
  • deploy gradually with rollback capability;
  • monitor technical, model, business, and social indicators;
  • assign accountable owners; and
  • review, retrain, or retire systems as conditions change.

Chapter Summary

AI evaluation concerns more than predictive accuracy. Classification tasks require appropriate attention to precision, recall, specificity, thresholds, imbalance, and error costs; regression requires measures such as MAE, MSE, and RMSE interpreted in context. Data quality, leakage, representative sampling, and label validity determine whether evaluation results are trustworthy. Robustness, fairness, explainability, privacy, and security address whether a system is dependable and acceptable in practice.

Production AI is a socio-technical architecture containing data pipelines, storage, training, model registries, APIs, applications, cloud infrastructure, monitoring, and human oversight. MLOps provides reproducible lifecycle practices for deployment, observability, controlled change, incident response, and retirement. The central professional principle is that a model should be judged by its real-world purpose, risks, operating conditions, and impact—not by one isolated benchmark score.

Key Terms

Accuracy: Proportion of all predictions that are correct.

API: Interface through which software components exchange requests and responses.

Calibration: Agreement between predicted probabilities and observed outcome frequencies.

Class imbalance: Unequal prevalence of classes in a dataset.

Confusion matrix: Table of true and false positive and negative classifications.

Data leakage: Use of information unavailable at prediction time in training or evaluation.

Drift: Change in data, relationships, or model behavior over time.

Explainability: Ability to provide understandable accounts of model behavior or outputs.

F1 score: Harmonic mean of precision and recall.

False negative: Positive case incorrectly predicted as negative.

False positive: Negative case incorrectly predicted as positive.

MLOps: Practices for developing, deploying, monitoring, and governing machine-learning systems.

Model registry: Controlled repository of models, versions, metadata, and evaluation evidence.

Precision: Proportion of predicted positives that are truly positive.

Recall: Proportion of actual positives that are detected.

Robustness: Ability to maintain acceptable behavior under plausible variation or attack.

Shadow deployment: Live testing of a model without allowing it to affect decisions.

Specificity: Proportion of actual negatives correctly rejected.

Threshold: Cutoff used to convert a score or probability into a decision.

Distribution shift: Change between training conditions and deployment conditions.

Review Questions

Short Answer Questions

1. Why can accuracy be misleading for an imbalanced classification problem?

2. Distinguish precision from recall.

3. What is data leakage? Give one example.

4. Name three categories of monitoring used in production AI.

5. Why is model versioning important in MLOps?

Long Answer Questions

1. Explain how the consequences of false positives and false negatives should influence metric and threshold selection.

2. Describe a production AI architecture from data ingestion through monitoring.

3. Discuss the relationship among robustness, fairness, explainability, privacy, and security.

4. Explain how a model registry, continuous integration, and controlled deployment support reliable MLOps.

5. Discuss why offline benchmark performance may fail to predict real-world AI impact.

Analytical / Application Questions

1. A medical screening model has high recall but low precision. Analyze when this may be acceptable and propose operational safeguards.

2. Design an evaluation and monitoring plan for an AI system that detects fraudulent insurance claims, including data-quality checks, metrics, drift indicators, and human review.

3. A new model improves accuracy by 2 percentage points but increases latency, cost, and error disparity between demographic groups. Recommend whether it should be deployed and justify your decision using technical and governance considerations.

Multiple Choice Questions with Answers

Question 1

Which metric measures the proportion of predicted positive cases that are actually positive?

A. Recall

B. Precision

C. Specificity

D. Accuracy

Correct Answer: B. Precision

Question 2

A dataset contains 40 true positives, 20 false positives, 10 false negatives, and 930 true negatives. What is the recall?

A. 66.7%

B. 72.7%

C. 80%

D. 97%

Correct Answer: C. 80%

Question 3

Which practice most directly prevents leakage from duplicated applicants appearing in both training and test data?

A. Increasing the classification threshold

B. Using applicant-level grouping during splitting

C. Adding more model layers

D. Reporting only accuracy

Correct Answer: B. Using applicant-level grouping during splitting

Question 4

Which metric is expressed in the same units as the regression target and treats errors linearly?

A. MAE

B. MSE

C. ROC-AUC

D. F1 score

Correct Answer: A. MAE

Question 5

What is the primary purpose of a model registry?

A. To replace all human review

B. To store only raw user passwords

C. To manage model versions and associated metadata

D. To increase class imbalance

Correct Answer: C. To manage model versions and associated metadata

Question 6

In a shadow deployment, the new model:

A. Receives live inputs but does not affect decisions

B. Serves all users immediately

C. Is used only on historical data

D. Is permanently disabled

Correct Answer: A. Receives live inputs but does not affect decisions

Question 7

Which statement about lowering a binary classification threshold is generally correct?

A. It always increases both precision and recall

B. It generally increases recall while potentially reducing precision

C. It has no effect on predictions

D. It guarantees perfect calibration

Correct Answer: B. It generally increases recall while potentially reducing precision

Question 8

Which is an example of data drift?

A. A change in the distribution of incoming features

B. A documented API version

C. A fixed model hash

D. A completed code review

Correct Answer: A. A change in the distribution of incoming features

Question 9

Why may precision–recall curves be especially informative for rare-event detection?

A. They ignore all positive cases

B. They focus on performance involving positive predictions and actual positives

C. They measure deployment latency directly

D. They eliminate the need for labels

Correct Answer: B. They focus on performance involving positive predictions and actual positives

Question 10

Which control most directly helps limit unauthorized use of an online inference API?

A. Data duplication

B. Authentication and authorization

C. Removing monitoring

D. Increasing RMSE

Correct Answer: B. Authentication and authorization

Introduction to Artificial Intelligence
Chapter 13 of 15