Math for AI course · Lesson 11 of 180

Linear Equations for AI: Turn One Formula Into a Geometric Line

Learn how one two-variable linear equation becomes a line, test its points, handle vertical cases, and read a linear classifier score contour.

Share this article

A small classifier assigns a score to two features:

s(x1,x2)=2x1+x2−5.s(x_1,x_2)=2x_1+x_2-5.

The feature pairs (0,5)(0,5), (1,3)(1,3), and (2,1)(2,1) look different, yet each gets the same score:

s(0,5)=s(1,3)=s(2,1)=0.s(0,5)=s(1,3)=s(2,1)=0.

Those are not three isolated coincidences. They sit on one geometric line, and every point on that line receives score zero. By the end of this lesson, you will be able to turn a two-variable linear equation into a line, produce and test solutions, and recognize the same geometry inside a linear classifier score contour.

Learning outcome: Convert a two-variable linear equation into a line and test solutions.

This lesson builds directly on Lesson 9: Equations for AI, where an equation became a constraint that selects a solution set. Here the allowed values are pairs (x,y)∈R2(x,y)\in\mathbb R^2, and geometry lets us see that set. Lesson 10: Reading AI Derivations supplies the companion habit: every rearrangement must preserve exactly the same points.

The official Mathematics for Machine Learning companion places systems of linear equations at the start of linear algebra. Its Section 2.1 explains the geometric view that one equation in two variables represents a line and that a system asks where such lines intersect. This lesson isolates the one-line foundation. Its examples, code, visual, and assessments are original, and the next lesson will add the second equation.

One equation describes a place

Consider the general two-variable equation

ax+by=c,ax+by=c,

where xx and yy are real-valued coordinates and aa, bb, and cc are fixed real coefficients. The equation is linear because xx and yy appear only to the first power, are not multiplied by each other, and are multiplied only by fixed numbers.

Suppose b≠0b\ne0. Subtract axax from both sides, then divide by the known nonzero number bb:

ax+by=c,by=c−ax,y=−abx+cb.\begin{aligned} ax+by&=c,\\ by&=c-ax,\\ y&=-\frac{a}{b}x+\frac{c}{b}. \end{aligned}

This is slope-intercept form, y=mx+qy=mx+q. The slope is m=−a/bm=-a/b: increasing xx by one unit changes yy by −a/b-a/b units while the constraint remains true. The vertical-axis intercept is q=c/bq=c/b, reached when x=0x=0.

The rearranged formula does more than make plotting convenient. It exposes one free choice. Pick any real xx; the equation calculates exactly one matching yy. As xx varies continuously, the solution point traces a line rather than a finite collection of dots.

One worked line reveals slope, intercepts, and points

Work through

3x+2y=12.3x+2y=12.

Here a=3a=3, b=2b=2, and c=12c=12. Because bb is nonzero, solving for yy is legal:

3x+2y=12,2y=12−3x,y=6−32x.\begin{aligned} 3x+2y&=12,\\ 2y&=12-3x,\\ y&=6-\frac32x. \end{aligned}

The line has slope −3/2-3/2. If xx rises by 22, yy falls by 33. That paired change keeps the left side fixed because

3(Δx)+2(Δy)=3(2)+2(−3)=0.3(\Delta x)+2(\Delta y)=3(2)+2(-3)=0.

A residual turns that truth test into one number:

r(x,y):=3x+2y−12.r(x,y):=3x+2y-12.

Points on the line have residual 00. A nonzero residual gives both a failed test and a sign: positive means the weighted sum is above 1212, and negative means it is below 1212.

Candidate pointSubstitute into 3x+2y3x+2yResidual r(x,y)r(x,y)Verdict
(0,6)(0,6)3(0)+2(6)=123(0)+2(6)=1200On the line
(2,3)(2,3)3(2)+2(3)=123(2)+2(3)=1200On the line
(4,0)(4,0)3(4)+2(0)=123(4)+2(0)=1200On the line
(2,4)(2,4)3(2)+2(4)=143(2)+2(4)=1422Off the line

Two distinct points are enough to draw this line, but they are not the whole solution set. The controlled visual makes the missing family tangible.

Move one coordinate while the equation calculates the other: every displayed pair stays on 3x + 2y = 12.
Choose a point on the line

Use the slider with a pointer or the arrow, Page Up, Page Down, Home, and End keys.

2
Calculated y-coordinate3Calculated from y = (12 − 3x) ÷ 2

You can also drag the circular point left or right along the line.

Selected point: (2, 3). Its residual is 0, so it satisfies the equation.

