AIML · Lecture 08 · Introduction to machine learning · Part 2Course homeOpen slide deck  
Artificial Intelligence and Machine Learning · Lecture 08 of 16

Introduction to machine learning · Part 2

Turn the crop-yield task into a dataset and a prediction rule, then assess its performance on new observations.

3 chapters · 26 reading sections · 3 interactive examples · Lecture 08 of 16. Formulating a regression task.

Bridge from Part 1Now make the prediction task precise

A predictor is an input used to make a prediction; the outcome or target is what we want to predict. For the crop-yield task, fertilizer level is the predictor and crop yield is the outcome. These roles will be used before introducing their mathematical notation.

Part 1 compared learning settings and application domains. Here we focus on one chosen task: supervised regression for crop yield. The shared example provides continuity; the new material explains how to record observations, define candidate functions and assess predictions.

We will not reclassify the learning settings. Instead, we move from an informal task to a dataset, a prediction function, a model family and a procedure for evaluating new cases.

Our starting point

Known fertilizer level
Predict crop yield

We have chosen a supervised regression task.

The next questions

How is one observation recorded?

Which prediction functions may we use?

How do we judge their predictions?

Predictor: an input used to make a prediction. Here: fertilizer level.Outcome (target): what we want to predict. Here: crop yield.

Lecture mapFormulating a regression task: three chapters

This lecture formulates a regression task through three chapters: Variables and datasets, Models and hypotheses, and Generalization. Data splitting, model selection and leakage are practical parts of evaluating generalization.

1 · Variables and datasets

Collect variables and outcomes, then organize their measured values.

1.1One observation is one field trial

An observation in the fertilizer example is one field trial: one field receives a recorded fertilizer level, and its yield is measured later. A dataset row joins those values for the same trial. This identifies the unit of observation before introducing formulas.

The fertilizer example contains 25 trials and one predictor. Its physical dosage and yield units are not specified. Later, a clearly marked two-predictor toy example adds measured soil moisture to illustrate vectors and matrices; it is separate from the 25 fertilizer observations.

The symbol i numbers field trials. The value xᵢ is the fertilizer measurement for trial i, and yᵢ is that trial’s measured yield. The fertilizer measurements use an illustrative scale with unspecified physical units.

A golden wheat field
One field trial: record fertilizer level, then measure the crop yield.

One row in the fertilizer example

Trial iFertilizer xᵢYield yᵢ
10.00001.9200

Here fertilizer is the predictor (input); yield is the outcome (target).

i = field-trial number; xᵢ = its fertilizer value; yᵢ = its measured yield.The 25 fertilizer observations use an illustrative scale; physical units are unspecified.

1.2Variables name quantities; indexed values name records

Uppercase symbols name variables shared across trials: X₁ is fertilizer level, X₂ is measured soil moisture, and Y is crop yield. This small two-predictor toy example is separate from the 25 fertilizer observations, which have only fertilizer as a predictor. It is reused later to explain vectors and matrices.

For trial 2, the fertilizer value is 0.6 and the soil-moisture value is 0.5. We write x₂₁ = 0.6 and x₂₂ = 0.5. The first index, i = 2, selects trial 2; the second index, j = 1 or j = 2, selects the predictor. Keeping i fixed and changing j moves across the input columns of the same row.

The outcome for that trial is y₂ = 1.1. Because this task has one outcome, its recorded value needs only the trial index. In general, xᵢⱼ records predictor j in trial i, while yᵢ records the target for that trial.

Toy example: three field trials

Trial
i
Fertilizer
X₁
Soil moisture
X₂
Yield
Y
10.20.40.8
20.60.51.1
30.90.30.7

X₁ and X₂ name the inputs; Y names the outcome.

Read values from trial 2

x21 = 0.6Trial 2, predictor 1: fertilizer.
x22 = 0.5Trial 2, predictor 2: soil moisture.

