sksurv.kernels.ClinicalKernelTransform#
- class sksurv.kernels.ClinicalKernelTransform(*, fit_once=False, ordinal_categories=None, _numeric_ranges=None, _numeric_columns=None, _nominal_columns=None)[source]#
Transform data using a clinical Kernel
The clinical kernel distinguishes between continuous ordinal, and nominal variables.
See [1] for further description.
fitandtransformmust be called with the same dataframe library. Passing a pandas input to one and a polars input to the other raisesTypeError.- Parameters:
fit_once (bool, optional) – If set to
True, fit() does only transform the training data, but not update its internal state. You should call prepare() once before calling transform(). In this mode, fit() expects the prepared numeric array and rejects a pandas or polars DataFrame with aTypeError; call prepare(X) with the DataFrame first. If set toFalse, it behaves like a regular estimator, i.e., you need to call fit() before transform().ordinal_categories (mapping of str to sequence of labels, optional) – Columns to treat as ordinal, mapped to their category order, e.g.
{"stage": ["I", "II", "III", "IV"]}. Backend-independent. pandasCategorical(ordered=True)columns are additionally auto-detected.
- n_features_in_#
Number of features seen during
fit.- Type:
int
- feature_names_in_#
Names of features seen during
fit. Defined only when X has feature names that are all strings.- Type:
ndarray, shape = (n_features_in_,)
References
- __init__(*, fit_once=False, ordinal_categories=None, _numeric_ranges=None, _numeric_columns=None, _nominal_columns=None)[source]#
Methods
__init__(*[, fit_once, ordinal_categories, ...])fit(X[, y])Determine transformation parameters from data in X.
fit_transform(X[, y])Fit to data, then transform it.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
pairwise_kernel(X, Y)Function to use with
sklearn.metrics.pairwise.pairwise_kernels().prepare(X)Determine transformation parameters from data in X.
set_output(*[, transform])Set output container.
set_params(**params)Set the parameters of this estimator.
transform(Y)Compute all pairwise distances between self.X_fit_ and Y.
- fit(X, y=None, **kwargs)[source]#
Determine transformation parameters from data in X.
Subsequent calls to transform(Y) compute the pairwise distance to X. Parameters of the clinical kernel are only updated if fit_once is False, otherwise you have to explicitly call prepare() once.
- Parameters:
X (pandas.DataFrame or polars.DataFrame, shape = (n_samples, n_features)) – Data to estimate parameters from.
y (None) – Ignored. This parameter exists only for compatibility with
sklearn.pipeline.Pipeline.kwargs (dict) – Ignored. This parameter exists only for compatibility with
sklearn.pipeline.Pipeline.
- Returns:
self – Returns the instance itself.
- Return type:
object
- fit_transform(X, y=None, **fit_params)#
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).
**fit_params (dict) – Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.
- Returns:
X_new – Transformed array.
- Return type:
ndarray array of shape (n_samples, n_features_new)
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequestencapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
params – Parameter names mapped to their values.
- Return type:
dict
- pairwise_kernel(X, Y)[source]#
Function to use with
sklearn.metrics.pairwise.pairwise_kernels().- Parameters:
X (ndarray, shape = (n_features,))
Y (ndarray, shape = (n_features,))
- Returns:
similarity – Similarities are normalized to be within [0, 1].
- Return type:
float
- prepare(X)[source]#
Determine transformation parameters from data in X.
Use if fit_once is True, in which case fit() does not set the parameters of the clinical kernel.
- Parameters:
X (pandas.DataFrame or polars.DataFrame, shape = (n_samples, n_features)) – Data to estimate parameters from.
- set_output(*, transform=None)#
Set output container.
Refer to the user guide for more details and Introducing the set_output API for an example on how to use the API.
- Parameters:
transform ({"default", "pandas", "polars"}, default=None) –
Configure output of transform and fit_transform.
”default”: Default output format of a transformer
”pandas”: DataFrame output
”polars”: Polars output
None: Transform configuration is unchanged
Added in version 1.4: “polars” option was added.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- transform(Y)#
Compute all pairwise distances between self.X_fit_ and Y.
- Parameters:
Y (array-like, shape = (n_samples_y, n_features))
- Returns:
kernel – Kernel matrix. Values are normalized to lie within [0, 1].
- Return type:
ndarray, shape = (n_samples_y, n_samples_X_fit_)