Business profits – analyzing trends
We are interested in predicting the profits of a business for the year 2018 given its profits for previous years:
Year | Profit in USD |
2011 | $40,000 |
2012 | $43,000 |
2013 | $45,000 |
2014 | $50,000 |
2015 | $54,000 |
2016 | $57,000 |
2017 | $59,000 |
2018 | ? |
Â
Analysis
In this example, the profit is always increasing, so we can think of representing the profit as a growing function that's dependent on the time variable, which is represented by years. The variations in profit between the subsequent years are $3,000, $2,000, $5,000, $4,000, $3,000, and $2,000. These differences do not seem to be affected by time, and the variation between them is relatively low. Therefore, we may try to predict the profit for the coming years by performing linear regression. We express profit, p, in terms of the year, y, in a linear equation, also called a trend line:
We can find the constants, a and b, using linear regression.
Analyzing trends using the least squares method in Python
Input:
We store the data from the preceding...