y₂ = 1.1: the measured yield of trial 2.

First index i: choose the trial (row).Second index j: choose the predictor (input column).Uppercase X₁, X₂ and Y name variables.Lowercase xᵢⱼ and yᵢ record values for one trial.These are toy values for notation. The 25-trial dataset uses fertilizer as its only predictor.

1.3Variable types: magnitudes and categories

A variable is a feature recorded across experiments when possible. Examples include age, number of owned cars, hair colour and recorded sex categories. The table explains the variable types and gives examples of each.

TypeMeaning and examples
QuantitativeNumerical magnitudes, such as age, patient height and average daily temperature.
ContinuousValues in a continuous set, such as height or average daily temperature.
DiscreteSeparate values, such as the number of owned cars or age recorded in whole years.
Categorical / nominalCategories fixed by the task, such as hair colour, country or employment status. Nominal category order carries no meaning.
Binary nominalTwo unordered labels, such as employed/unemployed, often stored as 0/1.
OrdinalOrdered labels, such as survey responses 0=don’t like, 1=like, 2=love; or qualification status 0=without a degree, 1=with a degree. The second example is also binary. Codes alone do not establish equal spacing.

The measurement or encoding determines the type. Age may be treated continuously or recorded in whole years. Binary describes two categories and can overlap with an ordered scheme; 0/1 category codes do not by themselves make a task quantitative. Ordinal codes do not imply equal spacing.

A type tree: quantitative variables can be continuous or discrete; categorical variables can be nominal, ordinal or binary.
Continuous: values along a continuum.Discrete: separate quantitative values.Nominal: categories without a natural order.Ordinal: ordered categories, without equal spacing.Binary: two categories; these may also be ordered.

1.4Predictors are inputs; the outcome is the target

This formulation predicts one outcome Y from one or more predictors X₁, …, Xₘ; m is their number. A predictor is an input variable, also called a feature, independent variable or explanatory variable. The outcome is the output to predict, also called target, dependent/predicted variable or response.

These names describe task roles and may refer to a variable or its recorded measurement in context. “Independent” does not establish statistical independence, and “explanatory” does not establish causation. A proposed predictor may turn out to have no useful relationship with the outcome.

Inputs must be available at prediction time. Soil moisture measured before planting could be used to predict yield. Future realized rainfall would not be available for a prediction made beforehand; a forecast is a different input.

Predictors X₁, …, XₘAvailable when we predict
ModelUses the predictor values
Outcome YThe quantity to estimate
X₁: fertilizer    →    Y: yield
X₁, …, Xₘ = predictor variables; m = their number.Y = outcome variable, also called target or response.Predictor, input and feature describe the same role here.The name “independent variable” does not establish independence or causation.

1.5Collect the observed input–target pairs

The supervised dataset 𝓓={(xi,yi)}i=1n is a collection of n recorded input–target pairs. Here i identifies a trial, xᵢ records its input and yᵢ its target. With one predictor, xᵢ can be displayed as a single number; with several predictors it will be a vector.

The fertilizer example contains n = 25 observations and m = 1 predictor. The table displays its first three rows, rounded to four decimal places. The observations example at the start of Models and hypotheses retains all 25 observations.

Trial iFertilizer xᵢYield yᵢ
10.00001.9200
20.04171.7144
30.08332.0449
𝓓={(xi,yi)}i=1n
𝓓 = dataset containing n input–target pairs.i = observation number, from 1 to n.xᵢ = recorded input; yᵢ = recorded target.Here n = 25 observations and m = 1 predictor.

1.6Domains contain values; input spaces contain combinations

The domain 𝓧ⱼ is the set of values allowed for predictor Xⱼ. The outcome domain is 𝓨. For quantitative regression, 𝓨 is typically a subset of the real numbers ℝ; for classification it is a finite set of class labels.

