- 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)
0
y(60000000)
180000000
Now that know what these
Let's say the following are a list of points along a line.
X | Y |
---|---|
0 | 0 |
30 million | 40 million |
60 million | 80 million |
How do we calculate the slope
The
$\Delta$ is the capitalized version of the Greek letter Delta. In math, delta means change. So you can the read the above formula as$m$ equals change in$y$ divided by change in$x$ .
For example, let's take another look of our graph, and our line. Let's travel the distance from
-
$\Delta x$ = 30 million -
$\Delta y$ = 40 million
Notice that another way to word change in
So, we can describe our
$\Delta y = y_1- y_0$ $\Delta x = x_1 - x_0$
where
So putting this altogether, we can say
Ok, let's apply this formula to our line. Because we can choose any two points along a straight line to calculate the slope of that line, we can now choose the second and third points in our table (30,000,000, 40,000,000) as our initial point, and an ending point of (60,000,000, 80,000,000). Then plugging these coordinates into our formula, we have the following:
$m =(y_1 - y_0)\div(x_1 - x_0) = (80,000,000 - 40,000,000) \div (60,000,000 - 30,000,000) = 4/3 = 1.33$
So that is how we calculate the slope of a line, take any two points along that line and divide distance travelled vertically from the distance travelled horizontally. Rise over run. Change in
Now, not only can we calculate our slope variable given two points along the line, but we can also calculate our y-intercept. For example, take a look at a new line, the line in the graph below.
If you look at the far-left of the x-axis you will see that our
Here's what we can do. 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 (30 million, 66 million) and (40 million, 80 million). Plugging this into our formula for
$m = (y_1 - y_0)/(x_1 - x_0) = (80,000,000 - 66,000,000)/ (40,000,000 - 30,000,000) = 13,000,000 / 10,000,000 $ = 1.3
Ok, so now plugging our calculated value of
Now the formula is true, for any point (x, y) along the line. So to solve for
$ 80,000,000 = 1.3 * 40,000,000 + b $
So now let's solve for
$ 80,000,000 = 1.3 * 40,000,000 + b $
$ 80,000,000 = 52,000,000 + b $
$ 28,000,000 = b $
Solving for
def y(x):
return 1.3*x + 28000000
Let's see how well we did by providing a value of
y(20000000)
54000000.0
So using our formula, when
In this lesson, we saw how to calculate the slope and y-intercept variables that describe our 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