Using OLS to forecast how much electricity can be produced

Ordinary Least Squares (OLS) is also a linear model. In fact, a linear regression is estimated using the least squares method as well. The OLS is, however, capable of estimating a model where the relationship between the dependent and independent variables is nonlinear as long as this relationship is linear in parameters.

Getting ready

To execute this recipe, you will need pandas and Statsmodels. No other prerequisites are required.

How to do it…

We will, as always, wrap our model estimation efforts in a function (the regression_ols.py file):

import statsmodels.api as sm @hlp.timeit def regression_ols(x,y): ''' Estimate a linear regression ''' # add a constant to the data x = sm.add_constant(x) ...

Get Practical Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.