Visualize the slope-intercept form in fully interactive 2D or 3D space. Click points to reveal drag handles, or rotate the space freely to view from any angle. The graph area is maximized for best viewing.
Overview
The two numbers
y = mx + c
m is the slope — how much y changes for every 1 you move along x. Positive climbs left to right, negative falls, zero is flat.
c is the y-intercept — the value of y when x is 0, which is exactly where the line crosses the vertical axis.
Slope is rise over run: take any two points on the line and divide the change in y by the change in x. Any two points give the same answer, which is what makes it a straight line.
Parameters
Slope (m)
Y-Int (c)
Slope (mz)
Z-Int (cz)
-10010
Presets
Graph Explorer
Click points & drag arrows
Live Calc
General Form
y=mx+c
z=mzx+cz
Current Equation
Evaluating Point X
Let x = 2
y = (1)(2) + 0 = 2
z = (0)(2) + 0 = 0
Resulting Coordinates
( 2, 2 )
Equation of a Line: An Interactive Guide
Master the slope-intercept form by seeing how each parameter affects the line in real-time.
The Core Concept: Slope-Intercept Form
The equation of a straight line is most commonly expressed in the slope-intercept form: y = mx + c. This simple formula is incredibly powerful because it describes the exact relationship between the horizontal position (x) and the vertical position (y) for every point on that line.
Understanding 'm': The Slope
The slope, represented by m, is the "steepness" of the line. It tells you how much the y value changes for every one unit increase in the x value.
A positive slope (m > 0) means the line goes upwards from left to right.
A negative slope (m < 0) means the line goes downwards from left to right.
A zero slope (m = 0) results in a perfectly horizontal line, as the y value never changes.
The larger the absolute value of m, the steeper the line.
Understanding 'c': The Y-Intercept
The y-intercept, represented by c, is the point where the line crosses the vertical y-axis. It's the value of y when x is zero. Changing the y-intercept shifts the entire line up or down without changing its steepness.
Interactive Exploration Guide
Use the graph and controls to build a strong intuition:
Isolate the Slope (m): Set the y-intercept (c) to 0. Now, use the slider or input for slope (m). Watch how the line pivots around the origin (0,0). Set m to 2. Notice that for every 1 unit you move right on the x-axis, the line goes up 2 units on the y-axis.
Isolate the Intercept (c): Set the slope (m) to 1. Now, change the y-intercept (c). Observe how the line slides up and down the y-axis, but its angle never changes.
Use the X-Slider: Set m=2 and c=3. The equation is y = 2x + 3. Now, move the "X-Coordinate" slider. As you change x, watch the "Live Calc" panel. It shows you exactly how the final y coordinate is calculated for the point on the line.
Go 3D: Switch to "3D Space". Now you have a second equation for the z-axis: z = m_z * x + c_z. This demonstrates how you can describe a line in three-dimensional space using the same principles, just with an additional dimension. Rotate the graph by clicking and dragging to see the line from all angles.
Real-World Application: Cost Modeling
This concept is fundamental in data science and machine learning, especially in Linear Regression. Imagine you're predicting house prices.
y could be the price of a house.
x could be its size in square feet.
c would be the base price of a house (e.g., the value of the land).
m would be the price per square foot.
By finding the "line of best fit" through a scatter plot of house data, a machine learning model is essentially just finding the optimal values for m and c.
Key Takeaway
The equation y = mx + c is a simple but profound way to model linear relationships. The slope (m) defines the rate of change, and the y-intercept (c) defines the starting point. Mastering these two parameters is the first step toward understanding more complex mathematical and machine learning models.
Equation of a Line (y = mx + c): A Practical Guide
Every straight line is two numbers: how steeply it climbs, and where it crosses the vertical axis. Fitting a line to data, and a neuron's decision boundary, are both this equation wearing different vocabulary.
Finding a line through two points
Given (1, 5) and (3, 11):
m = (11 − 5) / (3 − 1) = 6 / 2 = 3
Now substitute either point back in to find c. Using (1, 5):
5 = 3(1) + c → c = 2
So the line is y = 3x + 2. Check it against the other point: 3(3) + 2 = 11. Correct.
Why this shows up everywhere later
Linear regression fits exactly this equation — it searches for the m and c that put the line closest to a cloud of points.
A single neuron computes z = wx + b. That is the same equation: the weight is the slope and the bias is the intercept. When you read that a bias "shifts the decision boundary", this is the shift being described.
In three dimensions the same idea becomes a plane, z = m1x + m2y + c, and beyond that a hyperplane. The intuition does not change; only the number of slopes does.
Two numbers describe every straight line
y = mx + c
m is the slope — how much y changes for each unit of x. c is the intercept — the value of y when x is zero.
Change m and the line pivots. Change c and it slides up or down without tilting. Those are the only two things a straight line can do, which is why two numbers are enough.
Reading the slope's sign and size:
m
Line
3
Climbs steeply
1
Climbs at 45°
0.2
Climbs gently
0
Flat
−2
Falls
Slope is rise over run: pick any two points, divide the change in y by the change in x. Any two points on the same line give the same answer — that constancy is the definition of straightness.
Finding the line through two points
Given (1, 5) and (3, 11):
m = (11 − 5) / (3 − 1) = 6 / 2 = 3
Substitute either point back in to get c. Using (1, 5): 5 = 3(1) + c, so c = 2.
The line is y = 3x + 2. Check with the other point: 3(3) + 2 = 11. Correct.
Two other forms of the same line are worth recognising:
Point-slope: y − y₁ = m(x − x₁). The most convenient when you have a point and a slope.
General: Ax + By + C = 0. Handles vertical lines, which y = mx + c cannot, and is the form that generalises to planes.
Where it shows up in machine learning
Linear regression is the search for the m and c that put the line closest to a cloud of points. The whole method is this equation plus a definition of "closest".
A neuron computes z = wx + b. That is the same equation with different letters: the weight is the slope, the bias is the intercept. When you read that "the bias shifts the decision boundary", this is the shift being described.
Decision boundaries in logistic regression and linear SVMs are the line where the score crosses zero — on one side the model says class A, on the other class B.
Higher dimensions keep the idea and add slopes. With two inputs, z = m₁x + m₂y + c is a plane. With 700 inputs it is a hyperplane. You cannot picture it, and none of the algebra changes.
Perpendicular, parallel, and distance
Two lines are parallel when their slopes are equal, and perpendicular when the product of their slopes is −1 — so the perpendicular to a slope of 2 has slope −½.
That fact does real work: in an SVM the margin is measured perpendicular to the boundary, and in linear regression the residuals are measured vertically rather than perpendicularly — a distinction that separates ordinary least squares from total least squares and changes the fitted line.
The distance from a point to a line in general form is:
d = |Ax₀ + By₀ + C| / √(A² + B²)
That formula is exactly what an SVM maximises when it looks for the widest margin.
Try this above
Press Horizontal. The slope is 0, so y never changes no matter how far along x you travel.
Press Negative and watch the line fall left to right — the sign of m is direction, not size.
Press Fractional for a slope between 0 and 1: a gentle climb rather than a steep one.
Change c on its own and watch the line slide vertically without ever tilting.
Switch to 3D Space and add a second slope. The line becomes a plane, and there are now two directions to climb in.
What usually goes wrong
Confusing sign with steepness. A slope of −5 is steeper than a slope of 2. The minus sign only says which way it leans.Expecting every line to fit this form. A vertical line has an undefined slope — x never changes, so the run is zero and you would be dividing by it. Vertical lines are written x = k instead, which is why regression cannot fit perfectly vertical relationships.
In one line
m tilts, c slides — and a neuron’s weight and bias are the same two numbers under different names.
Fitting a line to data
Real data does not sit on a line, so "the line through the points" becomes "the line closest to the points". Ordinary least squares defines closest as the smallest total squared vertical distance, and gives a formula for the answer:
m = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² c = ȳ − m x̄
Two things fall out of the second formula. The fitted line always passes through the point (mean of x, mean of y). And once you have the slope, the intercept costs nothing.
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.array([2.1, 4.2, 5.8, 8.1, 9.9])
m, c = np.polyfit(x, y, 1) # slope and intercept
print(f"y = {m:.2f}x + {c:.2f}") # y = 1.96x + 0.10
Reading the result in the data's own units is the point of the exercise: a slope of 1.96 means each extra unit of x is associated with roughly two extra units of y.
From two points to a decision boundary
The same line written three ways -- slope-intercept, the vector form, and as a classifier boundary. They are the same object.
example_01.pyNumPy
import numpy as np
p1, p2 = np.array([1.0, 3.0]), np.array([4.0, 9.0])
m = (p2[1] - p1[1]) / (p2[0] - p1[0])
c = p1[1] - m * p1[0]
print("through (1,3) and (4,9): y = %.2fx + %.2f" % (m, c))
for x in (0.0, 1.0, 2.5, 4.0):
print(" x=%.1f -> y=%.2f" % (x, m * x + c))
print()
# same line as w . x + b = 0, with w normal to the line
w = np.array([-m, 1.0])
b = -c
print("as w . x + b = 0 with w = %s, b = %.2f" % (w, b))
print(" both original points give zero: %.10f, %.10f"
% (w @ p1 + b, w @ p2 + b))
print()
print("w is perpendicular to the line -- dot it with the direction:")
print(" w . (p2-p1) = %.10f" % (w @ (p2 - p1)))
print()
print("the sign of w.x + b says which side a point is on:")
for pt in ([0.0, 0.0], [2.0, 9.0], [5.0, 1.0], [3.0, 7.0]):
v = w @ np.array(pt) + b
side = "on the line" if abs(v) < 1e-9 else ("above" if v > 0 else "below")
print(" %-12s -> %+8.3f (%s)" % (pt, v, side))
print()
print("distance from a point to the line is that value over ||w||:")
for pt in ([0.0, 0.0], [2.0, 9.0], [5.0, 1.0]):
v = w @ np.array(pt) + b
print(" %-12s -> %.4f" % (pt, abs(v) / np.linalg.norm(w)))
print()
print("this is exactly what logistic regression and a linear SVM learn:")
print("a w and a b, then the sign of w.x + b is the prediction. everything")
print("above the line is one class, everything below is the other.")
Output
Common misconceptions
Confusing sign with steepness. A slope of −5 is steeper than a slope of 2; the sign only says which way it leans.
Interpreting the intercept when x = 0 is impossible. "The price of a zero-square-metre house" is not a meaningful number; it is just where the line crosses the axis.
Expecting every relationship to be a line. A vertical line has undefined slope, and many real relationships curve. Check a scatter plot before fitting one.
Extrapolating beyond the data. A line fitted between x = 1 and x = 10 will confidently answer for x = 500, and that answer is fiction.
Reading a slope as causation. It is an association, and nothing about fitting a line establishes that x causes y.
Questions people ask
What if the line is vertical? The slope is undefined, because the run is zero. Vertical lines are written x = k, which is why regression cannot fit a perfectly vertical relationship.
What is the difference between m and a correlation coefficient? The slope is in the data's units (pounds per square metre); the correlation is unitless and between −1 and 1. They share a sign and answer different questions.
How does this become a plane? Add another input and another slope: z = m₁x + m₂y + c. Each input contributes its own slope.
Why is it called linear regression if I can fit curves? Because it is linear in the parameters. Add x² as a feature and the model fits a parabola while remaining a linear model.
Does the intercept matter? Usually yes — forcing c = 0 makes the line pass through the origin, which is a strong assumption and rarely justified.
How do I know a line is a good fit? Look at the residual plot. A shapeless band around zero means the line captured the pattern; a curve means it did not.
Recap in one screen
y = mx + c: the slope tilts the line, the intercept slides it.
Slope is rise over run, and it is identical between any two points on the line.
A neuron's z = wx + b is the same equation; weight is slope, bias is intercept.
More inputs means more slopes — a plane, then a hyperplane, with the algebra unchanged.
Least squares finds the line minimising squared vertical distance, and it always passes through the means.
Check yourself
0 of 3
Answer without scrolling back up.
In y = mx + c, what does c control?
c is the intercept: it slides the whole line up and down without rotating it. m is the slope, and it is the only term that changes the steepness.
A line has slope m = 0. What does it look like?
Slope is rise over run. A zero rise for any run is a flat, horizontal line. A vertical line is the case with no defined slope at all, because the run is zero and you cannot divide by it.
Why does this one equation matter so much later on?
w·x + b is y = mx + c with more inputs. Weights play the role of slopes and the bias plays the role of the intercept, which is why a perceptron can only ever draw a straight boundary.
Cheat sheet
Equation of a Line (y = mx + c)
Visualize the slope-intercept form in fully interactive 2D or 3D space. Click points to reveal drag handles, or rotate the space freely to view from any angle. The graph area is maximized for best viewing.
Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.