The full input space is the Cartesian product 𝓧 = 𝓧₁ × ··· × 𝓧ₘ. Here × means that we form tuples by choosing one value from each domain; it is not multiplication of measured values. With fertilizer and soil moisture as predictors, one input is a pair consisting of one fertilizer value and one moisture value.

The notation x ∈ 𝓧 means that x belongs to the input space. A space describes possible cases; a dataset contains only the particular cases we recorded. A suitable encoding is needed before categorical, image or text inputs can be used in a numerical design matrix.

In the diagram, three allowed fertilizer values and three moisture values give 3 × 3 = 9 possible input pairs. The three recorded toy observations occupy only three of those combinations.

A separate two-predictor toy example

𝓧₁ = {0.2, 0.6, 0.9}
𝓧₂ = {0.3, 0.4, 0.5}

Example domains for fertilizer and measured soil moisture.

𝓧 = 𝓧₁ × 𝓧₂
The Cartesian product combines each of three fertilizer values with each of three soil-moisture values, giving nine possible input pairs.
X₁ = fertilizer; X₂ = measured soil moisture.𝓧ⱼ = allowed values for predictor Xⱼ; j identifies it.𝓧 = input space; 𝓨 = allowed outcome values.× forms every possible tuple; ∈ means “belongs to”.The 3 × 3 domain combinations give 9 possible inputs; they need not all be observed.

1.7One input vector collects one value per predictor

Observation i consists of an input vector xᵢ and, in supervised training data, a target value yᵢ. The vector xᵢ = (xᵢ₁, …, xᵢₘ)ᵀ collects one value for each of the m predictors. The superscript T denotes transpose; we use it here to write the listed values as a column vector.

For an illustrative two-predictor example, let x₁ = (0.2, 0.4)ᵀ and y₁ = 0.8. The first input entry is fertilizer level and the second is soil moisture; the target is yield. These toy values illustrate vector and matrix notation. They are separate from the 25-observation fertilizer plot, which has only one predictor.

In xᵢⱼ, i identifies the observation and j identifies the predictor. The notation xᵢ ∈ 𝓧 and yᵢ ∈ 𝓨 states that recorded inputs and targets belong to their respective spaces.

In this notation, xᵢ is the observation or input data point, and xᵢⱼ ∈ 𝓧ⱼ records predictor j in analysis i. The target yᵢ ∈ 𝓨 is the outcome measurement for the same analysis. The terms observation or data point may also refer to the complete pair (xᵢ,yᵢ); here input vector and input–target pair make that distinction explicit. A dataset may contain survey answers, images or text as well as numerical measurements.

A separate two-predictor toy example

RecordFertilizerSoil moistureYield
10.20.40.8
20.60.51.1
30.90.30.7

Read the first record as a column

x₁ = (0.2, 0.4)ᵀ
y₁ = 0.8

Fertilizer first, soil moisture second.

xᵢ = (xᵢ₁, …, xᵢₘ)ᵀ ∈ 𝓧
xᵢⱼ ∈ 𝓧ⱼ,   yᵢ ∈ 𝓨
xᵢ = observation / input data point; yᵢ = its target.xᵢⱼ = measurement of predictor j; m = predictor count.𝓧ⱼ = predictor j’s domain; 𝓧 = full input space.𝓨 = outcome domain; ᵀ writes the entries as a column.

1.8A design matrix stores input rows; a vector stores targets

The design matrix X stores input observations as rows and predictors as columns. For n observations and m numerical predictors, X ∈ ℝn×m. Entry Xᵢⱼ is predictor j in observation i. Since xᵢ is a column vector, row i of the matrix is xiT.

The target vector Y = (y₁, …, yₙ)ᵀ has one entry for each row. In the three-row toy example, the input matrix has rows (0.2, 0.4), (0.6, 0.5), (0.9, 0.3), and the target vector is (0.8, 1.1, 0.7)ᵀ. It has n = 3 and m = 2, whereas the fertilizer chart has one predictor.

