Simple linear regression
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='darkgrid')
from sklearn.linear_model import LinearRegression
lung = pd.read_csv('LungDisease.csv')
sns.scatterplot(data=lung, x='Exposure',y='PEFR')
predictors = ['Exposure']
outcome = 'PEFR'
lm = LinearRegression()
lm.fit(lung[predictors], lung[outcome])
print(f'Intercept: {lm.intercept_:.3f}')
print(f'Coefficient Exposure: {lm.coef_[0]:.3f}')
sns.regplot(data=lung,x='Exposure', y='PEFR')
References:
Bruce, Peter, Andrew Bruce, and Peter Gedeck. Practical statistics for data scientists: 50+ essential concepts using R and Python. O'Reilly Media, 2020.