Last active
December 21, 2022 05:05
-
-
Save galenseilis/70fe9d29f612578adf3fc4c9c44d28ae to your computer and use it in GitHub Desktop.
Statistical rethinking with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import statsmodels.api as sm | |
import statsmodels.formula.api as smf | |
cars = sm.datasets.get_rdataset('cars') | |
cars = cars.raw_data | |
model = smf.ols('dist ~ speed', data=cars) | |
results = model.fit() | |
print(results.params) | |
plt.scatter(cars.speed, results.resid) | |
plt.xlabel('Speed') | |
plt.ylabel('Residuals') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment