Multiple linear regression

627 views
Skip to first unread message

Dr. Ssuna Bashir

unread,
Aug 29, 2019, 10:04:13 AM8/29/19
to pystatsmodels
Hello guys, help me know where am going wrong

import statsmodels.formula.api as sm
X = np.append(arr = np.ones((50, 1)).astype(int), values = X, axis =1)
X_opt = X[:, [0,1,2,3,4,5]]
regressor_OLS = sm.ols(endog = Y, exog = X_opt).fit()
regressor_OLS.summary()

am getting this error

  File "<ipython-input-64-a30cf8cdcb43>", line 1, in <module>
    regressor_OLS = sm.ols(endog = Y, exog = X_opt).fit()

TypeError: from_formula() missing 2 required positional arguments: 'formula' and 'data'

Peter Quackenbush

unread,
Sep 3, 2019, 5:32:55 PM9/3/19
to pystatsmodels
Sorry for slow response. There's a subtle thing you're missing...

If you do import statsmodels.formula.api as sm, then you are landing the formula-based api. You'll need to use patsy to build your design matrices (endogenous and exogenous variables). Note that "ols" is lowercase. For example, for GLM, you do "sm.glm" as this example:


If you do import statsmodels.api as sm, then you need to specify the endogenous and exogenous matrix. 

Reply all
Reply to author
Forward
0 new messages