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) # create the model object model = sm.OLS(y, x) # and return the fit model return model.fit() # the file name of the dataset r_filename = '../../Data/Chapter6/power_plant_dataset_pc.csv' # read the data...