If you run the code below, it'll plot some data points (green circles), which are the temperature in a room (y-axis) vs. the minutes into a day (x-axis). (The graph axes are not labeled. The x-axis goes from 0 to 100, and the y-axis from 0 to 60.)
The exercise here is to see if you can manually find a "trendline" that passes through the data points.
Alter the m= (slope) and b= (y-intercept) to see if you can make the yellow line go through the data points.
Now you try. Alter the m= and b= lines, picking a slope and y-intercept, and see if you can get the line to pass through the data points.
Type your code here:
See your results here:
What good is a trendline? Well, if you can indeed find a line that passes through the data points, it does a few things for you.
First, it tells you that there might be a correlation between the data on your two axes. Here, this means the temperature might be correlated with the time of day. (Maybe this is a room facing the rising sun for example.)
Second, it allows you to extract information even if the data isn't there. For example, suppose you want to know what the temperature was at 30 minutes? You don't have a data point at 30 minutes, but if your trendline came out to be $y=0.2x+39$, you could find that $y=0.2(30)+39$ or $45$. This is called "interpolating."
You could also look outside of your data range to see what the temperature might be at 200 minutes (supposing the heating source continues as it has). You could do $y=0.2(200)+39$ to get $79$. This is called "extrapolating."
Share your code
Show a friend, family member, or teacher what you've done!