Every solution of 3x + 2y = 12●Selected solution
A movable point on the line 3x plus 2y equals 12The line descends from negative 2 comma 9 to 6 comma negative 3. The selected point begins at 2 comma 3 and always has residual zero.
Text alternative for the selected point
QuantityCurrent valueHow it is obtained
x-coordinate2Chosen with the range control
y-coordinate3(12 − 3 × 2) ÷ 2
Residual03 × 2 + 2 × 3 − 12

The first server-rendered state is (2,3)(2,3), and the table beneath the chart contains the same calculation. The line does not need JavaScript to make its mathematical point; hydration adds the ability to choose another xx and watch the matching yy change. The control uses fixed quarter-unit steps for inspection, while the mathematical parameter can be any real number.

A parameter accounts for the entire line

Writing down several points suggests a pattern, but a parameter describes all of them at once. Let tt be any real number and set

(x,y)=(t,6−32t),t∈R.(x,y)=\left(t,6-\frac32t\right), \qquad t\in\mathbb R.

Every pair in this family is a solution because

3t+2(6−32t)=3t+12−3t=12.3t+2\left(6-\frac32t\right) =3t+12-3t =12.

The converse matters too. Any pair satisfying 3x+2y=123x+2y=12 must also satisfy y=6−32xy=6-\tfrac32x. Choosing t=xt=x places that pair in the parameterized family. Together, those two directions show that the parameterization includes every point on the line and no off-line point.

This is why a graphing window never contains the whole mathematical object. Pixels and sampled coordinates are finite; the line is the infinite solution set specified by the equation.

NumPy generates points; the original equation verifies them

The code should mirror the algebra. NumPy documents linspace as returning evenly spaced samples over a specified interval. Generate a few xx values, calculate their matching yy values, and then test the original constraint rather than trusting the rearrangement:

import numpy as np
import matplotlib.pyplot as plt

# 3x + 2y = 12  ->  y = (12 - 3x) / 2
x = np.linspace(-2.0, 6.0, num=5)
y = (12.0 - 3.0 * x) / 2.0
residual = 3.0 * x + 2.0 * y - 12.0

print("x:", x)
print("y:", y)
print("residual:", residual)
print("on line:", np.isclose(residual, 0.0, rtol=0.0, atol=1e-12))

candidates = np.array([[2.0, 3.0], [2.0, 4.0], [4.0, 0.0]])
candidate_residual = 3.0 * candidates[:, 0] + 2.0 * candidates[:, 1] - 12.0
print("candidate residual:", candidate_residual)
print(
    "candidate on line:",
    np.isclose(candidate_residual, 0.0, rtol=0.0, atol=1e-12),
)

plt.plot(x, y, label="3x + 2y = 12")
plt.plot(candidates[:, 0], candidates[:, 1], "o", label="tested points")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
plt.show()

The executed output is:

x: [-2.  0.  2.  4.  6.]
y: [ 9.  6.  3.  0. -3.]
residual: [0. 0. 0. 0. 0.]
on line: [ True  True  True  True  True]
candidate residual: [0. 2. 0.]
candidate on line: [ True False  True]

np.isclose compares floating-point values with an explicit tolerance. Here rtol=0.0 and atol=1e-12 mean “accept a residual whose absolute magnitude is at most 10−1210^{-12}.” That is a numerical engineering decision at this example’s scale, not a symbolic proof that the equation holds. The proof came from the algebra; the code checks that this implementation agrees.

The plotting call follows Matplotlib’s plot contract: the supplied arrays provide the horizontal and vertical coordinates of the line nodes. A denser plot would look smoother, but it would not create more mathematical solutions.

A classifier contour is the same equation with feature names

Return to the opening score:

s(x1,x2)=2x1+x2−5.s(x_1,x_2)=2x_1+x_2-5.

Here x1x_1 and x2x_2 are input features, 22 and 11 are fixed weights, and −5-5 is an intercept. A score contour collects all feature pairs that receive one chosen score. The zero-score contour satisfies

s(x1,x2)=0  ⟺  2x1+x2=5  ⟺  x2=5−2x1.s(x_1,x_2)=0 \iff 2x_1+x_2=5 \iff x_2=5-2x_1.

That is a line. Moving from (1,3)(1,3) to (2,1)(2,1) raises x1x_1 by 11 and lowers x2x_2 by 22, leaving the score unchanged:

2(1)+3−5=0,2(2)+1−5=0.2(1)+3-5=0, \qquad 2(2)+1-5=0.

