Difference between revisions of "Regression"

From Bitnami MediaWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
===<code>statsmodels</code>===
 
===<code>statsmodels</code>===
 +
 +
<syntaxhighlight lang=python>
 +
import statsmodels.api as sm
 +
df = pd.DataFrame(my_data)
 +
y = df['my_dep_variable']
 +
X = df['everything_else']
 +
# optionally add intercept
 +
X = sm.add_constant(X)
 +
# create model
 +
model = sm.OLS(y, X)
 +
results = model.fit()
 +
results.summary()
 +
</syntaxhighlight>
  
 
===<code>sklearn</code>===
 
===<code>sklearn</code>===

Revision as of 22:43, 23 October 2023

statsmodels

import statsmodels.api as sm
df = pd.DataFrame(my_data)
y = df['my_dep_variable']
X = df['everything_else']
# optionally add intercept
X = sm.add_constant(X)
# create model 
model = sm.OLS(y, X)
results = model.fit()
results.summary()

sklearn

pingouin