sksurv.svm.FastKernelSurvivalSVM#
- class sksurv.svm.FastKernelSurvivalSVM(alpha=1, *, rank_ratio=1.0, fit_intercept=False, kernel='rbf', gamma=None, degree=3, coef0=1, kernel_params=None, max_iter=20, verbose=False, tol=None, optimizer=None, random_state=None, timeit=False)[source]#
Implements an efficient kernel Support Vector Machine for survival analysis.
The model extends
FastSurvivalSVMto non-linear relationships through kernel functions.See the User Guide and [1] for further description.
- Parameters:
alpha (float, default: 1) – Weight of penalizing the squared hinge loss in the objective function. Must be greater than 0.
rank_ratio (float, optional, default: 1.0) – Mixing parameter between regression and ranking objectives, with
0 <= rank_ratio <= 1. Ifrank_ratio = 1, only ranking is performed. Ifrank_ratio = 0, only regression is performed. Arank_ratioless than 1.0 (i.e., including a regression objective) is only supported if theoptimizeris ‘avltree’, ‘PRSVM’, or ‘rbtree’.fit_intercept (bool, optional, default: False) – Whether to calculate an intercept for the regression model. If set to
False, no intercept will be calculated. This parameter has no effect ifrank_ratio = 1, i.e., only ranking is performed.kernel (str or callable, default: 'rbf') – Kernel mapping used internally. This parameter is directly passed to
sklearn.metrics.pairwise.pairwise_kernels(). If kernel is a string, it must be one of the metrics in pairwise.PAIRWISE_KERNEL_FUNCTIONS or “precomputed”. If kernel is “precomputed”, X is assumed to be a kernel matrix. Alternatively, if kernel is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two rows from X as input and return the corresponding kernel value as a single number. This means that callables fromsklearn.metrics.pairwiseare not allowed, as they operate on matrices, not single samples. Use the string identifying the kernel instead.gamma (float, optional, default: None) – Gamma parameter for the RBF, laplacian, polynomial, exponential chi2 and sigmoid kernels. Interpretation of the default value is left to the kernel; see the documentation for
sklearn.metrics.pairwise. Ignored by other kernels.degree (int, optional, default: 3) – Degree of the polynomial kernel. Ignored by other kernels.
coef0 (float, optional, default: 1) – Zero coefficient for polynomial and sigmoid kernels. Ignored by other kernels.
kernel_params (dict or None, optional, default: None) – Additional parameters (keyword arguments) for kernel function passed as callable object.
max_iter (int, optional, default: 20) – Maximum number of iterations to perform in Newton optimization
verbose (bool, optional, default: False) – If
True, print messages during optimization.tol (float or None, optional, default: None) – Tolerance for termination. If
None, the solver’s default tolerance is used. Seescipy.optimize.minimize().optimizer ({'avltree', 'rbtree'}, optional, default: 'rbtree') – Specifies which optimizer to use..
random_state (int,
numpy.random.RandomStateinstance, or None, optional, default: None) – Used to resolve ties in survival times. Pass an int for reproducible output across multiplefit()calls.timeit (bool, int, or None, optional, default: False) – If
Trueor a non-zero integer, the time taken for optimization is measured. If an integer is provided, the optimization is repeated that many times. Results can be accessed from theoptimizer_result_attribute.
- coef_#
Weights assigned to the samples in training data to represent the decision function in kernel space.
- Type:
ndarray, shape = (n_samples,), dtype = float
- fit_X_#
Training data used for fitting. Used to compute the kernel matrix for prediction.
- Type:
ndarray, shape = (n_samples, n_features_in_), dtype = float
- optimizer_result_#
Stats returned by the optimizer. See
scipy.optimize.OptimizeResult.
- 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_,), dtype = object
- n_iter_#
Number of iterations run by the optimization routine to fit the model.
- Type:
int
See also
FastSurvivalSVMFast implementation for linear kernel.
References
- __init__(alpha=1, *, rank_ratio=1.0, fit_intercept=False, kernel='rbf', gamma=None, degree=3, coef0=1, kernel_params=None, max_iter=20, verbose=False, tol=None, optimizer=None, random_state=None, timeit=False)[source]#
Methods
__init__([alpha, rank_ratio, fit_intercept, ...])fit(X, y)Build a survival support vector machine model from training data.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
predict(X)Predict risk scores or transformed survival times.
score(X, y)Returns the concordance index of the prediction.
set_params(**params)Set the parameters of this estimator.
Attributes
- fit(X, y)[source]#
Build a survival support vector machine model from training data.
- Parameters:
X (array-like, shape = (n_samples, n_features)) – Data matrix.
y (structured array, shape = (n_samples,)) – A structured array with two fields. The first field is a boolean where
Trueindicates an event andFalseindicates right-censoring. The second field is a float with the time of event or time of censoring.
- Return type:
self
- 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
- predict(X)[source]#
Predict risk scores or transformed survival times.
If the model has been fit only considering the ranking objective (
rank_ratio = 1), predictions are risk scores (i.e. higher values indicate an increased risk of experiencing an event). The scores have no unit and are only meaningful to rank samples by their risk of experiencing an event.If the regression objective has been used (
rank_ratio < 1), predictions are transformed survival times. Lower scores indicate shorter survival, higher scores longer survival.- Parameters:
X (array-like, shape = (n_samples, n_features)) – The input samples.
- Returns:
y – Risk scores (if
rank_ratio = 1), or transformed survival times (ifrank_ratio < 1).- Return type:
ndarray, shape = (n_samples,), dtype=float
- score(X, y)[source]#
Returns the concordance index of the prediction.
- Parameters:
X (array-like, shape = (n_samples, n_features)) – Test samples.
y (structured array, shape = (n_samples,)) – A structured array containing the binary event indicator as first field, and time of event or time of censoring as second field.
- Returns:
cindex – Estimated concordance index.
- Return type:
float
See also
sksurv.metrics.concordance_index_censoredComputes the concordance index.
- 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