Confidence Intervals for Model Prediction

I follow statsmodels instructions

OLS model equipped

formula = ~ C(E) + C(M) + X' lm = ols(formula, salary_table).fit() print lm.summary() 

Predicted values ​​are provided through:

lm.predict({'X' : [12], 'M' : [1], 'E' : [2]})

The result is returned as a single array of values.

Is there a way to return confidence intervals for the predicted value (prediction intervals) in statsmodels?

Thanks.

+6
source share
2 answers

We wanted to make it easier. You should be able to use

 from statsmodels.sandbox.regression.predstd import wls_prediction_std prstd, iv_l, iv_u = wls_prediction_std(results) 

If you have any problems, report the problem on github.

+10
source

in addition, you can try using the get_prediction method.

 values_to_predict = pd.DataFrame({'X' : [12], 'M' : [1], 'E' : [2]}) predictions = result.get_prediction(values_to_predict) predictions.summary_frame(alpha=0.05) 

I found the summary_frame () method is similar to here , and you can find the get_prediction () method here . You can change the confidence level of the confidence interval and the prediction interval by changing the "alpha" parameter.

0
source

Source: https://habr.com/ru/post/943764/


All Articles