When I was doing multiple regression analysis, I was worried that the slope and p-value calculated by Excel and the value calculated by Statsmodel of Python were different, but I noticed that I did not add a constant term to Statsmodel. ・ ・.
It seems that you can use ʻadd_const` of Stats model to add it. statsmodels.tools.tools.add_constant
hoge.py
from statsmodels import api as sm
X = df[["height","width"]]
X = sm.add_constant(X)
y = df["weight"]
model = sm.OLS(y,X)
result = model.fit()
result.summary()
Thank you very much.
Recommended Posts