Linear Regression 13 | Python for MLR Model Diagnosis — Part 3
Linear Regression 13 | Python for MLR Model Diagnosis — Part 3

- Import Packages
import copy
from math import *
import pandas as pd
import numpy as np
import scipy
from scipy import stats
from scipy.stats import kstest
from scipy.stats import boxcox
import scipy.linalg as linalg
from sklearn import linear_model
import statsmodels.api as sm
import statsmodels.formula.api as smf
from statsmodels.stats.diagnostic import het_breuschpagan
from patsy import dmatrices
from statsmodels.stats.outliers_influence import variance_inflation_factor
import matplotlib.pyplot as plt
import seaborn as sns
%config InlineBackend.figure_format='retina'
2. Subset Selection
An example instance is,
SubsetSelection(df_brand, 'BrandLiking')
The output is,

3. Forward Stepwise Model Selection (Automatically Select)
An example instance is,
ForwardSelection(df_icecream, 'cons', 'R_sq_adj')
The plot of the model selection is,

The output is,
'cons ~ temp + income + price'
Note that different methods can give different results,
ForwardSelection(df_icecream, 'cons', 'aic')
The plot of the model selection is,

The output is,
'cons ~ income + price + time + temp'