Bold X names the whole matrix; Xⱼ names a predictor variable; xᵢ names an observed input vector. Bold Y names the vector of recorded targets, while Y names the outcome variable and yᵢ one recorded target. Matrix notation assumes suitable numerical representations: raw text, images or categories may need encoding.

Design matrix: bold X

X = 0.20.40.60.50.90.3

Toy inputs: fertilizer, then soil moisture; one row per trial.

Target vector: bold Y

Y = (0.8, 1.1, 0.7)ᵀ

Measured yield for each trial, in the same row order.

X ∈ ℝn×m, Y ∈ ℝⁿ
Row i of X is xiT; the target in row i is yᵢ.
n = number of observations; m = number of predictors.i = row number; j = predictor-column number.xᵢ = input column vector; ᵀ transposes it into a row.Bold X stores inputs; bold Y stores the target values.ℝ = real numbers; ℝn×m means n rows and m columns.Xⱼ names a predictor variable; its values fill column j.

1.9General matrix notation: n rows and m predictors

The worked numerical matrix is an instance of this general formula. Stack one input row for every observation to form the matrix X, and place the corresponding target values in the same order in Y. Entry xᵢⱼ is predictor j in observation i. The displayed ellipses continue that pattern up to row n and predictor m.

Since xᵢ = (xᵢ₁, …, xᵢₘ)ᵀ is defined as a column vector, row i of X is xiT. The transpose turns the input column vector into a matrix row. X ∈ ℝⁿˣᵐ has n rows and m columns; Y = (y₁, …, yₙ)ᵀ ∈ ℝⁿ has n matching targets.

The input matrix repeats the row pattern

X=x1T⋮xnT=x₁₁…x₁ₘ⋮⋱⋮xₙ₁…xₙₘ

X ∈ ℝn×m: n rows and m predictor columns.

The target vector follows the same order

Y=y₁⋮yₙ

Y ∈ ℝⁿ: one target for each input row.

n = observations; m = predictors; ℝ = real numbers.xᵢ = input column vector; xiT = row i of bold X.xᵢⱼ = predictor j’s measured value in observation i.yᵢ = recorded target for that same observation.The ellipsis … and vertical dots ⋮ mean “continue the same pattern”; ⋱ continues it diagonally.

2 · Models and hypotheses

Inspect the observations, choose a function form and fit its parameters.

2.1Inspect the fertilizer observations

Inspect the 25 fertilizer/yield observations. Hover over a point or choose its observation number to read its values. Drag to zoom, switch to Pan to move through the chart, and use Reset view to restore the full range.

Each point is one input–target pair. The horizontal position is the fertilizer input and the vertical position is the recorded yield. This fertilizer plot has n = 25 observations and m = 1 predictor; the earlier two-predictor matrix was a separate notation example.

Interactive example · Inspect the fertilizer observations
Initial state of the interactive example: Inspect the fertilizer observations
Change the controls and inspect the result. The example pauses when you move away.

2.2Training fits predictions to recorded targets

Plotting the collected measurements reveals a possible curved relationship. Model training searches for a convincing prediction function that fits those recorded pairs. The assumed model restricts its possible form, such as a polynomial family. Model can also mean the fitted function after training.

A function f: 𝓧 → 𝓨 maps an input xᵢ to a prediction ŷᵢ = f(xᵢ). Its prediction should be approximately equal to the corresponding measured target yᵢ for recorded pairs (xᵢ,yᵢ) in the dataset 𝓓. The hat marks a prediction, ∈ means belongs to, and ≈ means approximately equal. The complete fitting equation is shown below.

The task is regression because the outcome is a quantitative magnitude. Approximate fit is expected: measurements need not lie exactly on one curve. The next step fixes a function form and identifies the parameters that training can change.

