bartz.ScoreKind

class bartz.ScoreKind(*values)[source]

Kind of score computed by Bart.score.

The shapes are for multivariate outcomes with k components, at m test points, with ndpost = num_chains * n_save posterior samples. For univariate outcomes, drop the k axis. The kinds loglik, lpd, mlpd, and logloss are available only for univariate outcomes, use their _joint or _marginal variants for multivariate outcomes. The kinds based on the density of the outcome (loglik*, lpd*, mlpd*, logloss) and brier require target='outcome'.

In the formulas, \(s = 1, \ldots, S\) indexes the posterior samples, \(i = 1, \ldots, m\) the test points, and \(j = 1, \ldots, k\) the outcome components (dropped if univariate). \(y_{ji}\) is truth, \(p_s\) the density of the outcome given the parameters in sample \(s\) (the probability for binary components), \(F_{ji}\) the cumulative distribution function (cdf) of the posterior of the target, and \([\cdot]\) is 1 if the condition holds and 0 otherwise. The expectations over the posterior are exact averages over the samples.

For the outcome, \(F_{ji}\) is the posterior predictive, the mixture of the distributions of the outcome given the parameters in the samples. For the mean and the latent, it’s the empirical cdf interpolation defined as the inverse of numpy.quantile(..., method='hazen').

loglik = 'loglik'[source]

Range (-∞, ∞), or (-∞, 0] for a binary outcome, higher is better, shape (ndpost, m). Univariate only.

Log likelihood of each test point under each posterior sample.

\[\log p_s(y_i)\]
loglik_joint = 'loglik_joint'[source]

Range (-∞, ∞), or (-∞, 0] if all outcome components are binary, higher is better, shape (ndpost, m).

ScoreKind.loglik with the density joint across the outcome components.

\[\log p_s(y_{1i}, \ldots, y_{ki})\]
loglik_marginal = 'loglik_marginal'[source]

Range (-∞, ∞), or (-∞, 0] on binary components, higher is better, shape (ndpost, k, m).

ScoreKind.loglik with the marginal density of each outcome component. The marginalization is over the other components, given the parameters, so this is not the marginal likelihood of Bayesian model comparison.

\[\log p_s(y_{ji})\]
lpd = 'lpd'[source]

Range (-∞, ∞), or (-∞, 0] for a binary outcome, higher is better, shape (m,). Univariate only.

Log predictive density of each test point, i.e., the log of the posterior mean of the likelihood.

\[\log \frac1S \sum_{s=1}^S p_s(y_i)\]
lpd_joint = 'lpd_joint'[source]

Range (-∞, ∞), or (-∞, 0] if all outcome components are binary, higher is better, shape (m,).

ScoreKind.lpd with the density joint across the outcome components.

\[\log \frac1S \sum_{s=1}^S p_s(y_{1i}, \ldots, y_{ki})\]
lpd_marginal = 'lpd_marginal'[source]

Range (-∞, ∞), or (-∞, 0] on binary components, higher is better, shape (k, m).

ScoreKind.lpd with the marginal density of each outcome component, see ScoreKind.loglik_marginal.

\[\log \frac1S \sum_{s=1}^S p_s(y_{ji})\]
mlpd = 'mlpd'[source]

Range (-∞, ∞), or (-∞, 0] for a binary outcome, higher is better, scalar. Univariate only.

Mean log predictive density, the average of ScoreKind.lpd over the test points.

\[\frac1m \sum_{i=1}^m \log \frac1S \sum_{s=1}^S p_s(y_i)\]
mlpd_joint = 'mlpd_joint'[source]

Range (-∞, ∞), or (-∞, 0] if all outcome components are binary, higher is better, scalar.

Average of ScoreKind.lpd_joint over the test points.

\[\frac1m \sum_{i=1}^m \log \frac1S \sum_{s=1}^S p_s(y_{1i}, \ldots, y_{ki})\]
mlpd_marginal = 'mlpd_marginal'[source]

