Skip to content

Commit

Permalink
Adding Inline example for psislw and r2_score. (#1129)
Browse files Browse the repository at this point in the history
* Added inline example

* remove extra space

* update CHANGELOG.md

* address review comments

* added reference
  • Loading branch information
smit-s authored Apr 8, 2020
1 parent 6383820 commit c2b80b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Add classifier to `setup.py` including Matplotlib framework (#1133)
* Image thumbs generation updated to be Bokeh 2 compatible (#1116)
* Add new examples for `plot_pair` (#1110)

* Add examples for `psislw` and `r2_score` (#1129)

## v0.7.0 (2020 Mar 2)

Expand Down
29 changes: 29 additions & 0 deletions arviz/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,22 @@ def psislw(log_weights, reff=1.0):
Smoothed log weights
kss : array
Pareto tail indices
References
----------
* Vehtari et al. (2015) see https://arxiv.org/abs/1507.02646
Examples
--------
Get Pareto smoothed importance sampling (PSIS) log weights:
.. ipython::
In [1]: import arviz as az
...: data = az.load_arviz_data("centered_eight")
...: log_likelihood = data.sample_stats.log_likelihood.stack(sample=("chain", "draw"))
...: az.psislw(-log_likelihood, reff=0.8)
"""
if hasattr(log_weights, "sample"):
n_samples = len(log_weights.sample)
Expand Down Expand Up @@ -874,6 +890,19 @@ def r2_score(y_true, y_pred):
Pandas Series with the following indices:
r2: Bayesian R²
r2_std: standard deviation of the Bayesian R².
Examples
--------
Calculate R² for Bayesian regression models :
.. ipython::
In [1]: import arviz as az
...: data = az.load_arviz_data('regression1d')
...: y_true = data.observed_data["y"].values
...: y_pred = data.posterior_predictive.stack(sample=("chain", "draw"))["y"].values.T
...: az.r2_score(y_true, y_pred)
"""
_numba_flag = Numba.numba_flag
if y_pred.ndim == 1:
Expand Down

0 comments on commit c2b80b7

Please sign in to comment.