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

Fit does not throw exception if negative event times are passed #406

Closed
sebp opened this issue Sep 17, 2023 Discussed in #404 · 0 comments · Fixed by #410
Closed

Fit does not throw exception if negative event times are passed #406

sebp opened this issue Sep 17, 2023 Discussed in #404 · 0 comments · Fixed by #410
Assignees
Labels

Comments

@sebp
Copy link
Owner

sebp commented Sep 17, 2023

CoxPHSurvivalAnalysis can be fit with negative observe time points. It only fails during prediction. However, by definition time should be non-negative and fit should throw an exception.

import numpy as np
from sksurv.linear_model.coxph import CoxPHSurvivalAnalysis
from sksurv.util import Surv

X = np.array([[1, 2, 3, 4, 5, 6, 7, 8]]).T
y = Surv.from_arrays(
    event=[True, False, False, True, True, True, True, False],
    time=[0, 1, 2, 3, 4, -1, 6, 7],
)

# successful
cph = CoxPHSurvivalAnalysis().fit(X, y)

# fails
cph.predict_survival_function(X[:2], return_array=True)
Traceback (most recent call last):
  File "/home/sebp/Projekte/scikit-survival/cph_neg.py", line 15, in <module>
    cph.predict_survival_function(X[:2], return_array=True)
  File "/home/sebp/Projekte/scikit-survival/sksurv/linear_model/coxph.py", line 618, in predict_survival_function
    return self._predict_survival_function(self._baseline_model, self.predict(X), return_array)
  File "/home/sebp/Projekte/scikit-survival/sksurv/base.py", line 49, in _predict_survival_function
    return self._predict_function("get_survival_function", baseline_model, prediction, return_array)
  File "/home/sebp/Projekte/scikit-survival/sksurv/base.py", line 26, in _predict_function
    arr[i, :] = fn(times)
  File "/home/sebp/Projekte/scikit-survival/sksurv/functions.py", line 95, in __call__
    raise ValueError(f"x must be within [{self.domain[0]:f}; {self.domain[1]:f}]")
ValueError: x must be within [0.000000; 7.000000]

Discussed in #404

@sebp sebp added the bug label Sep 17, 2023
@sebp sebp self-assigned this Sep 17, 2023
sebp added a commit that referenced this issue Oct 1, 2023
sebp added a commit that referenced this issue Oct 1, 2023
@sebp sebp closed this as completed in #410 Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant