# !pip install statsmodels
import pandas as pd
data = { 'x': [1,2,3,4,5], 'y': [1,3,4,6,5]}
df = pd.DataFrame(data)
import statsmodels.formula.api as smf
lm_model = smf.ols(formula = 'y ~ x', data = df).fit()
lm_model.params
Intercept 0.5
x 1.1
dtype: float64
import seaborn as sns
import matplotlib.pyplot as plt
sns.lmplot(x='x', y ='y', data = df );
resid = lm_model.resid
resid
0 -0.6
1 0.3
2 0.2
3 1.1
4 -1.0
dtype: float64
lm_model.rsquared
0.8175675675675675