d***@cimenviro.com
2018-11-14 22:10:59 UTC
Hi
I'm an R user moving to python so I've been learning the statsmodel api.
I'm having difficulty accessing the endog data after doing a prediction
i.e.
ols = smf.ols("np.log(demand) ~ temperature", data=train_data).fit()
y_train_pred = ols.predict(train_data)
y_train = ols.model.endog
print('train error (rmse): \n', np.round(np.sqrt(ols.mse_resid), 2))
y_test_pred = ols.predict(test_data)
y_test = ols.model.endog
print('test error (rmse): \n',
np.round(np.sqrt(smt.eval_measures.mse(y_test, y_test_pred)), 2))
In the last block, y_test is incorrect as ols.model contains the orginal
fitted values. I've specifically transformed endog in the example to show
why it's important to access the predicted endog rather than use
test_data.demand, but it's also important if ols.predict() drops any rows
i.e. due to NA's
In R for example predict() returns a predict object containing the endog /
exog and fitted values using the original data and predict(newdata) updates
endog / exog and fitted. Is there some way of doing this with statsmodel?
Regards
David
I'm an R user moving to python so I've been learning the statsmodel api.
I'm having difficulty accessing the endog data after doing a prediction
i.e.
ols = smf.ols("np.log(demand) ~ temperature", data=train_data).fit()
y_train_pred = ols.predict(train_data)
y_train = ols.model.endog
print('train error (rmse): \n', np.round(np.sqrt(ols.mse_resid), 2))
y_test_pred = ols.predict(test_data)
y_test = ols.model.endog
print('test error (rmse): \n',
np.round(np.sqrt(smt.eval_measures.mse(y_test, y_test_pred)), 2))
In the last block, y_test is incorrect as ols.model contains the orginal
fitted values. I've specifically transformed endog in the example to show
why it's important to access the predicted endog rather than use
test_data.demand, but it's also important if ols.predict() drops any rows
i.e. due to NA's
In R for example predict() returns a predict object containing the endog /
exog and fitted values using the original data and predict(newdata) updates
endog / exog and fitted. Is there some way of doing this with statsmodel?
Regards
David