Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Downcast time points passed to brier_score #349

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sksurv/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _check_inputs(event_indicator, event_time, estimate):


def _check_times(test_time, times):
times = check_array(np.atleast_1d(times), ensure_2d=False, dtype=test_time.dtype, input_name="times")
times = check_array(np.atleast_1d(times), ensure_2d=False, input_name="times")
times = np.unique(times)

if times.max() >= test_time.max() or times.min() < test_time.min():
Expand Down
22 changes: 22 additions & 0 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,28 @@ def test_brier_coxph():
assert round(abs(score[0] - 0.208817407492645), 5) == 0


def test_brier_score_int_dtype():
times = np.arange(30, dtype=int)
rnd = np.random.RandomState(1)
times = rnd.choice(times, 20)

y_int = np.empty(20, dtype=[("event", bool), ("time", int)])
y_int["event"] = np.ones(20, dtype=bool)
y_int["event"][:10] = False
y_int["time"] = times

pred = rnd.randn(20, 10)
tp = np.linspace(1.0, 2.0, 10)
_, bs_int = brier_score(y_int, y_int, pred, times=tp)

y_float = np.empty(20, dtype=[("event", bool), ("time", float)])
y_float["event"][:] = y_int["event"]
y_float["time"][:] = y_int["time"]
_, bs_float = brier_score(y_float, y_float, pred, times=tp)

assert_array_almost_equal(bs_float, bs_int)


def test_ibs_nottingham_1(nottingham_prognostic_index):
times = np.linspace(365, 1825, 5) # t=1..5 years
preds, y = nottingham_prognostic_index(times)
Expand Down