scikit-survival 0.26.0__cp314-cp314-macosx_10_15_x86_64.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
@@ -0,0 +1,195 @@
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
+ import pandas as pd
14
+ from pandas.api.types import CategoricalDtype, is_string_dtype
15
+ from sklearn.base import BaseEstimator, TransformerMixin
16
+ from sklearn.utils.validation import _check_feature_names, _check_feature_names_in, _check_n_features, check_is_fitted
17
+
18
+ from .column import encode_categorical
19
+
20
+ __all__ = ["OneHotEncoder"]
21
+
22
+
23
+ def check_columns_exist(actual, expected):
24
+ """Check if all expected columns are present in a dataframe.
25
+
26
+ Parameters
27
+ ----------
28
+ actual : pandas.Index
29
+ The actual columns of a dataframe.
30
+ expected : pandas.Index
31
+ The expected columns.
32
+
33
+ Raises
34
+ ------
35
+ ValueError
36
+ If any of the expected columns are missing from the actual columns.
37
+ """
38
+ missing_features = expected.difference(actual)
39
+ if len(missing_features) != 0:
40
+ raise ValueError(f"{len(missing_features)} features are missing from data: {missing_features.tolist()}")
41
+
42
+
43
+ class OneHotEncoder(BaseEstimator, TransformerMixin):
44
+ """Encode categorical features using a one-hot scheme.
45
+
46
+ This transformer only works on pandas DataFrames. It identifies columns
47
+ with `category` or `object` data type as categorical features.
48
+ The features are encoded using a one-hot (or dummy) encoding scheme, which
49
+ creates a binary column for each category. By default, one category per feature
50
+ is dropped. a column with `M` categories is encoded as `M-1` integer columns
51
+ according to the one-hot scheme.
52
+
53
+ The order of non-categorical columns is preserved. Encoded columns are inserted
54
+ in place of the original column.
55
+
56
+ Parameters
57
+ ----------
58
+ allow_drop : bool, optional, default: True
59
+ Whether to allow dropping categorical columns that only consist
60
+ of a single category.
61
+
62
+ Attributes
63
+ ----------
64
+ feature_names_ : pandas.Index
65
+ Names of categorical features that were encoded.
66
+
67
+ categories_ : dict
68
+ A dictionary mapping each categorical feature name to a list of its
69
+ categories.
70
+
71
+ encoded_columns_ : pandas.Index
72
+ The full list of feature names in the transformed output.
73
+
74
+ n_features_in_ : int
75
+ Number of features seen during ``fit``.
76
+
77
+ feature_names_in_ : ndarray, shape = (`n_features_in_`,)
78
+ Names of features seen during ``fit``. Defined only when `X`
79
+ has feature names that are all strings.
80
+ """
81
+
82
+ def __init__(self, *, allow_drop=True):
83
+ self.allow_drop = allow_drop
84
+
85
+ def fit(self, X, y=None): # pylint: disable=unused-argument
86
+ """Determine which features are categorical and should be one-hot encoded.
87
+
88
+ Parameters
89
+ ----------
90
+ X : pandas.DataFrame
91
+ The data to determine categorical features from.
92
+ y : None
93
+ Ignored. This parameter exists only for compatibility with
94
+ :class:`sklearn.pipeline.Pipeline`.
95
+
96
+ Returns
97
+ -------
98
+ self : object
99
+ Returns the instance itself.
100
+ """
101
+ self.fit_transform(X)
102
+ return self
103
+
104
+ def _encode(self, X, columns_to_encode):
105
+ return encode_categorical(X, columns=columns_to_encode, allow_drop=self.allow_drop)
106
+
107
+ def fit_transform(self, X, y=None, **fit_params): # pylint: disable=unused-argument
108
+ """Fit to data, then transform it.
109
+
110
+ Fits the transformer to ``X`` by identifying categorical features and
111
+ then returns a transformed version of ``X`` with categorical features
112
+ one-hot encoded.
113
+
114
+ Parameters
115
+ ----------
116
+ X : pandas.DataFrame
117
+ The data to fit and transform.
118
+ y : None, optional
119
+ Ignored. This parameter exists only for compatibility with
120
+ :class:`sklearn.pipeline.Pipeline`.
121
+ fit_params : dict, optional
122
+ Ignored. This parameter exists only for compatibility with
123
+ :class:`sklearn.pipeline.Pipeline`.
124
+
125
+ Returns
126
+ -------
127
+ Xt : pandas.DataFrame
128
+ The transformed data.
129
+ """
130
+ _check_feature_names(self, X, reset=True)
131
+ _check_n_features(self, X, reset=True)
132
+
133
+ def is_string_or_categorical_dtype(dtype):
134
+ return is_string_dtype(dtype) or isinstance(dtype, CategoricalDtype)
135
+
136
+ columns_to_encode = pd.Index(
137
+ [name for name, dtype in X.dtypes.items() if is_string_or_categorical_dtype(dtype)]
138
+ )
139
+ x_dummy = self._encode(X, columns_to_encode)
140
+
141
+ self.feature_names_ = columns_to_encode
142
+ cat_cols = {}
143
+ for col_name in columns_to_encode:
144
+ col = X[col_name]
145
+ if not isinstance(col.dtype, CategoricalDtype):
146
+ col = col.astype("category")
147
+ cat_cols[col_name] = col.cat.categories
148
+ self.categories_ = cat_cols
149
+ self.encoded_columns_ = x_dummy.columns.copy()
150
+ return x_dummy
151
+
152
+ def transform(self, X):
153
+ """Transform ``X`` by one-hot encoding categorical features.
154
+
155
+ Parameters
156
+ ----------
157
+ X : pandas.DataFrame
158
+ The data to transform.
159
+
160
+ Returns
161
+ -------
162
+ Xt : pandas.DataFrame
163
+ The transformed data.
164
+ """
165
+ check_is_fitted(self, "encoded_columns_")
166
+ _check_n_features(self, X, reset=False)
167
+ check_columns_exist(X.columns, self.feature_names_)
168
+
169
+ Xt = X.astype({col: CategoricalDtype(cat) for col, cat in self.categories_.items()})
170
+
171
+ new_data = self._encode(Xt, self.feature_names_)
172
+ return new_data.loc[:, self.encoded_columns_]
173
+
174
+ def get_feature_names_out(self, input_features=None):
175
+ """Get output feature names for transformation.
176
+
177
+ Parameters
178
+ ----------
179
+ input_features : array-like of str or None, default: None
180
+ Input features.
181
+
182
+ - If `input_features` is `None`, then `feature_names_in_` is
183
+ used as feature names in.
184
+ - If `input_features` is an array-like, then `input_features` must
185
+ match `feature_names_in_` if `feature_names_in_` is defined.
186
+
187
+ Returns
188
+ -------
189
+ feature_names_out : ndarray of str objects
190
+ Transformed feature names.
191
+ """
192
+ check_is_fitted(self, "encoded_columns_")
193
+ input_features = _check_feature_names_in(self, input_features)
194
+
195
+ return self.encoded_columns_.to_numpy(copy=True)
sksurv/svm/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ from .minlip import HingeLossSurvivalSVM, MinlipSurvivalAnalysis
2
+ from .naive_survival_svm import NaiveSurvivalSVM
3
+ from .survival_svm import FastKernelSurvivalSVM, FastSurvivalSVM
4
+
5
+ __all__ = [
6
+ "FastKernelSurvivalSVM",
7
+ "FastSurvivalSVM",
8
+ "HingeLossSurvivalSVM",
9
+ "MinlipSurvivalAnalysis",
10
+ "NaiveSurvivalSVM",
11
+ ]
Binary file
Binary file