Performing linear regression is commonly done using the statsmodels or scikit-learn libraries.
Performance of linear regression :
slope, intercept, r_value, p_value, std_err = linregress(diainac_df[‘% INACTIVE’], diainac_df[‘% DIABETIC’])
Where % DIABETIC,%INACTIVE are columns from diainac dataframe.
Plotting the data and the regression line:
plt.scatter(diainac_df[‘% INACTIVE’], diainac_df[‘% DIABETIC’], s=10,label=’Data’)
plt.plot(diainac_df[‘% INACTIVE’], regression_line, color=’red’, label=’Linear Regression’)
Plot is shown below :
The values obtained are :