Filter concepts by levelShowing all levels.

AI Full-Stack · Section 1

AI and Machine Learning Fundamentals — Must Be Strong

Level
beginner
Read
55 min
Concepts
7

The vocabulary every other section in this topic assumes: how AI, ML, deep learning and generative AI nest inside each other; the five learning paradigms and what signal each learns from; the three data roles (train, validation, test) plus inference; features versus labels and parameters versus hyperparameters; the six task types, named by output shape; and the single most important diagnostic in applied ML — reading a train/validation gap to tell overfitting from underfitting, and recognizing when leakage or distribution shift fakes a good score entirely.

What is true here

  1. AI ⊃ ML ⊃ deep learning ⊃ generative AI — nested subsets, not synonyms
  2. Five learning paradigms, distinguished by where the training signal comes from
  3. Train fits the model, validation tunes decisions, test scores once — inference is production use with no label
  4. A train/validation error gap diagnoses overfitting vs underfitting; leakage and shift fake a good score without it
  5. Task types are named by output shape: a number, a label, groups, fewer features, a flag, or an order

What you will be able to do

  • Place any AI system correctly inside the AI/ML/deep learning/generative AI nesting
  • Name the learning paradigm a described system uses, from its training signal
  • Explain why touching the test set during development invalidates it
  • Diagnose overfitting vs underfitting from a train/validation accuracy pair
  • Name the ML task type a business problem maps to, from its output shape

Core vocabulary

The terms and distinctions every later section in this topic — data, features, evaluation, pipelines, deep learning — assumes you already have.

AI, ML, deep learning and generative AI — the nesting

standardbeginner

Artificial intelligence (AI) is the broad goal of building systems that do tasks that normally need human intelligence. Machine learning (ML) is one way to build AI: a program improves at a task by learning patterns from data instead of following hand-written rules.

Think of it as

Think of these terms as nested circles, not a straight line. AI is the outer circle — any system that behaves intelligently, including hand-written rule engines. ML is a smaller circle inside it — systems that learn their rules from data. Deep learning is smaller still — ML using neural networks with many layers. Generative AI is a slice of deep learning that produces new content (text, images, audio) instead of only predicting a label or number. A foundation model is a large model, usually deep learning, trained once on broad data and reused for many tasks — that's a statement about how it was trained, not about its architecture. Discriminative models predict a label or value for an input ('is this email spam?'); 'predictive system' is a looser umbrella term for anything that outputs a forecast, whether or not it uses ML at all.

text
AI
└─ Machine Learning        (learns from data, not hand-written rules)
   └─ Deep Learning        (multi-layer neural networks)
      └─ Generative AI     (produces new content, not just a label)

Foundation model:      trained once on broad data, reused for many tasks
Discriminative model:  predicts a label/value — not generative

The nested terms, with one example each

The nested terms, with one example each
TermDefinesExample
AIAny system performing tasks that normally need human intelligenceA chess engine using hand-written heuristics
Machine learningA system that learns its behavior from data rather than fixed rulesA spam filter trained on labeled emails
Deep learningML using multi-layer neural networksAn image classifier built from convolutional layers
Generative AIDeep learning that produces new contentAn LLM that writes a paragraph
Foundation modelA large model pretrained once on broad data, reused across tasksGPT, Llama, CLIP
Discriminative modelPredicts a label or value for a given inputA model that outputs "spam" or "not spam"

Remember: AI ⊃ ML ⊃ deep learning ⊃ generative AI, each nested inside the last. A foundation model is defined by "trained once, reused everywhere," not by its architecture.

See also: learning paradigms · ml task types

The five learning paradigms

standardbeginner

Learning paradigms differ in what signal a model learns from. Supervised learning learns from labeled examples. Unsupervised learning finds structure with no labels. Self-supervised learning creates its own labels from the data itself. Reinforcement learning learns from trial and error against a reward.

Think of it as

