MAI cheat sheet
MAI · Keep the key ideas within reach.
Foundations of AI and Machine Learning
Supervised learning minimizes expected loss over labeled pairs (x, y); unsupervised learning models P(x) or finds structure; reinforcement learning maximizes expected discounted return E[Σ γ^t r_t].
Bias-variance decomposition: expected squared error = bias² + variance + irreducible noise; high bias underfits (both train and validation error high), high variance overfits (low train error, high validation error).
Precision = TP/(TP+FP); Recall = TP/(TP+FN); F1 = 2·P·R/(P+R); a model threshold trades precision against recall along the ROC or PR curve.
AUC-ROC equals the probability a random positive outranks a random negative; AUC is threshold-independent, while accuracy is not and is misleading under class imbalance.
Regularization: L2 (ridge) adds λΣw² and shrinks weights smoothly; L1 (lasso) adds λΣ|w| and drives weights to exactly zero, performing feature selection.
Gradient descent update: w ← w − η∇L(w); η too large diverges, η too small converges slowly; stochastic and mini-batch variants trade gradient noise for speed.
No Free Lunch: no algorithm dominates across all problem distributions; model choice must be driven by data size, feature type, and the loss that matters in deployment.
k-fold cross-validation estimates generalization by training on k−1 folds and validating on the held-out fold; stratified folds preserve class proportions for imbalanced targets.
Data Preparation, Feature Engineering, and Model Evaluation
Fit all preprocessing (imputation, scaling, encoding, feature selection) on training folds only; fitting on the full dataset leaks validation information and inflates reported scores.
Standardization z = (x − μ)/σ suits roughly Gaussian features; min-max scaling maps to [0,1] but is sensitive to outliers; robust scaling uses median and IQR.
One-hot encoding for low-cardinality nominals; target or frequency encoding for high-cardinality features, computed inside cross-validation folds to avoid leakage.
Missing data mechanisms: MCAR (missingness independent of values), MAR (explainable by observed variables), MNAR (depends on the unobserved value); MNAR needs explicit modeling or sensitivity analysis.
Data leakage examples: using future timestamps, including the target in a derived feature, or scaling before the train/test split; always use time-ordered splits for temporal data.
Class imbalance: resampling, class weights, or threshold tuning; evaluate with PR-AUC, recall at fixed precision, or cost-weighted confusion-matrix outcomes rather than raw accuracy.
Feature importance from tree ensembles (impurity or permutation) is not causal; correlated features split importance, so permutation importance on held-out data is preferred.
Evaluation protocol must mirror deployment: same population, same label delay, same decision threshold; report confidence intervals via bootstrap for small test sets.
Neural Networks and Deep Learning
A dense layer computes y = σ(Wx + b); stacking nonlinear activations makes the network a universal function approximator given sufficient width.
ReLU (max(0, x)) mitigates vanishing gradients versus sigmoid/tanh; variants LeakyReLU, GELU, and Swish address the dying-ReLU problem.
Backpropagation applies the chain rule to compute gradients layer by layer; automatic differentiation in frameworks implements the same computation graph.
Batch normalization normalizes activations per mini-batch, stabilizing and accelerating training; layer normalization normalizes per sample and is standard in transformers.
Dropout randomly zeroes activations during training as regularization; at inference it is disabled and activations are scaled to preserve expected magnitude.
Convolutional layers exploit local connectivity and weight sharing, giving translation equivariance; pooling reduces spatial resolution and parameter count.
Attention computes softmax(QKᵀ/√d_k)V, weighting input positions by relevance; multi-head attention learns several such weightings in parallel.
Optimizers: SGD with momentum, Adam (adaptive per-parameter learning rates with bias correction), AdamW (decoupled weight decay); learning-rate schedules include warmup and cosine decay.
Generative AI and Large Language Models
Transformer decoder models predict the next token autoregressively; pretraining minimizes cross-entropy over token sequences, then instruction tuning and preference optimization align behavior.
Tokenization uses subword schemes (BPE, WordPiece, SentencePiece); token counts, not word counts, drive context limits and API cost.
Generation is controlled by temperature (scales logits), top-k (restrict to k tokens), top-p/nucleus (smallest set reaching probability p), and repetition penalties.
Retrieval-augmented generation grounds answers in retrieved documents, reducing hallucination and enabling citations; retrieval quality and chunking strategy dominate results.
Embeddings map text to vectors; cosine similarity measures semantic closeness; vector indexes (HNSW, IVF) trade recall for latency at scale.
Fine-tuning adapts weights to a task; parameter-efficient methods (LoRA, adapters) train small added matrices; prompting and RAG require no weight updates.
Hallucination is fluent output unsupported by evidence; mitigations include grounding, constrained decoding, self-consistency checks, and abstention when confidence is low.
Context window limits are in tokens; long contexts increase latency and cost quadratically in attention, so summarization and retrieval often outperform stuffing.
AI Ethics, Safety, and Governance
Fairness metrics conflict: demographic parity (equal positive rates), equalized odds (equal TPR and FPR across groups), and calibration cannot all hold simultaneously except in degenerate cases.
Protected attributes and their proxies (zip code, name, language) can encode discrimination even when the attribute is excluded from features.
Explainability techniques: SHAP (Shapley-value attributions), LIME (local surrogate), permutation importance, and counterfactual explanations; each answers a different question.
Privacy controls: data minimization, de-identification, differential privacy (calibrated noise), federated learning, and consent tracking; k-anonymity alone is vulnerable to linkage attacks.
Safety risks include prompt injection, jailbreaks, data exfiltration, insecure output handling, and model theft; defenses include input/output filtering and least-privilege tool access.
Governance artifacts: model cards, datasheets for datasets, risk registers, audit logs, human-in-the-loop review, and documented approval gates for high-risk use cases.
Regulatory landscape includes the EU AI Act's risk tiers (unacceptable, high, limited, minimal), GDPR data-subject rights, and sector rules; obligations scale with risk and role.
Red teaming probes for harmful, biased, or unsafe behavior before release; findings feed mitigation, monitoring thresholds, and incident response playbooks.
AI Solution Design and Deployment
Frame the business problem as a measurable ML objective with a baseline: define the decision, the label, the loss of errors, and the success metric before modeling.
Build vs. buy: consider data sensitivity, differentiation value, time to market, total cost of ownership, and vendor lock-in for foundation-model APIs.
Serving patterns: batch scoring for periodic needs, real-time REST/gRPC endpoints for interactive use, streaming for event-driven pipelines; latency budgets drive the choice.
Architecture components: feature store, model registry, artifact storage, inference service, API gateway, and observability hooks; version data, code, and model together.
Deployment strategies: shadow (compare without serving), canary (small traffic slice), blue-green (switch and roll back), and A/B testing for causal impact.
Scaling: GPU/accelerator selection depends on model size and throughput; quantization, distillation, batching, and caching reduce inference cost and latency.
Latency budgets decompose into network, preprocessing, inference, and postprocessing; p95 or p99 tail latency, not the mean, determines user experience.
Design for failure: timeouts, fallbacks to simpler models or cached responses, circuit breakers, and graceful degradation when a dependency is unavailable.
AI Operations, Monitoring, and Maintenance
Data drift is a shift in input distribution P(x); concept drift is a shift in P(y|x); label drift is a shift in P(y); each requires different detection and response.
Drift detection methods: population stability index (PSI), Kolmogorov-Smirnov tests, chi-square for categoricals, and embedding-distance metrics for unstructured data.
Monitor service health (latency, error rate, throughput, saturation) and model health (prediction distribution, feature ranges, calibration, business KPI) separately.
Delayed labels require proxy metrics; when ground truth arrives, backfill and compare to detect silent degradation before users notice.
Retraining triggers include drift thresholds, performance decay, scheduled cadence, and upstream data or schema changes; always validate in a shadow period first.
MLOps pipelines automate data validation, training, evaluation gates, registration, deployment, and rollback; reproducibility requires pinned environments and versioned data.
Incident response: detect, triage, contain (roll back or disable), communicate, and conduct a postmortem; log model inputs, outputs, and versions for auditability.
Cost monitoring covers compute, storage, and token/API spend; caching, batching, and right-sizing instances are the main levers.
Business Strategy and AI Project Management
Value estimation: compare expected benefit (revenue lift, cost saved, risk reduced) against total cost of ownership including data, compute, people, and maintenance.
Prioritization frameworks: value versus feasibility matrices, RICE, and cost-of-delay; rank use cases by measurable impact and data readiness.
Project phases: discovery, data feasibility, prototype, pilot, production, and scale; each phase has explicit exit criteria and a go/no-go decision.
Risk register categories: data availability, model performance, regulatory, reputational, vendor, and security; assign owners and mitigations per item.
ROI for AI = (benefit − cost)/cost; include opportunity cost and the ongoing cost of monitoring and retraining, not just build cost.
Stakeholder alignment requires translating model metrics into business metrics (e.g., recall to captured fraud dollars) and agreeing on acceptance thresholds.
Change management: process redesign, user training, and adoption metrics determine realized value; a technically sound model with low adoption returns nothing.
Build an experimentation culture: define hypotheses, run controlled pilots, and measure causal lift against a holdout rather than pre/post comparisons alone.