In another post we handled your manager’s request using Linear Regression in Excel. Your manager is a Python lover and she wants you to conduct the analysis in Python. How do you do it?
The process is pretty similar, other than the running environment, and a few lines of code.
First let’s import the data.

Then let’s do a quick scatter chart.

Now let’s do a Line Fit Plot.

And we will print the slope and the intercept.

If you want a detailed summary output (similar to Linear Regression in Excel), you can do an OLS below.

Based on the regression results, we also get the below formula:
Sales = 0.43 + 5.03 * Advertising
3 thoughts on “Linear Regression in Python”