Ask two questions: does the training data come with an answer key, and where did that answer key come from? Supervised: yes, a human wrote it. Unsupervised: no answer key at all — the model groups or compresses the data on its own. Self-supervised: the answer key is manufactured from the data itself — mask a word and ask the model to predict it, no human needed. Semi-supervised sits between supervised and unsupervised: a small human-labeled set plus a much larger unlabeled one. Reinforcement learning is different in kind — there is no fixed dataset, only an agent taking actions in an environment and getting a reward it tries to maximize over time.

text
labels present?
  yes -> every example labeled?      -> Supervised
         only some examples labeled? -> Semi-supervised
  no  -> labels self-generated from the input? -> Self-supervised
         reward from acting, no fixed dataset? -> Reinforcement learning
         otherwise                              -> Unsupervised

Five paradigms, by training signal

Five paradigms, by training signal
ParadigmSignal it learns fromExample task
SupervisedHuman-provided labels on every examplePredict house price from labeled sales data
UnsupervisedNo labels — structure in the data itselfGroup customers into segments by behavior
Semi-supervisedA few labels plus many unlabeled examplesClassify documents: 100 labeled, 10,000 unlabeled
Self-supervisedLabels generated automatically from the inputPredict a masked word in a sentence
Reinforcement learningA reward signal from acting in an environmentLearn a game-playing policy from wins and losses

Remember: Ask: are there labels, and where did they come from? Human-written = supervised. Self-generated from the input = self-supervised. None = unsupervised. A reward from acting, no fixed dataset = reinforcement learning.

See also: taxonomy of ai ml dl · ml task types

Training, validation, testing and inference

standardbeginner

A model's data gets split into three roles. Training data teaches the model. Validation data checks progress and tunes choices like which settings to use. Test data gives one final, honest score after every decision is locked in. Inference is using the finished model on new data in production.

Think of it as

Training, validation and test are three separate slices of data used at three separate moments, and mixing them up is the single most common way a project quietly cheats itself. Training data is what the model's parameters are fit to. Validation data is what you look at while making decisions — which model, which settings — so it's really part of the development loop, not a fully independent check. Test data is touched exactly once, at the end, to report a number nobody used to make any decision. Inference is a fourth, later moment: production data the model has never seen, with no label attached at all — you're asking, not checking.

text
data
 ├─ train (60-80%)      -> fit the model's parameters
 ├─ validation (10-20%) -> tune decisions, compare models
 └─ test (10-20%)       -> one final, honest score

later, in production:
 new, unlabeled input -> inference -> prediction

Remember: Train fits the model, validation guides your decisions, test reports one final honest score, inference is using the model on new, unlabeled data in production.

See also: generalization and the bias variance tradeoff · splitting and stratified sampling

Features, labels, parameters and hyperparameters

standardbeginner

A feature is one measurable input to a model, like a house's square footage. A label (or target) is the answer you want the model to predict, like its sale price. A parameter is a number the model learns during training. A hyperparameter is a setting you choose before training starts, like how many trees a random forest builds.

Think of it as

Features and labels describe your data; parameters and hyperparameters describe your model. Features are what goes in, a label (also called a target) is what should come out — together, one row of features plus its label is one 'example'. Parameters are the numbers training adjusts automatically so predictions match labels; you never set these by hand. Hyperparameters are everything training does NOT adjust — you set them before training starts, and they control how training happens.

text
example = (features, label)
  features: [sqft=1800, bedrooms=3, age=12]
  label:    price=415000

model.parameters      <- learned from many examples
model.hyperparameters <- set by you before training

Where each term comes from

Where each term comes from
TermSet byExample
FeaturePresent in the raw dataSquare footage of a house
Label / targetPresent in the raw data (for supervised learning)Sale price of the house
ParameterLearned automatically during trainingA weight in a linear regression
HyperparameterChosen by you before training startsLearning rate, number of trees

Remember: Features and labels come from your data; parameters and hyperparameters describe your model. Parameters are learned, hyperparameters are chosen.

See also: feature types

Generalization, overfitting and the bias-variance trade-off

corebeginner

