StatsModels

import statsmodels.api as sm
from statsmodels.stats.outliers_influence \
     import variance_inflation_factor as VIF
from statsmodels.stats.anova import anova_lm

Simple Linear Regression

model = sm.OLS(y, X)
results = model.fit()
summarize(results)

Multiple Linear Regression

use MS() again, but with multiple columns:

X = MS(['col1', 'col2']).fit_transform(dataframe)
model = sm.OLS(y, X)
results = model.fit()

Interaction Terms

Add a tuple to MS() to add an interaction term:

X = MS(['col1',
        'col2',
        ('col1', 'col2')]).fit_transform(dataframe)

Non-linear Transformations of the Predictors

Add poly() from ISLP to MS():

X = MS([poly('col1', degree=2), 'col2']).fit_transform(dataframe)

Qualitative Predictors

Connect With Me!