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 the User Guide and [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 probability of remaining event-free at time points specified by times. The value of estimate[i] must correspond to the estimated probability of remaining event-free up to the time point times[i]. Typically, estimated probabilities are obtained via the survival function returned by an estimator’s predict_survival_function method.

  • 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.

Returns:

  • 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()
>>> X.loc[:, "tgrade"] = X.loc[:, "tgrade"].map(len).astype(int)
>>> 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]

See also

integrated_brier_score

Computes the average Brier score over all time points.

References