Download Linear_Functions.py from TinTinDo/Data-Science-Tutorial: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/TinTinDo/Data-Science-Tutorial/resolve/main/Linear_Functions.py
- Command line
-
hf download hf://TinTinDo/Data-Science-Tutorial/Linear_Functions.py
-
curl -L -o Linear_Functions.py https://huggingface.co/TinTinDo/Data-Science-Tutorial/resolve/main/Linear_Functions.py
1.88 kB
| # Linear Functions | |
| ''' | |
| A linear function has one independent variable (x) and one dependent variable (y), and has the following form: | |
| y = f(x) = ax + b | |
| This 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. | |
| # For example: | |
| # Let us say we want to predict calorie burnage using average pulse. We have the following formula: | |
| # f(x) = 2x + 80 | |
| ''' | |
| Here, 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 | |
| ''' | |
| 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. | |
| ''' | |