Range (-∞, ∞), or (-∞, 0] on binary components, higher is better, shape (k,).

Average of ScoreKind.lpd_marginal over the test points.

\[\frac1m \sum_{i=1}^m \log \frac1S \sum_{s=1}^S p_s(y_{ji})\]
logloss = 'logloss'[source]

Range [0, ∞), lower is better, scalar. Univariate binary only.

Log loss, or cross-entropy, of the predicted probabilities predict(kind='mean'). It’s the negative of ScoreKind.mlpd.

\[-\frac1m \sum_{i=1}^m \left(y_i \log \hat p_i + (1 - y_i) \log(1 - \hat p_i)\right), \qquad \hat p_i = \frac1S \sum_{s=1}^S p_s(y_i = 1)\]
mse = 'mse'[source]

Range [0, ∞), lower is better, shape (k,).

Mean squared error of the posterior mean of the target, which is predict(kind='mean') with target='outcome' or 'mean'.

\[\frac1m \sum_{i=1}^m \left(y_{ji} - \hat y_{ji}\right)^2, \qquad \hat y_{ji} = \int t \,\mathrm dF_{ji}(t)\]
rmse = 'rmse'[source]

Range [0, ∞), lower is better, shape (k,).

Square root of ScoreKind.mse.

\[\sqrt{\frac1m \sum_{i=1}^m \left(y_{ji} - \hat y_{ji}\right)^2}\]
r2 = 'r2'[source]

Range (-∞, 1], higher is better, shape (k,).

Coefficient of determination, the fraction of the variance of truth across the test points explained by the posterior mean of the target, with \(\hat y_{ji}\) as in ScoreKind.mse.

\[1 - \frac{\sum_{i=1}^m (y_{ji} - \hat y_{ji})^2} {\sum_{i=1}^m (y_{ji} - \bar y_j)^2}, \qquad \bar y_j = \frac1m \sum_{i=1}^m y_{ji}\]
brier = 'brier'[source]

Range [0, 1], lower is better, shape (k,), NaN on continuous components.

Brier score, the ScoreKind.mse of the predicted probabilities of the binary components.

\[\frac1m \sum_{i=1}^m \left(y_{ji} - \hat p_{ji}\right)^2, \qquad \hat p_{ji} = \frac1S \sum_{s=1}^S p_s(y_{ji} = 1)\]
crps = 'crps'[source]

Range [0, ∞), lower is better, shape (k,).

Continuous ranked probability score, the integrated squared difference between the cumulative distribution function of the posterior of the target and a step at truth, averaged over the test points. With target='outcome', it equals ScoreKind.brier on binary components, and its cost is quadratic in the number of posterior samples. With target='mean' or 'latent', \(F_{ji}\) is the plain empirical distribution of the samples, without interpolation.

\[\frac1m \sum_{i=1}^m \int_{-\infty}^\infty \mathrm dt \left(F_{ji}(t) - [t \ge y_{ji}]\right)^2\]
pit = 'pit'[source]

Range [0, 1], ideally uniform across the test points, shape (k, m), NaN on binary components with target='outcome'.

Probability integral transform, the cumulative distribution function of the posterior of the target evaluated at truth. If the posterior is calibrated, it’s uniformly distributed across the test points.

\[F_{ji}(y_{ji})\]
coverage = 'coverage'[source]

Range [0, 1], ideally equal to level, shape (k,), NaN on binary components with target='outcome'.

Fraction of test points where truth lies in the equal-tailed interval of the posterior of the target with probability level, i.e., between its quantiles at (1 - level) / 2 and (1 + level) / 2.

\[\frac1m \sum_{i=1}^m \left[ F_{ji}^{-1}\left(\frac{1 - \mathtt{level}}2\right) \le y_{ji} \le F_{ji}^{-1}\left(\frac{1 + \mathtt{level}}2\right) \right]\]