pythonintermediate
OLS Regression with statsmodels
Fit and interpret an Ordinary Least Squares regression model with diagnostics using statsmodels.
pythonPress ⌘/Ctrl + Shift + C to copy
import statsmodels.api as sm
import numpy as np, pandas as pd
np.random.seed(0)
n = 200
df = pd.DataFrame({'x1': np.random.randn(n),'x2': np.random.randn(n),'y': 3 + 2*np.random.randn(n)})
X = sm.add_constant(df[['x1','x2']])
model = sm.OLS(df['y'], X).fit()
print(model.summary())
print('AIC:', model.aic)Use Cases
- econometric analysis
- feature significance testing
- predictive modeling
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
pythonintermediate
Statistical Analysis with SciPy
Run hypothesis tests, correlations, and descriptive statistics on dataset columns with SciPy.
Best for: A/B testing
#scipy#statistics
pythonbeginner
Pandas Rank with Tie-Breaking Methods
Apply different ranking strategies (min, dense, average) and handle ties in pandas.
Best for: leaderboards
#pandas#ranking
sqladvanced
SQL Window Functions for Analytics
Advanced SQL window functions for running totals, rankings, moving averages, and gap analysis.
Best for: Building analytics dashboards with running totals
#sql#window-functions
sqladvanced
SQL Window Functions for Analytics
Use window functions for running totals, rankings, moving averages, and gap detection in analytics.
Best for: Building cumulative revenue dashboards
#sql#window-functions