sksurv.meta.Stacking#

class sksurv.meta.Stacking(meta_estimator, base_estimators, probabilities=True)[source]#

Meta estimator that combines multiple base learners.

By default, base estimators’ output corresponds to the array returned by predict_proba. If predict_proba is not available or probabilities = False, the output of predict is used.

Parameters
  • meta_estimator (instance of estimator) – The estimator that is used to combine the output of different base estimators.

  • base_estimators (list) – List of (name, estimator) tuples (implementing fit/predict) that are part of the ensemble.

  • probabilities (bool, optional, default: True) – Whether to allow using predict_proba method of base learners, if available.

estimators_#

The elements of the estimators parameter, having been fitted on the training data.

Type

list of estimators

named_estimators_#

Attribute to access any fitted sub-estimators by name.

Type

dict

final_estimator_#

The estimator which combines the output of estimators_.

Type

estimator

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 of shape (n_features_in_,)

__init__(meta_estimator, base_estimators, probabilities=True)[source]#

Methods

__init__(meta_estimator, base_estimators[, ...])

fit(X[, y])

Fit base estimators.

get_params([deep])

Get the parameters of an estimator from the ensemble.

predict(X)

Perform prediction.

predict_log_proba(X)

Perform prediction.

predict_proba(X)

Perform prediction.

score(X, y)

Returns the concordance index of the prediction.

set_params(**params)

Set the parameters of an estimator from the ensemble.

Attributes

steps

fit(X, y=None, **fit_params)[source]#

Fit base estimators.

Parameters
  • X (array-like, shape = (n_samples, n_features)) – Training data.

  • y (array-like, optional) – Target data if base estimators are supervised.

Return type

self

get_params(deep=True)[source]#

Get the parameters of an estimator from the ensemble.

Returns the parameters given in the constructor as well as the estimators contained within the estimators parameter.

Parameters

deep (bool, default=True) – Setting it to True gets the various estimators and the parameters of the estimators as well.

Returns

params – Parameter and estimator names mapped to their values or parameter names mapped to their values.

Return type

dict

predict(X)#

Perform prediction.

Only available of the meta estimator has a predict method.

Parameters

X (array-like, shape = (n_samples, n_features)) – Data with samples to predict.

Returns

prediction – Prediction of meta estimator that combines predictions of base estimators. n_dim depends on the return value of meta estimator’s predict method.

Return type

array, shape = (n_samples, n_dim)

predict_log_proba(X)#

Perform prediction.

Only available of the meta estimator has a predict_log_proba method.

Parameters

X (array-like, shape = (n_samples, n_features)) – Data with samples to predict.

Returns

prediction – Prediction of meta estimator that combines predictions of base estimators. n_dim depends on the return value of meta estimator’s predict method.

Return type

ndarray, shape = (n_samples, n_dim)

predict_proba(X)#

Perform prediction.

Only available of the meta estimator has a predict_proba method.

Parameters

X (array-like, shape = (n_samples, n_features)) – Data with samples to predict.

Returns

prediction – Prediction of meta estimator that combines predictions of base estimators. n_dim depends on the return value of meta estimator’s predict method.

Return type

ndarray, shape = (n_samples, n_dim)

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

set_params(**params)[source]#

Set the parameters of an estimator from the ensemble.

Valid parameter keys can be listed with get_params(). Note that you can directly set the parameters of the estimators contained in estimators.

Parameters

**params (keyword arguments) – Specific parameters using e.g. set_params(parameter_name=new_value). In addition, to setting the parameters of the estimator, the individual estimator of the estimators can also be set, or can be removed by setting them to ‘drop’.

Returns

self – Estimator instance.

Return type

object