sksurv.preprocessing.OneHotEncoder#

class sksurv.preprocessing.OneHotEncoder(*, allow_drop=True)[source]#

Encode categorical columns with M categories into M-1 columns according to the one-hot scheme.

The order of non-categorical columns is preserved, encoded columns are inserted inplace of the original column.

Parameters:

allow_drop (boolean, optional, default: True) – Whether to allow dropping categorical columns that only consist of a single category.

feature_names_#

List of encoded columns.

Type:

pandas.Index

categories_#

Categories of encoded columns.

Type:

dict

encoded_columns_#

Name of columns after encoding. Includes names of non-categorical columns.

Type:

list

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__(*, allow_drop=True)[source]#

Methods

__init__(*[, allow_drop])

fit(X[, y])

Retrieve categorical columns.

fit_transform(X[, y])

Convert categorical columns to numeric values.

get_feature_names_out([input_features])

Get output feature names for transformation.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Convert categorical columns to numeric values.

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

Retrieve categorical columns.

Parameters:
  • X (pandas.DataFrame) – Data to encode.

  • y – Ignored. For compatibility with Pipeline.

Returns:

self – Returns self

Return type:

object

fit_transform(X, y=None, **fit_params)#

Convert categorical columns to numeric values.

Parameters:
  • X (pandas.DataFrame) – Data to encode.

  • y – Ignored. For compatibility with TransformerMixin.

  • fit_params – Ignored. For compatibility with TransformerMixin.

Returns:

Xt – Encoded data.

Return type:

pandas.DataFrame

get_feature_names_out(input_features=None)[source]#

Get output feature names for transformation.

Parameters:

input_features (array-like of str or None, default=None) –

Input features.

  • If input_features is None, then feature_names_in_ is used as feature names in.

  • If input_features is an array-like, then input_features must match feature_names_in_ if feature_names_in_ is defined.

Returns:

feature_names_out – Transformed feature names.

Return type:

ndarray of str objects

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating 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

set_output(*, transform=None)#

Set output container.

See 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(X)#

Convert categorical columns to numeric values.

Parameters:

X (pandas.DataFrame) – Data to encode.

Returns:

Xt – Encoded data.

Return type:

pandas.DataFrame