scikit-survival 0.26.0__cp314-cp314-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. scikit_survival-0.26.0.dist-info/METADATA +185 -0
  2. scikit_survival-0.26.0.dist-info/RECORD +58 -0
  3. scikit_survival-0.26.0.dist-info/WHEEL +6 -0
  4. scikit_survival-0.26.0.dist-info/licenses/COPYING +674 -0
  5. scikit_survival-0.26.0.dist-info/top_level.txt +1 -0
  6. sksurv/__init__.py +183 -0
  7. sksurv/base.py +115 -0
  8. sksurv/bintrees/__init__.py +15 -0
  9. sksurv/bintrees/_binarytrees.cpython-314-darwin.so +0 -0
  10. sksurv/column.py +204 -0
  11. sksurv/compare.py +123 -0
  12. sksurv/datasets/__init__.py +12 -0
  13. sksurv/datasets/base.py +614 -0
  14. sksurv/datasets/data/GBSG2.arff +700 -0
  15. sksurv/datasets/data/actg320.arff +1169 -0
  16. sksurv/datasets/data/bmt.arff +46 -0
  17. sksurv/datasets/data/breast_cancer_GSE7390-metastasis.arff +283 -0
  18. sksurv/datasets/data/cgvhd.arff +118 -0
  19. sksurv/datasets/data/flchain.arff +7887 -0
  20. sksurv/datasets/data/veteran.arff +148 -0
  21. sksurv/datasets/data/whas500.arff +520 -0
  22. sksurv/docstrings.py +99 -0
  23. sksurv/ensemble/__init__.py +2 -0
  24. sksurv/ensemble/_coxph_loss.cpython-314-darwin.so +0 -0
  25. sksurv/ensemble/boosting.py +1564 -0
  26. sksurv/ensemble/forest.py +902 -0
  27. sksurv/ensemble/survival_loss.py +151 -0
  28. sksurv/exceptions.py +18 -0
  29. sksurv/functions.py +114 -0
  30. sksurv/io/__init__.py +2 -0
  31. sksurv/io/arffread.py +91 -0
  32. sksurv/io/arffwrite.py +181 -0
  33. sksurv/kernels/__init__.py +1 -0
  34. sksurv/kernels/_clinical_kernel.cpython-314-darwin.so +0 -0
  35. sksurv/kernels/clinical.py +348 -0
  36. sksurv/linear_model/__init__.py +3 -0
  37. sksurv/linear_model/_coxnet.cpython-314-darwin.so +0 -0
  38. sksurv/linear_model/aft.py +208 -0
  39. sksurv/linear_model/coxnet.py +592 -0
  40. sksurv/linear_model/coxph.py +637 -0
  41. sksurv/meta/__init__.py +4 -0
  42. sksurv/meta/base.py +35 -0
  43. sksurv/meta/ensemble_selection.py +724 -0
  44. sksurv/meta/stacking.py +370 -0
  45. sksurv/metrics.py +1028 -0
  46. sksurv/nonparametric.py +911 -0
  47. sksurv/preprocessing.py +195 -0
  48. sksurv/svm/__init__.py +11 -0
  49. sksurv/svm/_minlip.cpython-314-darwin.so +0 -0
  50. sksurv/svm/_prsvm.cpython-314-darwin.so +0 -0
  51. sksurv/svm/minlip.py +695 -0
  52. sksurv/svm/naive_survival_svm.py +249 -0
  53. sksurv/svm/survival_svm.py +1236 -0
  54. sksurv/testing.py +155 -0
  55. sksurv/tree/__init__.py +1 -0
  56. sksurv/tree/_criterion.cpython-314-darwin.so +0 -0
  57. sksurv/tree/tree.py +790 -0
  58. sksurv/util.py +416 -0