xᵢ ∈ 𝓧Recorded predictor values
f: 𝓧 → 𝓨The prediction rule
ŷᵢ ∈ 𝓨Predicted target
yᵢ ≈ ŷᵢ = f(xᵢ),   (xᵢ, yᵢ) ∈ 𝓓
𝓓 = recorded input–target pairs; i = record index.xᵢ = input; yᵢ = observed target; ŷᵢ = its prediction.f: 𝓧 → 𝓨 maps inputs to predicted outcomes.≈ means approximately equal; ∈ means belongs to.Model training searches for a function f that fits the collected data. The chosen model restricts its possible shape.

2.3A model fixes a form; a hypothesis chooses its parameters

Following the course convention, a model is an assumed function form. Once that form is fixed, a hypothesis θ is one numerical parameter setting, and the hypothesis space Θ is the set of allowed settings. The corresponding prediction rule is written fθ; the parameters need the assumed form to determine that function.

For the illustrative family fθ(x) = ax² + bx + c, θ = (a,b,c). Here x is one numerical input, a multiplies the squared term, b multiplies the linear term, and c is the intercept: the prediction at x = 0. The three curves illustrate three different coefficient choices in the same family.

Training changes coefficients within the selected form. Choosing another maximum polynomial degree changes the model family. Because Θ = ℝ³ permits a = 0, the displayed family contains polynomials of degree at most two, including linear and constant special cases.

The course’s supplied example curve is explored separately. Its model family and fitting algorithm are not specified, so it is not asserted to be quadratic or an optimal fit.

Polynomial family: degree at most 2

fθ(x) = ax² + bx + c
θ = (a, b, c)

Keep this form fixed. A hypothesis θ chooses numerical values for a, b and c.

Three quadratic-family curves with coefficient triples (1,0,0), (2,-1,0.5), and (0.5,1,0).
x = one numerical input; fθ(x) = predicted output.a = squared-term coefficient; b = linear coefficient.c = intercept: the prediction when x = 0.θ (theta) = the coefficient tuple (a, b, c).Course convention: θ is a hypothesis within a fixed function form; fθ is the corresponding prediction rule.

2.4A hypothesis space contains the allowed choices

The parameter setting θ selects one candidate function. The hypothesis space Θ is the set of allowed parameter settings, following the parameter-based convention used in the course. In the unrestricted quadratic example, Θ = ℝ³: every triple (a, b, c) of real coefficients is allowed.

For θ = (1, 0, 0), the selected function is fθ(x) = x². For θ = (2, −1, 0.5), it is fθ(x) = 2x² − x + 0.5. Both choices belong to the same space Θ and use the same functional form.

Another common convention calls the functions themselves hypotheses and calls their set the hypothesis space. Here θ names the coefficients and fθ names the corresponding function, so the distinction stays explicit. Fitting chooses a θ; model selection can compare families or complexity settings.

All allowed choices: Θ

Θ = ℝ³

Every real triple (a, b, c) is allowed in this quadratic family.

One selected choice: θ

θ = (1, 0, 0) ∈ Θfθ(x) = x²

This tuple selects one candidate function.

θ = one coefficient tuple (a, b, c).Θ (capital theta) = all allowed coefficient tuples.ℝ³ = triples of real numbers; ∈ means “belongs to”.x = numerical input; fθ(x) = its prediction.For this family, fθ(x) = ax² + bx + c; a, b and c are the fitted coefficients.

3 · Generalization

Inspect the fitted curve, quantify disagreement, then test predictions beyond the recorded data.

3.1Compare the observations and hypothesis

The plot overlays the fertilizer observations and an illustrative hypothesis curve. Toggle traces with the legend or select an observation to compare its target yᵢ with the curve’s prediction ŷᵢ. Their vertical difference is the residual, yᵢ − ŷᵢ.

This supplied curve illustrates a candidate hypothesis; it is not asserted to be quadratic or an optimal fit. The following sections first discuss the gaps, then introduce mean squared error as one numerical way to assess disagreement when a visual comparison is insufficient.

