Prediction intervals for OLS's model.predict() without using wls_prediction_std

瀏覽次數:239 次
跳到第一則未讀訊息

James

未讀,
2017年8月17日 下午5:15:252017/8/17
收件者:pystatsmodels
I feel I might be missing something obvious here, but is there an easy way to output a model's prediction with PIs for some new input without using wls_prediction_std? I am using a very simple OLS model, code to help my explanation is here:

model = sm.OLS.from_formula('mpg ~ horsepower', df)
model
= model.fit()
x_pred
= pd.DataFrame(data=[98],columns=['horsepower'])
print(model.predict(x_pred))

This yields a single predicted value, however I am interested in knowing the values at the 95% prediction interval. As mentioned I know there is a way to do this with wls_prediction_std as follows:

bias = pd.Series(np.ones(shape=(len(x_pred))))
x_pred
= pd.concat([bias,x_pred],axis=1)
print(x_pred)
print(wls_prediction_std(model, exog=x_pred.values))

However this clearly doesn't work very seamlessly with the OLS functionality (e.g. compared to the methods of RegressionResults). Is there a method in RegressionResults that I've missed?

josef...@gmail.com

未讀,
2017年8月17日 下午5:26:132017/8/17
收件者:pystatsmodels
There is a not well advertised and maybe still experimental method that works the same as predict but returns a prediction results instance with standard errors and confidence and prediction intervala.

Josef
回覆所有人
回覆作者
轉寄
0 則新訊息