Generalization is how well a model performs on data it has never seen, which is the only performance that actually matters. Overfitting means a model memorized the training data instead of the pattern behind it, so it does well in training and badly elsewhere. Underfitting means the model is too simple to capture the pattern at all, so it does badly everywhere, including training.

Think of it as

Every model makes two kinds of error, and they trade off against each other. Bias is error from a model too simple to represent the true pattern — it makes the same kind of mistake everywhere, confidently. Variance is error from a model too sensitive to the specific training data it happened to see — retrain it on a slightly different sample and its predictions swing wildly. A high-bias model underfits: simple, stable, wrong. A high-variance model overfits: complex, unstable, memorized. The two remaining failure modes are different in kind, not degree: data leakage happens when information from outside the legitimate training set — often a peek at the label, or at the future — sneaks into training and inflates every metric you compute; distribution shift happens when production data stops resembling training data, so a model that generalized fine at launch quietly degrades later. Neither shows up as a normal underfit/overfit pattern, which is what makes them dangerous — the validation score looks fine right up until it doesn't.

text
gap = train_error - validation_error

high train error, high val error  -> underfitting (add capacity)
low train error,  high val error  -> overfitting  (simplify, regularize, more data)
low train error,  low val error   -> good fit
low train + val error, but production fails -> suspect leakage or distribution shift

What we're doing: Diagnose three trained models from their train/validation accuracy gap.

diagnose_fit.pypython
results = {
    "model_A": {"train_acc": 0.99, "val_acc": 0.71},
    "model_B": {"train_acc": 0.68, "val_acc": 0.67},
    "model_C": {"train_acc": 0.91, "val_acc": 0.90},
}

for name, r in results.items():
    gap = r["train_acc"] - r["val_acc"]
    if r["train_acc"] < 0.80:
        print(f"{name}: underfitting (train acc too low)")
    elif gap > 0.15:
        print(f"{name}: overfitting (gap = {gap:.2f})")
    else:
        print(f"{name}: good fit (gap = {gap:.2f})")
2
Model A's near-perfect training accuracy next to a 28-point drop on validation is the signature of overfitting — it memorized training examples rather than the pattern behind them.
3
Model B is weak on both sets. A low validation score alone does not say why; the low training score is what rules out overfitting and points at underfitting instead.
4
Model C's small, consistent gap between train and validation is what a well-fit model looks like — neither score is read in isolation.

Why this works: Train and validation accuracy on their own diagnose nothing — it is the gap between them, read alongside the absolute training score, that says whether to simplify the model (overfitting), add capacity or features (underfitting), or look elsewhere entirely (leakage, if even the gap looks fine but production still fails).

Reading a high validation score as proof the model will work in production

Wrong

python
# Model scores 94% on the validation set.
# Ship it.
model.fit(X_train, y_train)
score = model.score(X_val, y_val)  # 0.94
deploy(model)

Better

python
# Check the validation set was never touched by a
# training-time step that saw labels or future data,
# then confirm on a held-out test set the model has
# never influenced any decision from.
assert no_leakage(X_train, X_val)
score = model.score(X_val, y_val)
test_score = model.score(X_test, y_test)  # touched once
if abs(score - test_score) < 0.03:
    deploy(model)

What you see: A model that scored well in validation fails badly in production, or a retrained model’s validation score keeps rising while real-world performance does not — usually because leakage let the model see information (a scaler fit on the whole dataset, a duplicate row split across train/validation) that production input will never have.

Why: A validation score answers 'did this model do well on THIS data,' not 'will it do well on data it hasn't seen yet.' Leakage and distribution shift both produce a validation score that looks trustworthy while being disconnected from real generalization — the only defense is to test the pipeline's boundaries, not just the final number.

Bias-variance tradeoff, from 30 real model fits

Same train/test split, degree 1-15, each point a real np.polyfit() + real measured error

