Mathematical functions are important to know as a data scientist, because we want to make predictions and interpret them.
In mathematics a function is used to relate one variable to another variable.
Suppose we consider the relationship between calorie burnage and average pulse. It is reasonable to assume that, in general, the calorie burnage will change as the average pulse changes - we say that the calorie burnage depends upon the average pulse.
Furthermore, it may be reasonable to assume that as the average pulse increases, so will the calorie burnage. Calorie burnage and average pulse are the two variables being considered.
Because the calorie burnage depends upon the average pulse, we say that calorie burnage is the dependent variable and the average pulse is the independent variable.
The relationship between a dependent and an independent variable can often be expressed mathematically using a formula (function).
A linear function has one independent variable (x) and one dependent variable (y), and has the following form:
y = f(x) = ax + bThis function is used to calculate a value for the dependent variable when we choose a value for the independent variable.
Explanation:
- f(x) = the output (the dependant variable)
- x = the input (the independant variable)
- a = slope = is the coefficient of the independent variable. It gives the rate of change of the dependent variable
- b = intercept = is the value of the dependent variable when x = 0. It is also the point where the diagonal line crosses the vertical axis.
Linear Function With One Explanatory Variable
A function with one explanatory variable means that we use one variable for prediction.
Let us say we want to predict calorie burnage using average pulse. We have the following formula:
f(x) = 2x + 80Here, the numbers and variables means:
- f(x) = The output. This number is where we get the predicted value of Calorie_Burnage
- x = The input, which is Average_Pulse
- 2 = Slope = Specifies how much Calorie_Burnage increases if Average_Pulse increases by one. It tells us how "steep" the diagonal line is
- 80 = Intercept = A fixed value. It is the value of the dependent variable when x = 0
Plotting a Linear Function
The term linearity means a "straight line". So, if you show a linear function graphically, the line will always be a straight line. The line can slope upwards, downwards, and in some cases may be horizontal or vertical.
Here is a graphical representation of the mathematical function above:

Graph Explanations:
- The horizontal axis is generally called the x-axis. Here, it represents Average_Pulse.
- The vertical axis is generally called the y-axis. Here, it represents Calorie_Burnage.
- Calorie_Burnage is a function of Average_Pulse, because Calorie_Burnage is assumed to be dependent on Average_Pulse.
- In other words, we use Average_Pulse to predict Calorie_Burnage.
- The blue (diagonal) line represents the structure of the mathematical function that predicts calorie burnage.
The Sports Watch Data Set
Take a look at our health data set:
| Duration | Average_Pulse | Max_Pulse | Calorie_Burnage | Hours_Work | Hours_Sleep |
|---|---|---|---|---|---|
| 30 | 80 | 120 | 240 | 10 | 7 |
| 30 | 85 | 120 | 250 | 10 | 7 |
| 45 | 90 | 130 | 260 | 8 | 7 |
| 45 | 95 | 130 | 270 | 8 | 7 |
| 45 | 100 | 140 | 280 | 0 | 7 |
| 60 | 105 | 140 | 290 | 7 | 8 |
| 60 | 110 | 145 | 300 | 7 | 8 |
| 60 | 115 | 145 | 310 | 8 | 8 |
| 75 | 120 | 150 | 320 | 0 | 8 |
| 75 | 125 | 150 | 330 | 8 | 8 |
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.
No comments:
Post a Comment