python - Linear Regression using Scikit-learn vs Statsmodels -
i wanted check if multiple linear regression problem produced same output when solved using scikit-learn , statsmodels.api. did in 3 sections (in order of mention): statsmodels(without intercept), statsmodels(with intercept) , skl. expected, skl coefficients , r(square) same of statsmodels(with intercept) skl mean square error equivalent of statsmodels(without intercept).
i going share notebook code; it's basic piece of code, since have started machine learning applications. please go through , tell me why happening. also, if share insights on inefficient piece of code, thankful. here's code:
you made mistake, explains strange results. when make predictions linear model scikit-learn, write:
predictions2 = lm.predict(xtest2)
notice using lm
model, 1 resulting first statsmodels regression. instead, should have written:
predictions2 = lm2.predict(xtest2)
when this, results expected.
Comments
Post a Comment