bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Data Science/DS Math
Data Science•DS Math

Data Science - Plotting Linear Functions

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Data Science - Plotting Linear Functions?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ matplotlib.pyplot as plt
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Why is The Line Not Fully Drawn Down to The y-axis?
Plot the Existing Data in Python
The Sports Watch Data Set
4Data move

Before charting or modeling a dataset, which move should come first?

The Sports Watch Data Set

Take a look at our health data set:

DurationAverage_PulseMax_PulseCalorie_BurnageHours_WorkHours_Sleep
3080120240107
3085120250107
459013026087
459513027087
4510014028007
6010514029078
6011014530078
6011514531088
7512015032008
7512515033088

Plot the Existing Data in Python

Now, we can first plot the values of Average_Pulse against Calorie_Burnage using the matplotlib library.

The plot() function is used to make a 2D hexagonal binning plot of points x,y:

Example

import matplotlib.pyplot as plt
health_data.plot(x ='Average_Pulse',
y='Calorie_Burnage', kind='line'),
plt.ylim(ymin=0)
plt.xlim(xmin=0)

plt.show()

Example Explained

  • Import the pyplot module of the matplotlib library
  • Plot the data from Average_Pulse against Calorie_Burnage
  • kind='line' tells us which type of plot we want. Here, we want to have a straight line
  • plt.ylim() and plt.xlim() tells us what value we want the axis to start on. Here, we want the axis to begin from zero
  • plt.show() shows us the output

The code above will produce the following result:

The Graph Output

As we can see, there is a relationship between Average_Pulse and Calorie_Burnage. Calorie_Burnage increases proportionally with Average_Pulse. It means that we can use Average_Pulse to predict Calorie_Burnage.

Why is The Line Not Fully Drawn Down to The y-axis?

The reason is that we do not have observations where Average_Pulse or Calorie_Burnage are equal to zero. 80 is the first observation of Average_Pulse and 240 is the first observation of Calorie_Burnage.

Look at the line. What happens to calorie burnage if average pulse increases from 80 to 90?

We can use the diagonal line to find the mathematical function to predict calorie burnage.

As it turns out

  • If the average pulse is 80, the calorie burnage is 240
  • If the average pulse is 90, the calorie burnage is 260
  • If the average pulse is 100, the calorie burnage is 280

There is a pattern. If average pulse increases by 10, the calorie burnage increases by 20.

Previous

Data Science - Linear Functions

Next

Data Science - Slope and Intercept