Interactive example · Compare the observations and hypothesis
Initial state of the interactive example: Compare the observations and hypothesis
Change the controls and inspect the result. The example pauses when you move away.

3.2Why does the curve miss some observed points?

The diagram zooms the same fertilizer measurements. Blue dots are measured yields and the purple line is the supplied curve. At fertilizer level 0.25, the measured yield is 2.225 while the curve predicts 2.475. The highlighted vertical segment compares these two values at the same input. Other points lie above or below the curve, so the curve captures an overall trend without passing through every observation.

The illustrative curve follows the overall trend but misses individual measurements. This discrepancy motivates two questions: could another hypothesis fit the recorded data better, and how can fit be judged when a visual plot is impractical, for example with many predictors?

Measurement error can contribute to these gaps. Unrecorded soil, weather or other conditions can also change yields, and the chosen model may miss part of the relationship. A visible disagreement alone does not identify its cause.

Fitting should capture a useful relationship despite fluctuations in the observations. Passing through every training point can reproduce accidental variation. The next slide defines residuals and MSE as one concrete way to measure disagreement before considering performance on new cases.

Zoom of the fertilizer observations and illustrative curve. At fertilizer level 0.25, the measured yield is 2.225 and the curve prediction is 2.475; the vertical gap is highlighted.

A convincing curve raises two questions

Could another hypothesis fit these observations better?

How can we measure fit when a plot is impractical, for example with many predictors?

Read each gap vertically: measured yield versus the curve prediction at the same fertilizer level.Gaps can reflect measurement noise, unrecorded conditions or model mismatch.

3.3A residual is the gap between observation and prediction

The prediction for observation i is ŷᵢ = fθ(xᵢ). Its residual is rᵢ = yᵢ − ŷᵢ, the observed target minus the prediction. A positive residual means the model predicted too low; a negative one means it predicted too high.

Mean squared error (MSE) averages the squared residuals over n observations: MSE=1n∑i=1n(yi−ŷi)2. The summation symbol ∑ means add the terms for i = 1 through n. Squaring prevents positive and negative residuals from cancelling and gives larger disagreements more weight.

MSE is one concrete score for regression, used here as a bridge to the regression lecture. Its units are squared target units. A lower training MSE means a closer fit to these recorded targets, not necessarily more accurate predictions on new cases.

At the same input, an observed target of 4 and a prediction of 3 give a vertical residual of 1.

From one gap to an average score

rᵢ = yᵢ − ŷᵢ

Observed minus predicted.

MSE=1n∑i=1nri2

Square the gaps, add them and divide by n.

yᵢ = observed target; ŷᵢ = predicted target.rᵢ = residual: observed minus predicted.i = record number; n = number scored; xᵢ = its input.MSE = mean squared error; ∑ adds the n squared residuals.MSE has squared target units. Low training MSE alone does not establish good new predictions.

3.4Generalization means predicting relevant new cases

A prediction function should work beyond the recorded pairs in 𝓓, on relevant unseen cases in the input and outcome domains. Generalization means predicting the outcome of relevant unseen inputs, rather than only explaining the measurements used to fit the function.

In the displayed new-case formula, x is an input and y is its associated outcome; ŷ = fθ(x) is the fitted rule’s prediction. The pair belongs to 𝓧 × 𝓨 because these are its input and outcome domains. This membership specifies the possible types of pairs. It does not require fitting every arbitrary pairing of an input with an unrelated outcome.

With noisy outcomes, approximate agreement on useful new cases is the aim. A small training error is not sufficient evidence of this. Held-out observations estimate performance for the intended future use; the following practical sections separate fitting, model choice and final assessment.

