- Understand how to calculate the slope variable for a given line
- Understand how to calculate the y-intercept variable for a given line
Previously, we saw how a regression line can help us describe our relationship between an input variable like a movie budget and an output variable like the expected revenue from a movie with that budget. Let's take a look at that line again.
We also showed how we can describe a line with the formula
def y(x):
return 3*x + 0
y(0)
y(60000000)
We know what these
Say the following are a list of points along a line.
X | Y |
---|---|
0 | 0 |
30 | 90 |
60 | 180 |
How do we calculate the slope
This is the technique. We can determine the slope by taking any two points along the line and looking at the ** ratio of the vertical distance travelled to the horizontal distance travelled**. Rise over run.
Or, in math, it's:
The
$\Delta$ is the capitalized version of the Greek letter Delta. Delta means change. So you can the read the above formula as$m$ equals change in$y$ divided by change in$x$ .
Let's take another look of our graph and our line. Let's look at
-
$\Delta x$ = 30 -
$\Delta y$ = 90 $\frac{\Delta y}{\Delta x} = \frac{90}{30} = 3$
In other words, change in
Therefore, we can describe our
$\Delta y = y_1- y_0$ $\Delta x = x_1 - x_0$
where
Altogether, we can say
given a beginning point
$(x_0, y_0)$ and an ending point$(x_1, y_1)$ along any segment of a straight line, the slope of that line$m$ equals the following:
$$m = \frac{(y_1 - y_0)}{(x_1 - x_0)}$$
Now, let's apply this formula to our line. We can choose any two points along a straight line to calculate the slope of that line. So we now choose the second and third points in our table:
- our initial point (30, 90)
- our ending point of (60, 180)
Then plugging these coordinates into our formula, we have the following:
$m =\frac{(y_1 - y_0)}{(x_1 - x_0)} = \frac{(180 - 90)}{(60 - 30)} = 90/30 = 3$
So that is how we calculate the slope of a line.
Rise over run. Take any two points along that line and divide distance travelled vertically from the distance travelled horizontally. Change in
$y$ divided by change in$x$ .
Now that we know how to calculate the slope, let's turn our attention to calculating the y-intercept.
For example, look at the line below.
If you look at the far-left of the x-axis you will see that our
First, let's figure out the slope of our line. Once again, we can choose any two points on the line to do this. So we choose the points (60, 208) and (30, 118). Plugging this into our formula for
$m =\frac{(y_1 - y_0)}{(x_1 - x_0)} = \frac{(208 - 118)}{(60 - 30)} = 90/30 = 3$
Ok, now we plug in our value of
Now to solve for
It turns out we have lots of values for
$ 118 = 3 * 30 + b $
$ 118 = 90 + b $
$ 28 = b $
Solving for
def y(x):
return 3*x + 28
Let's see how well we did by providing a value of
y(20)
When plugging an
In this lesson, we saw how to calculate the slope and y-intercept variables that describe a line. We can take any two points along the line to calculate our slope variable. This is because given two points along the straight line, we can divide the change in