bartz.ScoreKind¶
- class bartz.ScoreKind(*values)[source]¶
Kind of score computed by
Bart.score.The shapes are for multivariate outcomes with
kcomponents, atmtest points, withndpost = num_chains * n_saveposterior samples. For univariate outcomes, drop thekaxis. The kindsloglik,lpd,mlpd, andloglossare available only for univariate outcomes, use their_jointor_marginalvariants for multivariate outcomes. The kinds based on the density of the outcome (loglik*,lpd*,mlpd*,logloss) andbrierrequiretarget='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 thetarget, 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.loglikwith 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.loglikwith 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.lpdwith 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.lpdwith the marginal density of each outcome component, seeScoreKind.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.lpdover 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_jointover 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_marginalover 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 ofScoreKind.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 ispredict(kind='mean')withtarget='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
truthacross the test points explained by the posterior mean of thetarget, with \(\hat y_{ji}\) as inScoreKind.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.mseof 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
targetand a step attruth, averaged over the test points. Withtarget='outcome', it equalsScoreKind.brieron binary components, and its cost is quadratic in the number of posterior samples. Withtarget='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 withtarget='outcome'.Probability integral transform, the cumulative distribution function of the posterior of the
targetevaluated attruth. 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 withtarget='outcome'.Fraction of test points where
truthlies in the equal-tailed interval of the posterior of thetargetwith probabilitylevel, i.e., between its quantiles at(1 - level) / 2and(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]\]