The result of the execution of the program is shown at the Figure 02.
>>>y = ax + b (y = 82.9842x + 23.5645)
>>>x = 2 y = 189.533
Figure 02. Result of the execution of the linear regression
It can be noticed that the result of the script printed at the console three lines. The first one showing the line equation, the second the value predicted for the quantity of items sold when the unit cost is $$ 2,00 and finally, the third line brings the evaluated Rˆ2 metrics. The fourth line shows the interpretation of the Rˆ2 metrics: if this value is below than 0.8, it's recommended to use a non-linear model. Otherwise, the linear regression can be used to this prediction problem.
One detail that must be considered is the numerical precision of the python implementation, that can be different from the equation presented by the Excel. Other important observation is that we cannot forget that this generated equation not necessarily provide all the scatters of the plot, that is, by using the equation we can not obtain exactly the same values of the previously data, thus the equation generated by the linear regression creates an approximation of the values. The Figure 03 shows the plot with the new value predicted, which it's represented by the red dot.
Figure 03. The Quantity of products sold predicted when the price = $2,00
In this example, we considered that the quantity sold depends only of the unit cost of the product. Based on this supposition, we worked with a price of $$ 2,00 for each unit and calculated the quantity approximated by the sells model.
To download the script with all the archives used at this example, just click here.
I expect you enjoyed this article,
Any doubts, please comment !
See you next time,
Marcel P. Caraciolo