# sksurv.metrics.brier_score¶

sksurv.metrics.brier_score(survival_train, survival_test, estimate, times)[source]

Estimate the time-dependent Brier score for right censored data.

The time-dependent Brier score is the mean squared error at time point $$t$$:

$\mathrm{BS}^c(t) = \frac{1}{n} \sum_{i=1}^n I(y_i \leq t \land \delta_i = 1) \frac{(0 - \hat{\pi}(t | \mathbf{x}_i))^2}{\hat{G}(y_i)} + I(y_i > t) \frac{(1 - \hat{\pi}(t | \mathbf{x}_i))^2}{\hat{G}(t)} ,$

where $$\hat{\pi}(t | \mathbf{x})$$ is the predicted probability of remaining event-free up to time point $$t$$ for a feature vector $$\mathbf{x}$$, and $$1/\hat{G}(t)$$ is a inverse probability of censoring weight, estimated by the Kaplan-Meier estimator.

See [1] for details.

Parameters: survival_train (structured array, shape = (n_train_samples,)) – Survival times for training data to estimate the censoring distribution from. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field. survival_test (structured array, shape = (n_samples,)) – Survival times of test data. A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field. estimate (array-like, shape = (n_samples, n_times)) – Estimated risk of experiencing an event for test data at times. The i-th column must contain the estimated probability of remaining event-free up to the i-th time point. times (array-like, shape = (n_times,)) – The time points for which to estimate the Brier score. Values must be within the range of follow-up times of the test data survival_test. times (array, shape = (n_times,)) – Unique time points at which the brier scores was estimated. brier_scores (array , shape = (n_times,)) – Values of the brier score.

Examples

>>> from sksurv.datasets import load_gbsg2
>>> from sksurv.linear_model import CoxPHSurvivalAnalysis
>>> from sksurv.metrics import brier_score
>>> from sksurv.preprocessing import OneHotEncoder


Load and prepare data.

>>> X, y = load_gbsg2()
>>> Xt = OneHotEncoder().fit_transform(X)


Fit a Cox model.

>>> est = CoxPHSurvivalAnalysis(ties="efron").fit(Xt, y)


Retrieve individual survival functions and get probability of remaining event free up to 5 years (=1825 days).

>>> survs = est.predict_survival_function(Xt)
>>> preds = [fn(1825) for fn in survs]


Compute the Brier score at 5 years.

>>> times, score = brier_score(y, y, preds, 1825)
>>> print(score)
[0.20881843]


References

 [1] E. Graf, C. Schmoor, W. Sauerbrei, and M. Schumacher, “Assessment and comparison of prognostic classification schemes for survival data,” Statistics in Medicine, vol. 18, no. 17-18, pp. 2529–2545, 1999.