This form is not invented for the diagram. An official scikit-learn LinearSVC example shows the decision function calculated as a feature matrix multiplied by learned coefficients plus an intercept. The scikit-learn RidgeClassifier documentation also states its binary confidence score is proportional to signed distance from the separating hyperplane and documents that a score above zero predicts its second class.

For this educational classifier, choose the explicit rule

class^={A,s(x1,x2)>0,B,s(x1,x2)≤0.\widehat{\text{class}}= \begin{cases} \text{A}, & s(x_1,x_2)>0,\\ \text{B}, & s(x_1,x_2)\le0. \end{cases}

Under that convention, the zero contour is the decision boundary: crossing it changes the predicted class. Points on one side have a positive score and points on the other have a negative score. The line alone does not specify the tie rule or class names; those belong to the prediction convention. Nor is the raw score automatically a probability.

Feature pairScore calculationScoreResult under the stated rule
(1,3)(1,3)2(1)+3−52(1)+3-500Class B, on the boundary
(2,2)(2,2)2(2)+2−52(2)+2-511Class A
(0,4)(0,4)2(0)+4−52(0)+4-5−1-1Class B

Division by zero reveals the missing cases

The sentence “ax+by=cax+by=c is a line” needs one condition: aa and bb cannot both be zero. Solving for yy needs the stronger local condition b≠0b\ne0.

Coefficient caseSolution setGeometric result
b≠0b\ne0y=−abx+cby=-\frac abx+\frac cbA nonvertical line
b=0b=0, a≠0a\ne0x=cax=\frac ca and any real yyA vertical line
a=0a=0, b≠0b\ne0y=cby=\frac cb and any real xxA horizontal line
a=b=0a=b=0, c=0c=0Every (x,y)∈R2(x,y)\in\mathbb R^2The whole plane, not one line
a=b=0a=b=0, c≠0c\ne0No solutionsThe empty set, not a line

For example, 2x+0y=62x+0y=6 simplifies to x=3x=3. Every point (3,y)(3,y) works, so the line is vertical. Trying to produce y=mx+qy=mx+q by dividing by b=0b=0 is not an awkward route—it is undefined. A vertical line has no finite slope because its xx coordinate does not change while yy can.

There is one more practical misconception to avoid. Two plotted points can determine a nondegenerate line, but passing two tests does not prove arbitrary code represents the intended equation. A swapped coefficient can still put those particular points in the expected places. Evaluate the residual for several deliberately chosen points, including an off-line point, and retain the algebraic derivation as the source of truth.

One more constraint will turn lines into intersections

One equation leaves one free coordinate: choose xx, and the line determines yy—or, for a vertical line, choose yy while xx stays fixed. That freedom is why a single equation usually has infinitely many coordinate-pair solutions.

The next lesson will impose a second equation on the same pair. A solution will then need to lie on both lines at once. The point-on-line test developed here becomes an intersection test, and the geometry will reveal why a system can have one solution, no solution, or an entire shared line.

Check your understanding

Question 1

Convert 4x + 2y = 8 into slope-intercept form. State the slope and both axis intercepts, showing each step.

Show the step-by-step solution

Because the coefficient of yy is the nonzero number 22, isolate yy with reversible steps:

4x+2y=8,2y=8−4x,y=4−2x.\begin{aligned} 4x+2y&=8,\\ 2y&=8-4x,\\ y&=4-2x. \end{aligned}

Comparing y=4−2xy=4-2x with y=mx+qy=mx+q gives slope m=−2m=-2 and vertical-axis intercept q=4q=4, so one intercept is (0,4)(0,4). For the horizontal-axis intercept, set y=0y=0:

0=4−2x  ⟺  2x=4  ⟺  x=2.0=4-2x \iff 2x=4 \iff x=2.

The other intercept is (2,0)(2,0). Both satisfy the original equation: 4(0)+2(4)=84(0)+2(4)=8 and 4(2)+2(0)=84(2)+2(0)=8.

Question 2

Test the points (3, 1), (1, 3), and (0, 4) against 2x + y = 7. Compute a residual for each and classify it as on or off the line.

Show the step-by-step solution

Use the residual r(x,y)=2x+y−7r(x,y)=2x+y-7:

r(3,1)=2(3)+1−7=0,r(1,3)=2(1)+3−7=−2,r(0,4)=2(0)+4−7=−3.\begin{aligned} r(3,1)&=2(3)+1-7=0,\\ r(1,3)&=2(1)+3-7=-2,\\ r(0,4)&=2(0)+4-7=-3. \end{aligned}

Only (3,1)(3,1) has residual zero, so it is on the line. The other two points are off the line. Their negative residuals mean their weighted sums, 55 and 44, fall below the required value 77.

Question 3

Parameterize every solution of x − 3y = 6 using one real parameter, then prove both directions of the set equality.

Show the step-by-step solution

Choose y=ty=t for any t∈Rt\in\mathbb R. Solving for xx gives

x−3t=6  ⟺  x=6+3t.x-3t=6 \iff x=6+3t.

So the proposed family is

(x,y)=(6+3t,t),t∈R.(x,y)=(6+3t,t), \qquad t\in\mathbb R.

First, every listed pair works because

(6+3t)−3t=6.(6+3t)-3t=6.

Second, any solution (x,y)(x,y) of the original equation satisfies x=6+3yx=6+3y. Setting t=yt=y writes that solution as (6+3t,t)(6+3t,t). The first direction excludes off-line points; the second ensures no solution was omitted.

Question 4

A student rewrites 5x + 0y = 10 as y = (10 − 5x) / 0 and concludes that the equation has no graph. Diagnose the error and give the correct solution set.

Show the step-by-step solution

The attempted rearrangement divides by the coefficient of yy, which is zero. Division by zero is undefined, so that step cannot preserve the solution set.

Work from the original equation instead:

5x+0y=10  ⟺  5x=10  ⟺  x=2.5x+0y=10 \iff 5x=10 \iff x=2.

The equation places no restriction on yy. Its solution set is

{(2,t)∣t∈R},\{(2,t)\mid t\in\mathbb R\},

the vertical line x=2x=2. The graph exists; only slope-intercept form with a finite slope is unavailable.

Question 5

Classify the solution sets of 0x + 0y = 0 and 0x + 0y = 4. Explain why neither equation describes a single line.

Show the step-by-step solution

For every real pair (x,y)(x,y),

0x+0y=0.0x+0y=0.

Therefore the first solution set is all of R2\mathbb R^2, the entire coordinate plane. It does not select one line.

The second equation simplifies to 0=40=4, which is false for every assignment. Its solution set is ∅\varnothing, the empty set. It does not contain a line at all. These cases are why the line definition requires at least one of aa or bb to be nonzero.

Question 6

For the score s(x₁, x₂) = −x₁ + 2x₂ − 4, find the zero-score contour and classify (0, 3), (2, 3), and (4, 3) using class A for positive scores and class B otherwise.

Show the step-by-step solution

Set the score to zero and isolate x2x_2:

−x1+2x2−4=0  ⟺  2x2=x1+4  ⟺  x2=12x1+2.-x_1+2x_2-4=0 \iff 2x_2=x_1+4 \iff x_2=\frac12x_1+2.

This line is the zero-score contour. Now evaluate the three points:

s(0,3)=−(0)+2(3)−4=2,s(2,3)=−(2)+2(3)−4=0,s(4,3)=−(4)+2(3)−4=−2.\begin{aligned} s(0,3)&=-(0)+2(3)-4=2,\\ s(2,3)&=-(2)+2(3)-4=0,\\ s(4,3)&=-(4)+2(3)-4=-2. \end{aligned}

Under the stated convention, (0,3)(0,3) is class A, while (2,3)(2,3) and (4,3)(4,3) are class B. The point (2,3)(2,3) lies exactly on the boundary. A different tie rule could assign the zero-score point differently, so the equation alone does not determine that label.

Question 7

Debug this NumPy check: on_line = (3 * x + 2 * y == 12). Write a tolerance-aware residual check and explain what it can and cannot establish.

Show the step-by-step solution

Compute the residual first, then compare it with zero using a tolerance chosen for the scale of the calculation:

residual = 3.0 * x + 2.0 * y - 12.0
on_line = np.isclose(residual, 0.0, rtol=0.0, atol=1e-12)

This accepts an element when ∣r∣≤10−12|r|\le10^{-12}. It avoids demanding bit-for-bit equality after floating-point arithmetic, where rounding may leave a tiny nonzero residual.

The result tests the supplied numerical arrays and this tolerance. It cannot prove the symbolic identity 3x+2y=123x+2y=12 for every real parameter value, and an overly large atol could incorrectly accept off-line points. The derivation establishes the formula; the numerical check helps catch implementation errors.

Sources

  1. Mathematics for Machine Learning companion website
  2. Mathematics for Machine Learning book PDF
  3. NumPy documentation: numpy.linspace
  4. NumPy documentation: numpy.isclose
  5. Matplotlib documentation: matplotlib.pyplot.plot
  6. scikit-learn documentation: RidgeClassifier
  7. scikit-learn example: Plot the support vectors in LinearSVC