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
Methods
fit(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None)
LabelEncoderFit 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
LabelEncoderReturn the DashAI data type produced by this converter for a column.
Parameters
- column_name : str, optional
- The column name to look up in the fitted encoders. When provided and the encoder has been fitted, the returned type reflects the actual fitted classes. Defaults to None.
Returns
- DashAIDataType
- A Categorical type derived from the encoder's fitted classes. Returns a placeholder
Categoricalif the encoder has not been fitted for the given column.
transform(self, x: 'DashAIDataset', y: Optional[ForwardRef('DashAIDataset')] = None) -> 'DashAIDataset'
LabelEncoderApply fitted label encoders to each eligible column, preserving NaN.
Parameters
- x : DashAIDataset
- Input dataset. Columns not seen during
fitare left unchanged. - y : DashAIDataset or None, optional
- Ignored. Present for API compatibility. Default
None.
Returns
- DashAIDataset
- Dataset with categorical/string columns replaced by integer codes.
changes_row_count(self) -> 'bool'
BaseConverterIndicate whether this converter changes the number of dataset rows.
Returns
- bool
- True if the converter may add or remove rows, False otherwise.
get_metadata(cls) -> 'Dict[str, Any]'
BaseConverterGet 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_schema(cls) -> dict
ConfigObjectGenerates the component related Json Schema.
Returns
- dict
- Dictionary representing the Json Schema of the component.
validate_and_transform(self, raw_data: dict) -> dict
ConfigObjectIt 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.