Building Linear Regression model
Linear regression is arguably the simplest model that one can build. It is a model of choice if you know that the relationship between your dependent variable and independent ones is linear.
Getting ready
To execute this recipe, you will need pandas
, NumPy
, and Scikit
. No other prerequisites are required.
How to do it…
Estimating the regression model with Scikit
is extremely easy (the regression_linear.py
file):
import sys sys.path.append('..') # the rest of the imports import helper as hlp import pandas as pd import numpy as np import sklearn.linear_model as lm @hlp.timeit def regression_linear(x,y): ''' Estimate a linear regression ''' # create the regressor object linear = lm.LinearRegression(fit_intercept=True, normalize=True, copy_X=True, n_jobs=-1) # estimate the model linear.fit(x,y) # return the object return linear # the file name of the dataset r_filename = '../../Data/Chapter6/power_plant_dataset_pc...