arviz.waic#
- arviz.waic(data, pointwise=None, var_name=None, scale=None, dask_kwargs=None)[source]#
Compute the widely applicable information criterion.
Estimates the expected log pointwise predictive density (elpd) using WAIC. Also calculates the WAIC’s standard error and the effective number of parameters. Read more theory here https://arxiv.org/abs/1507.04544 and here https://arxiv.org/abs/1004.2316
- Parameters
- data: obj
Any object that can be converted to an
arviz.InferenceData
object. Refer to documentation ofarviz.convert_to_inference_data()
for details.- pointwise: bool
If True the pointwise predictive accuracy will be returned. Defaults to
stats.ic_pointwise
rcParam.- var_namestr, optional
The name of the variable in log_likelihood groups storing the pointwise log likelihood data to use for waic computation.
- scale: str
Output scale for WAIC. Available options are:
log : (default) log-score
negative_log : -1 * log-score
deviance : -2 * log-score
A higher log-score (or a lower deviance or negative log_score) indicates a model with better predictive accuracy.
- dask_kwargsdict, optional
Dask related kwargs passed to
wrap_xarray_ufunc()
.
- Returns
- ELPDData object (inherits fromclass:pandas.Series) with the following row/attributes:
- waic: approximated expected log pointwise predictive density (elpd)
- waic_se: standard error of waic
- p_waic: effective number parameters
- var_warn: bool
True if posterior variance of the log predictive densities exceeds 0.4
- waic_i:class:~xarray.DataArray with the pointwise predictive accuracy,
only if pointwise=True
- waic_scale: scale of the reported waic results
The returned object has a custom print method that overrides pd.Series method.
See also
loo
Compute Pareto-smoothed importance sampling leave-one-out cross-validation (PSIS-LOO-CV).
compare
Compare models based on PSIS-LOO-CV or WAIC.
plot_compare
Summary plot for model comparison.
Examples
Calculate WAIC of a model:
In [1]: import arviz as az ...: data = az.load_arviz_data("centered_eight") ...: az.waic(data) ...: Out[1]: Computed from 2000 posterior samples and 8 observations log-likelihood matrix. Estimate SE elpd_waic -30.76 1.42 p_waic 0.90 -
Calculate WAIC of a model and return the pointwise values:
In [2]: data_waic = az.waic(data, pointwise=True) ...: data_waic.waic_i ...: Out[2]: <xarray.DataArray 'waic_i' (school: 8)> array([-4.91534201, -3.41568055, -3.85543363, -3.46533901, -3.40121364, -3.4765078 , -4.27523419, -3.95322615]) Coordinates: * school (school) object 'Choate' 'Deerfield' ... "St. Paul's" 'Mt. Hermon'