sksurv/testing.py ADDED
@@ -0,0 +1,155 @@
1
+ # This program is free software: you can redistribute it and/or modify
2
+ # it under the terms of the GNU General Public License as published by
3
+ # the Free Software Foundation, either version 3 of the License, or
4
+ # (at your option) any later version.
5
+ #
6
+ # This program is distributed in the hope that it will be useful,
7
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
8
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
+ # GNU General Public License for more details.
10
+ #
11
+ # You should have received a copy of the GNU General Public License
12
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
13
+ from contextlib import nullcontext
14
+ from importlib import import_module
15
+ from importlib.metadata import PackageNotFoundError, version
16
+ import inspect
17
+ from pathlib import Path
18
+ import pkgutil
19
+
20
+ import numpy as np
21
+ from numpy.testing import assert_almost_equal, assert_array_equal
22
+ from packaging.version import parse
23
+ import pandas as pd
24
+ import pytest
25
+ from sklearn.base import BaseEstimator, TransformerMixin
26
+
27
+ import sksurv
28
+ from sksurv.metrics import concordance_index_censored
29
+
30
+
31
+ def assert_cindex_almost_equal(event_indicator, event_time, estimate, expected):
32
+ result = concordance_index_censored(event_indicator, event_time, estimate)
33
+ assert_array_equal(result[1:], expected[1:])
34
+ concordant, discordant, tied_risk = result[1:4]
35
+ cc = (concordant + 0.5 * tied_risk) / (concordant + discordant + tied_risk)
36
+ assert_almost_equal(result[0], cc)
37
+ assert_almost_equal(result[0], expected[0])
38
+
39
+
40
+ def assert_survival_function_properties(surv_fns):
41
+ if not np.isfinite(surv_fns).all():
42
+ raise AssertionError("survival function contains values that are not finite")
43
+ if np.any(surv_fns < 0.0):
44
+ raise AssertionError("survival function contains negative values")
45
+ if np.any(surv_fns > 1.0):
46
+ raise AssertionError("survival function contains values larger 1")
47
+
48
+ d = np.apply_along_axis(np.diff, 1, surv_fns)
49
+ if np.any(d > 0):
50
+ raise AssertionError("survival functions are not monotonically decreasing")
51
+
52
+ # survival function at first time point
53
+ num_closer_to_zero = np.sum(1.0 - surv_fns[:, 0] >= surv_fns[:, 0])
54
+ if num_closer_to_zero / surv_fns.shape[0] > 0.5:
55
+ raise AssertionError(f"most ({num_closer_to_zero}) probabilities at first time point are closer to 0 than 1")
56
+
57
+ # survival function at last time point
58
+ num_closer_to_one = np.sum(1.0 - surv_fns[:, -1] < surv_fns[:, -1])
59
+ if num_closer_to_one / surv_fns.shape[0] > 0.5:
60
+ raise AssertionError(f"most ({num_closer_to_one}) probabilities at last time point are closer to 1 than 0")
61
+
62
+
63
+ def assert_chf_properties(chf):
64
+ if not np.isfinite(chf).all():
65
+ raise AssertionError("chf contains values that are not finite")
66
+ if np.any(chf < 0.0):
67
+ raise AssertionError("chf contains negative values")
68
+
69
+ d = np.apply_along_axis(np.diff, 1, chf)
70
+ if np.any(d < 0):
71
+ raise AssertionError("chf are not monotonically increasing")
72
+
73
+ # chf at first time point
74
+ num_closer_to_one = np.sum(1.0 - chf[:, 0] < chf[:, 0])
75
+ if num_closer_to_one / chf.shape[0] > 0.5:
76
+ raise AssertionError(f"most ({num_closer_to_one}) hazard rates at first time point are closer to 1 than 0")
77
+
78
+
79
+ def _is_survival_estimator(x):
80
+ return (
81
+ inspect.isclass(x)
82
+ and issubclass(x, BaseEstimator)
83
+ and not issubclass(x, TransformerMixin)
84
+ and x.__module__.startswith("sksurv.")
85
+ and not x.__name__.startswith("_")
86
+ and x.__module__.split(".", 2)[1] not in {"metrics", "nonparametric"}
87
+ )
88
+
89
+
90
+ def all_survival_estimators():
91
+ root = str(Path(sksurv.__file__).parent)
92
+ all_classes = []
93
+ for _importer, modname, _ispkg in pkgutil.walk_packages(path=[root], prefix="sksurv."):
94
+ # meta-estimators require base estimators
95
+ if modname.startswith("sksurv.meta"):
96
+ continue
97
+ module = import_module(modname)
98
+ for _name, cls in inspect.getmembers(module, _is_survival_estimator):
99
+ if inspect.isabstract(cls):
100
+ continue
101
+ all_classes.append(cls)
102
+ return set(all_classes)
103
+
104
+
105
+ class FixtureParameterFactory:
106
+ def get_cases(self):
107
+ cases = []
108
+ for name, func in inspect.getmembers(self):
109
+ if name.startswith("data_"):
110
+ values = func()
111
+ cases.append(pytest.param(*values, id=name))
112
+ return cases
113
+
114
+ def get_cases_func(self):
115
+ cases = []
116
+ for name, func in inspect.getmembers(self):
117
+ if name.startswith("data_"):
118
+ cases.append(pytest.param(func, id=name))
119
+ return cases
120
+
121
+
122
+ def check_module_minimum_version(module, version_str):
123
+ """
124
+ Check whether a module of a specified minimum version is available.
125
+
126
+ Parameters
127
+ ----------
128
+ module : str
129
+ Name of the module.
130
+ version_str : str
131
+ Minimum version of the module.
132
+
133
+ Returns
134
+ -------
135
+ available : bool
136
+ True if the module is available and its version is >= `version_str`.
137
+ """
138
+ try:
139
+ module_version = parse(version(module))
140
+ required_version = parse(version_str)
141
+ return module_version >= required_version
142
+ except PackageNotFoundError: # pragma: no cover
143
+ return False
144
+
145
+
146
+ def get_pandas_infer_string_context():
147
+ if check_module_minimum_version("pandas", "2.3.0"):
148
+ return (
149
+ pytest.param(pd.option_context("future.infer_string", False), id="infer_string=False"),
150
+ pytest.param(pd.option_context("future.infer_string", True), id="infer_string=True"),
151
+ )
152
+ return (
153
+ pytest.param(nullcontext(), id="pandas default options"),
154
+ pytest.param(nullcontext(), marks=pytest.mark.skip("no pandas 2.3.0")),
155
+ )
@@ -0,0 +1 @@
1
+ from .tree import ExtraSurvivalTree, SurvivalTree # noqa: F401