Training observations are used to fit a rule; different new observations check its predictions.
Recorded data: yᵢ ≈ ŷᵢ = fθ(xᵢ),   (xᵢ, yᵢ) ∈ 𝓓New cases: y ≈ ŷ = fθ(x),   (x, y) ∈ 𝓧 × 𝓨
𝓓 = training input–target pairs; i = record index.𝓧 = input space; 𝓨 = outcome domain.x = an input; y = its associated outcome; ŷ = prediction.fθ = prediction rule with fitted parameters θ.𝓧 × 𝓨 contains possible input–outcome pairs.The goal is useful predictions for relevant unseen cases. Noise can prevent exact agreement.

3.5Training, validation and test sets have different jobs

A training set is used to fit model parameters and any learned preprocessing. A validation set is held out from that fitting step and used to compare development choices, such as polynomial degree. A test set is reserved for estimating performance after those choices are fixed.

Repeatedly choosing models from test results makes the test set part of development. It can then give an optimistic estimate of performance. The validation set serves that development role so that a separate test can remain a final assessment.

The split should match the intended use. To predict later dates, hold out later observations. To predict on new fields or people, keep the relevant groups separate. A random row split may be inappropriate when related records appear in both sets.

The illustration assigns 30 of 50 observations to training, 10 to validation and 10 to testing: a 60/20/20 split. The block widths and dot counts show the same proportions. Training commonly receives the largest share, but there is no mandatory ratio; the split should leave enough evidence for fitting, model selection and a meaningful final evaluation.

Illustrative 60/20/20 split: 30 training observations in the largest block, 10 validation observations and 10 test observations. Every dot represents one observation.
Training set: fit adjustable model settings and input transformations.Validation set: compare choices such as model complexity.Test set: assess the final selected procedure.Hold out later dates or different groups when those match the intended use.

3.6Fit the training points; compare unseen validation points

Choose a polynomial degree and noise level. The model is fitted using 16 training points; its validation score uses 40 separate points generated from the same synthetic process. The true (generating) curve is the known rule used by this simulator: y = 2 + 1.2x − 0.9x². Each dot is a value on that curve plus random noise. Choose Show true curve to reveal it. The fitted curve is instead learned from the training dots; the fitting method is not given the true rule. We can reveal that rule here because the data are artificial; with real data it is usually unknown.

Compare training and validation errors as degree increases. A more flexible family can lower training error while failing to improve, or worsening, validation error. This is the overfitting pattern: fitting details of the sample that do not transfer to new observations. A degree-9 polynomial has more flexibility than degree 2, but need not pass through all 16 training points.

Noise is random variation added to the generated targets. The seed makes a chosen dataset repeatable. Because you use validation results to compare degrees, those points are a development resource, not a final untouched test set. A later test would assess the selected procedure on further held-out observations.

The control σ (sigma) is the standard deviation of the added noise: a larger value produces more variation around the generating curve. Keeping the same seed repeats the sample so that model comparisons can use the same observations.

Here x is a synthetic numerical input and y is its outcome. Polynomial degree is the highest power allowed in the fitted function. The symbol σ (sigma) is the standard deviation controlling the simulated noise. MSE means mean squared error. A seed repeats the same sampled data.

Interactive example · Fit the training points; compare unseen validation points
Initial state of the interactive example: Fit the training points; compare unseen validation points
Change the controls and inspect the result. The example pauses when you move away.

3.7Data leakage lets evaluation information enter preparation

Data leakage occurs when information unavailable in the intended prediction setting influences model development or evaluation. It can enter through input construction, preprocessing or a split that mixes related cases.

For example, computing feature means from all observations before splitting lets held-out inputs influence preprocessing, even if their target labels are never used. Estimate such preprocessing from the training data, then apply the fitted transformation to validation and test inputs.

Also inspect time and group relationships. If the goal is to predict future months for new fields, evaluation should hold out later dates and relevant fields. Merely hiding individual rows can leave closely related records available during training. Decide the deployment question before choosing the split.

Preprocessing transforms the inputs before fitting or prediction, such as subtracting a feature mean learned from data. Fit these learned quantities on training observations only and apply the same transformation to held-out observations.

Computing preprocessing from all rows before splitting leaks evaluation inputs; split first, fit preprocessing on training only, then apply it to held-out inputs.
Preprocessing transforms inputs before prediction, for example by subtracting a learned mean. Fit that transformation on training data, then apply it unchanged to held-out inputs.

3.8Use the notation to reason about four cases

These cases apply the notation and evaluation concepts introduced in Part 2. They concern the shape of input data, membership in a parameter space, the interpretation and units of residuals, and a split that matches deployment.

State the definition you use, then apply it to the case. The following worked answers explain the reasoning rather than only giving a number.

1 · Data

80 trials have four predictors, a lookup ID and a target. What is the shape of X? Does the ID belong in it?

2 · Model

Changing θ from (1,0,0) to (2,−1,0.5) changes signs. Does it require a different quadratic family?

3 · Error

In a toy case, observed yield is 4 kg and prediction is 6 kg. What does the residual mean? What units does its square have?

4 · Evaluation

Predict later months for fields never used in training. Which dates and field identities should be held out?

Bold X = input matrix; θ = coefficient tuple (a, b, c).Residual = observed target minus predicted target.Use the definitions to justify each answer; a lookup ID is not automatically an input.

3.9Reason from the definition, then apply it

With 80 observations and four predictor columns, the design matrix has shape 80 × 4 and the target vector has 80 entries. The lookup ID is not an input merely because it is stored alongside the measurements.

Both (1,0,0) and (2,−1,0.5) belong to Θ = ℝ³. Fitting a negative coefficient changes the parameter setting without changing the allowed space or quadratic form.

In the toy yield case the residual is observed minus predicted: 4 − 6 = −2 kg. A negative residual means overprediction. Its square is 4 kg², illustrating why mean squared error has squared target units.

For future months and unseen fields, the held-out data should be later in time and contain different field identities. A row shuffle alone does not enforce either requirement.

1 · Four predictor columns

X is 80 × 4; Y has 80 targets. A lookup ID does not become a predictor just because it is stored.

2 · Same allowed space

Both tuples are in Θ = ℝ³. Negative coefficients are allowed; the functional form stays quadratic.

3 · Overprediction

r = 4 − 6 = −2 kg. The prediction is too high. Squaring gives 4 kg².

4 · Later, different fields

Train on earlier dates from one group of fields; evaluate later dates from other fields.

n = 80 observations; m = 4 predictor columns.θ = coefficient tuple; Θ = allowed tuples; ℝ³ = real triples.Here r = residual, measured minus predicted. The intended use determines the appropriate split.

3.10A complete prediction problem follows this chain

A prediction problem begins with an observation unit, available predictors and an outcome. A dataset records input–target pairs; a matrix and vector organize their values. A model family and allowed parameter space then specify the candidate prediction rules.

Training fits a parameter setting. Validation compares development choices, and a held-out test assesses the selected procedure for the intended future use. The next regression lecture develops specific fitting methods within this framework.

1 · Define the record

What is observed, and which outcome is predicted?

2 · Organize the data

Pairs in 𝓓; predictor rows in X; targets in Y.

3 · Choose candidates

A function family and its allowed parameter space Θ.

4 · Fit parameters

Select θ using training observations.

5 · Compare choices

Use validation evidence for model selection.

6 · Assess the result

Estimate new-case performance on a held-out test.

𝓓 = dataset; bold X = input matrix; bold Y = targets.θ = fitted parameters; Θ = allowed parameter choices.The regression lecture develops fitting methods within this same formulation.

ReferencesSources for the data, notation and evaluation

The scikit-learn guidance provides further examples of preprocessing leakage and evaluation mistakes.

Common pitfalls and data leakage

Prepared from the corresponding AIML lecture deck. Figures and linked source credits are retained. The interactive examples reuse the lecture’s local data and controls. Keep this file in its lecture folder so its local assets remain available.
Continue learning