简体   繁体   English

模型预测的置信区间

[英]Confidence intervals for model prediction

I am following along with a statsmodels tutorial 我正在关注statsmodels教程

An OLS model is fitted with 配有OLS型号

formula = 'S ~ 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 value array. 结果作为单值数组返回。

Is there a method to also return confidence intervals for the predicted value (prediction intervals) in statsmodels? 是否有一种方法可以返回statsmodels中预测值(预测区间)的置信区间?

Thanks. 谢谢。

We've been meaning to make this easier to get to. 我们的意思是让这更容易。 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, please file an issue on github. 如果您有任何问题,请在github上提出问题。

additionally you can try to use the get_prediction method. 另外,您可以尝试使用get_prediction方法。

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 buried here and you can find the get_prediction() method here . 我发现summary_frame()方法埋在这里 ,你可以找到get_prediction()方法在这里 You can change the significance level of the confidence interval and prediction interval by modifying the "alpha" parameter. 您可以通过修改“alpha”参数来更改置信区间和预测区间的显着性级别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM