sksurv.column.encode_categorical#
- sksurv.column.encode_categorical(table, columns=None, **kwargs)[source]#
One-hot encode categorical features.
This function creates a binary column for each category and, by default, drops one of the categories per feature: a column with M categories is encoded as M-1 integer columns according to the one-hot scheme.
- Parameters:
table (pandas.DataFrame or pandas.Series) – Data with categorical columns to encode.
columns (list-like, optional, default: None) – Column names in the DataFrame to be encoded. If columns is None, all columns with object or category dtype will be converted. This parameter is ignored if table is a pandas.Series.
allow_drop (bool, optional, default: True) – Whether to allow dropping categorical columns that only consist of a single category.
- Returns:
encoded – The transformed data with categorical columns encoded as numeric. Numeric columns in the input table remain unchanged.
- Return type: