Skip to main content

LabelEncoder

Converter
DashAI.back.converters.scikit_learn.LabelEncoder

Encode categorical labels as contiguous integer codes in [0, n_classes - 1].

Each unique label value is mapped to a unique integer in ascending order of the sorted class list. For example, given classes ["cat", "dog", "fish"] the mapping is cat -> 0, dog -> 1, fish -> 2.

Unlike OrdinalEncoder (which operates on feature columns), LabelEncoder is designed for target label columns. It is typically applied to the output column before training classifiers that require numeric class indices (e.g. gradient-boosted trees, support vector machines, or any model that indexes a class-weight array). The DashAI implementation extends the sklearn behaviour to support multiple columns and to preserve NaN values during transformation.

References​

Parameters​

handle_unknown : string, default=error
Whether to raise an error or encode as -1 a label not seen during fit.

Methods​

fit(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None)

Defined on LabelEncoder

Fit a LabelEncoder for each eligible column in the dataset.

Parameters

x : DashAIDataset
Input dataset whose categorical/string columns will be encoded.
y : DashAIDataset or None, optional
Ignored. Present for API compatibility. Default None.

Returns

LabelEncoderConverter
The fitted converter instance (self).

get_output_type(self, column_name: str = None) -> DashAI.back.types.dashai_data_type.DashAIDataType

Defined on LabelEncoder

Return the DashAI data type produced by this converter for a column.

Parameters

column_name : str, optional
Not used. Defaults to None.

Returns

DashAIDataType
An Integer type backed by pyarrow.int64(), representing the contiguous integer label codes produced by the encoder.

transform(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'DashAIDataset'

Defined on LabelEncoder

Apply fitted label encoders and append encoded columns with a prefix.

Parameters

x : DashAIDataset
Input dataset. Columns not seen during fit are left unchanged.
y : DashAIDataset or None, optional
Ignored. Present for API compatibility. Default None.

Returns

DashAIDataset
Dataset with original columns preserved plus new encoded_* columns appended containing the integer label codes.

unseen_values(self, x: 'DashAIDataset') -> Dict[str, List[str]]

Defined on LabelEncoder

The labels of each fitted column of x that fit did not see.

Parameters

x : DashAIDataset
Rows of the converter's scope, as transform would get them.

Returns

dict
Column name to its unseen labels as sorted strings, only for the columns that have any.

build_report(self, data: 'Dict[str, Any]') -> 'Dict[str, Any]'

Defined on BaseConverter

Wrap converter-specific data with the producer converter name.

get_credential(self, name: str)

Defined on ConfigObject

Resolve a registered credential component by name.

Parameters

name : str
Credential component class name (e.g. "HuggingFaceCredential").

Returns

BaseCredential
An instance of the requested credential component.

get_metadata(cls) -> 'Dict[str, Any]'

Defined on BaseConverter

Get metadata for the converter, used by the DashAI frontend.

Parameters

cls : type
The converter class (injected automatically by Python for classmethods).

Returns

Dict[str, Any]
Dictionary containing display name, short description, image preview path, category, icon, color, and whether the converter is supervised.

get_report(self) -> 'Union[Dict[str, Any], None]'

Defined on BaseConverter

Return the converter report produced after execution, if any.

Returns

Dict[str, Any] or None
JSON-serializable report dict, or None when the converter does not produce one.

get_schema(cls) -> dict

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

infer_output_columns(self, inputs: List[Annotated[Union[DashAI.back.preprocessing.structure_types.ColumnItem, DashAI.back.preprocessing.structure_types.BlockItem], FieldInfo(annotation=NoneType, required=True, discriminator='kind')]]) -> DashAI.back.preprocessing.structure_types.StructureDelta

Defined on EncodingConverter

Estimate the output: the scope kept, plus one encoded copy each.

Parameters

inputs : list of ColumnItem | BlockItem
The dataset state items in this converter's scope.

Returns

StructureDelta
The unchanged inputs, plus the encoded columns.

raises_on_unseen(self) -> bool

Defined on EncodingConverter

Whether a category unseen in fit makes transform raise.

rows_to_keep(self, x: "'DashAIDataset'") -> 'List[int]'

Defined on BaseConverter

Positions of the rows of x that survive this converter.

Parameters

x : DashAIDataset
The converter's scope columns of one split.

Returns

list of int
0-based positions of the kept rows, in order.

session_params(cls, params: 'Optional[Dict[str, Any]]') -> 'Dict[str, Any]'

Defined on BaseConverter

A session step's params, with the session defaults under them.

Parameters

params : dict or None
The params the step stores.

Returns

dict
SESSION_PARAMS updated with params: what the step gives wins.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.

Parameters

raw_data : dict
A dictionary with the data provided by the user to initialize the model.

Returns

dict
A validated dictionary with the necessary objects.