Generated from real data — src/content/_image-generators/teach-bias-variance-tradeoff.py

  • A line chart with two real curves: training error and held-out test error, plotted against polynomial degree 1 to 15.
  • Training error keeps dropping as degree increases — a more complex model always fits the training data better.
  • Test error drops at first, bottoms out at degree 4, then rises again as the model starts overfitting past that point.
  • A dashed line marks degree 4, the real best-generalizing complexity found in this run.

Reading a train/validation error pattern

Reading a train/validation error pattern
SymptomTraining errorValidation errorLikely cause
UnderfittingHighHigh (similar to training)Model too simple / high bias
OverfittingLowHigh (much worse than training)Model too complex / high variance
Good fitLowLow (close to training)Right complexity for the data
LeakageLowLow, but production failsValidation set contaminated with training/label info

Remember: Generalization is the only score that matters. Overfitting = low train error, high validation error (too complex). Underfitting = high error on both (too simple). Bias is systematic error from simplicity; variance is instability from sensitivity to the training sample. Leakage and distribution shift both fake a good validation score without real generalization.

See also: feature target and temporal leakage · classification metrics · training validation testing inference

ML task types, by output shape

standardbeginner

Machine learning tasks are grouped by the shape of their output. Regression predicts a number. Classification predicts a category. Clustering groups similar examples with no predefined categories. Dimensionality reduction compresses many features into fewer. Anomaly detection flags examples that do not fit the pattern. Ranking orders a list by relevance.

Think of it as

The fastest way to name a task is to ask what the output looks like. A single continuous number is regression. One label from a fixed set is classification. Groups with no given labels is clustering. A shorter feature vector, same information, is dimensionality reduction. A flag on rare, unusual points is anomaly detection. An ordered list is ranking. The same dataset can often be framed as more than one of these — predicting an exact house price is regression, but 'is this house overpriced?' is classification on the same data.

text
output is...
  one number            -> regression
  one label, fixed set  -> classification
  groups, no labels     -> clustering
  fewer features         -> dimensionality reduction
  "does this fit?"        -> anomaly detection
  an ordered list         -> ranking

Six task types, by output shape

Six task types, by output shape
TaskOutput shapeExample
RegressionA single continuous numberPredict tomorrow's electricity demand
ClassificationOne label from a fixed setClassify a support ticket as billing/technical/other
ClusteringGroups with no predefined labelsSegment users by browsing behavior
Dimensionality reductionFewer features, same structureCompress 500 sensor readings to 10 components
Anomaly detectionA flag on unusual examplesDetect a fraudulent transaction
RankingAn ordered listOrder search results by relevance

Remember: Name the task from its output shape: a number is regression, a fixed label is classification, groups with no labels is clustering, fewer features is dimensionality reduction, an outlier flag is anomaly detection, an ordered list is ranking.

See also: core supervised model families · clustering methods · ranking metrics

Online vs batch inference, batch vs streaming data

standardbeginner

Online inference answers one request at a time, in real time — a user asks, the model responds immediately. Batch inference scores many examples at once on a schedule, with no one waiting on an individual answer. The same split applies to the data feeding a system: batch data arrives in scheduled chunks, streaming data arrives continuously, one event at a time.

Think of it as

The question to ask is: is someone waiting right now for one answer, or are you processing a pile of examples on a schedule? A live product recommendation while a user browses needs online inference — latency matters, usually under a second. A nightly job that scores every customer for churn risk is batch inference — throughput matters more than latency, and it can take hours. The data-side distinction is the same shape: a daily export file is batch data; a continuous feed of clicks or sensor readings is streaming data. A system can mix them, like a model trained in batch and then deployed for online inference.

text
online inference:  request -> model -> response        (ms-scale, one at a time)
batch inference:   [many rows] -> model -> [many scores]  (scheduled, throughput-focused)

batch data:     daily_export.csv arrives once a day
streaming data: event -> event -> event -> ...  (continuous)

Remember: Online inference: one request, real-time response. Batch inference: many examples scored on a schedule. The same split — scheduled chunks vs continuous events — applies to the data feeding the system.

See also: the ml pipeline stages

Advertisement