Math for AI course · Lesson 12 of 180
Two Observations, One Parameter Pair: Systems of Equations for AI
See a system as simultaneous constraints, classify two-line intersections, and recover an affine model’s weight and bias from two observations.
A tiny prediction rule has two unknown parameters:
The first observation says that input produced target . That does not reveal the weight or bias separately. It gives one constraint, , whose parameter pairs form an entire line. A second observation, , gives another line, .
Only one point lies on both lines: . At that point, the same model fits both rows. This shared point is the central idea of a system of linear equations: each equation imposes a constraint, and a solution must pass every constraint at the same time.
By the end of this lesson, you will be able to interpret a system as simultaneous constraints, solve a two-equation system by substitution or subtraction, classify two lines as intersecting, parallel, or coincident, and recover two exact model parameters from two observations.
Learning outcome: Interpret a system as simultaneous constraints and classify its intersections.
This lesson continues Lesson 11: Linear Equations for AI, where one equation became one geometric line and substitution tested whether a point belonged to it. The official Mathematics for Machine Learning companion places systems of linear equations at the opening of linear algebra. Its Section 2.1 connects simultaneous solutions with geometric intersections. The parameter-recovery scenario, derivations, code, visual, and assessments below are original.
One solution must pass two truth tests
Consider two linear equations in the same real unknowns and :
The fixed real numbers and multiply the weight. The fixed real numbers and are the required outputs. The ordered pair is the unknown parameter setting.
The word “simultaneously” prevents a common mistake. The pair solves , but it fails the second equation because . The pair solves , but fails the first because . Each pair fits one row; neither fits the system.
| Candidate | Test | Test | Solves the system? |
|---|---|---|---|
| No | |||
| No | |||
| Yes |
A system is not solved until the same assignment passes every original truth test.
Subtraction isolates what the observations changed
The opening system is
\begin{aligned} w+b&=5, \tag{1}\\ 3w+b&=9. \tag{2} \end{aligned}The two equations contain the same . Subtracting the entire left side of equation (1) from equation (2), and doing the same on the right, removes :
Now substitute into either original equation. Using equation (1),
The subtraction has an AI interpretation. Between the two observations, the input rises by and the output rises by . The bias contributes the same amount to both predictions, so it disappears from the difference. The weight is the output change per unit of input change:
Once the slope-like weight is known, either row reveals the bias. This is an exact two-point fit, not a description of ordinary large-dataset training. Real observations can include noise, and a third row may disagree with the line determined by the first two. Later lessons will develop tools for those cases.
The algebraic answer is the geometric crossing
Each observation can be rearranged as a line in the parameter plane:
This graph is not the usual plot of observed input against target . Its horizontal coordinate is a candidate weight and its vertical coordinate is a candidate bias. Every point on the first line fits observation 1. Every point on the second line fits observation 2. Their crossing at fits both.
Change the second observation below. The solid line remains ; the dashed line becomes . Native sliders expose the second input and target , while the three buttons jump to representative intersection states.
| Quantity | Current value | Interpretation |
|---|---|---|
| Observation 1 constraint | w + b = 5 | Every point on the solid line fits the first observation. |
| Observation 2 constraint | 3w + b = 9 | Every point on the dashed line fits the second observation. |
| Intersection class | One shared point | One solution: the lines meet at weight w = 2 and bias b = 3. |
| Recovered weight w | 2 | This coordinate belongs to the shared solution. |
| Recovered bias b | 3 | This coordinate belongs to the shared solution. |
The component’s first server-rendered state is the worked system: , , and . Its status sentence and table contain the conclusion independently of the SVG and remain useful without JavaScript. The line labels also use solid and dashed patterns, while the intersection has its own circled-plus shape, so color is not the only state cue.
Three pictures exhaust the two-line possibilities
For the family
subtracting the first equation from the second gives
The two differences classify the geometry without requiring matrices.
| Coefficient comparison | Target comparison | Geometry | System solution set |
|---|---|---|---|
| Any values | Intersecting | One point | |
| Parallel | Empty: | ||
| Coincident | The entire shared line |
When , division is legal and produces one weight:
When , the left-side difference is zero. If the targets differ, the subtracted equation becomes with a nonzero right side, a contradiction. If the targets also match, subtraction becomes the identity : the second equation repeats the first and contributes no new restriction.
The next lesson will turn this preview into a systematic study of no, one, and many solutions. For now, the geometric test is enough: crossing lines share one point, distinct parallel lines share none, and coincident lines share all their points.
NumPy verifies the fit and Matplotlib plots the constraints
The calculation can be implemented without hiding it inside a general solver. The function below accepts exactly two observations, handles the repeated-input boundary, and checks any recovered parameters against both original rows.
import numpy as np
import matplotlib.pyplot as plt
def recover_two_parameter_model(x, y, atol=1e-12):
delta_x = x[1] - x[0]
delta_y = y[1] - y[0]
if np.isclose(delta_x, 0.0, rtol=0.0, atol=atol):
if np.isclose(delta_y, 0.0, rtol=0.0, atol=atol):
return "many", None
return "none", None
weight = delta_y / delta_x
bias = y[0] - weight * x[0]
residual = weight * x + bias - y
return "one", (weight, bias, residual)
x = np.array([1.0, 3.0])
y = np.array([5.0, 9.0])
classification, result = recover_two_parameter_model(x, y)
weight, bias, residual = result
print("classification:", classification)
print("weight:", weight)
print("bias:", bias)
print("predictions:", weight * x + bias)
print("residual:", residual)
print(
"both constraints satisfied:",
np.isclose(residual, 0.0, rtol=0.0, atol=1e-12),
)
candidate_weight = np.linspace(-1.0, 5.0, num=121)
bias_from_first = y[0] - x[0] * candidate_weight
bias_from_second = y[1] - x[1] * candidate_weight
plt.plot(candidate_weight, bias_from_first, label="w + b = 5")
plt.plot(
candidate_weight,
bias_from_second,
"--",
label="3w + b = 9",
)
plt.plot([weight], [bias], "o", label="shared solution")
plt.xlabel("weight w")
plt.ylabel("bias b")
plt.legend()
plt.show()
The executed output for the intersecting case is:
classification: one
weight: 2.0
bias: 3.0
predictions: [5. 9.]
residual: [0. 0.]
both constraints satisfied: [ True True]
numpy.isclose
compares numbers using explicit relative and absolute tolerances. Here the
reference value is zero, so rtol=0.0 and atol=1e-12 make the intended
absolute threshold clear. That test checks this floating-point execution; it
does not replace the exact algebraic derivation.
numpy.linspace
returns evenly spaced samples over the chosen interval. The 121 sampled
weights give Matplotlib enough line nodes for a clean plot, but the samples are
not the mathematical solution set. Each line contains infinitely many real
points. The Matplotlib plot
documentation
specifies that the supplied x and y values provide the coordinates of line
nodes; calling it twice draws the two constraint lines.
Exact fit can fail when the dataset asks for more
The recovered model fits and . Suppose a third observation is . The model predicts
so its residual is . In the parameter plane, the new row contributes a third line, , which does not pass through . There is no single parameter pair that fits all three rows exactly.
This does not make the first calculation wrong. It changes the problem. Two rows selected the exact line through those two observations; the third row showed that the full dataset does not lie on it. Machine-learning practice often replaces “satisfy every equation exactly” with “find parameters whose predictions are collectively close,” but that approximation problem belongs to later lessons.
Another misconception runs in the opposite direction. If two observations are identical, such as and , the system has not learned the two parameters. It has written twice. Every point on that one line still fits, so the weight and bias remain underdetermined.
The dataset claim lives at the intersection
One observation can certify that a parameter pair fits one row. A system raises the standard: the same pair must survive every row’s test. For the two-row example, subtracting observations exposes the weight, substitution recovers the bias, and the crossing of the two parameter lines shows why the answer is shared.
That geometric habit will carry into the next lesson. When a new constraint arrives, inspect what it adds: a new crossing, a contradiction, or merely the same line drawn again.
Check your understanding
Question 1
Test (w, b) = (1, 4), (2, 3), and (3, 0) against the system w + b = 5 and 3w + b = 9. Which pair, if any, solves the system?
Show the step-by-step solution
Substitute each pair into both original equations.
For ,
It fits the first constraint only. For ,
It fits both constraints. For ,
It fits the second constraint only. Therefore is the sole listed pair that solves the system. Passing either truth test alone is insufficient.
Question 2
Solve 2u + v = 8 and 5u + v = 17 by subtraction. Verify the result in both equations and identify the intersection point.
Show the step-by-step solution
Subtract the first equation from the second. Parentheses keep the subtraction attached to every term:
Substitute into the first equation:
Now verify both originals:
The solution and geometric intersection point are .
Question 3
An affine model ŷ = wx + b observes (x, y) = (−1, 1) and (2, 10). Recover w and b, then write the fitted prediction rule.
Show the step-by-step solution
Translate the observations into parameter constraints:
Subtract the first equation from the second:
Substitute into :
The fitted rule is . It returns and , so both residuals are zero.
Question 4
Classify the intersection of 2x + y = 4 and 2x + y = 7. Show how subtraction proves the classification.
Show the step-by-step solution
Subtract the first equation from the second:
The statement is false for every . Both lines have the same left side, so they have the same slope, but their different right sides place them at different intercepts. They are distinct parallel lines. Their intersection, and therefore the system’s solution set, is .
Question 5
Classify the system 2x + 2y = 10 and x + y = 5. Explain why writing two equations does not create a unique solution.
Show the step-by-step solution
Divide the first equation by the nonzero number :
The result is exactly the second equation. Both equations therefore draw the same line. Every point with satisfies both:
and doubling that equality gives . The system has infinitely many solutions along one coincident line; the second equation repeats rather than narrows the first constraint.
Question 6
A student subtracts w + b = 5 from 3w + b = 9 and writes 2w + 2b = 4. Find the first error, finish the solution correctly, and verify it.
Show the step-by-step solution
Subtraction must apply to the entire first left side:
The student’s is a sign-distribution error. Because , the correct step is
Substituting into gives , so . Verification in both original equations yields
Thus is the solution.
Question 7
The model ŷ = 2x + 3 fits observations (1, 5) and (3, 9). A third observation is (2, 8). Does the same parameter pair solve all three constraints? Compute and interpret the residual.
Show the step-by-step solution
Evaluate the model at the third input:
Using residual , the third residual is
The pair still solves the first two constraints, but it fails the third because . Therefore no, this parameter pair does not solve the three-equation system. The negative residual means its prediction is one unit below the third target.