bluecast.preprocessing.encode_target_labels

A module for encoding target column labels.

This is a convenience feature. It is only relevant when target column values are categorical. In such cases they will be converted to numerical values, but reverse-transformed for the end-user at the end of the pipeline.

Module Contents

Classes

TargetLabelEncoder

Encode target column labels.

Functions

cast_bool_to_int(→ pandas.DataFrame)

This function takes a DataFrame and a column name. If the column is of type bool, it casts it to int and returns the DataFrame.

bluecast.preprocessing.encode_target_labels.cast_bool_to_int(df: pandas.DataFrame, column_name: str) pandas.DataFrame

This function takes a DataFrame and a column name. If the column is of type bool, it casts it to int and returns the DataFrame.

Parameters:
  • df – The input DataFrame.

  • column_name – The name of the column to check and possibly cast.

returns: The modified DataFrame with the column cast to bool if it was of type int.

class bluecast.preprocessing.encode_target_labels.TargetLabelEncoder

Encode target column labels.

This function is only relevant when target column values are categorical. In such cases they will be converted into numerical representation. This encoding can also be reversed to translate back.

fit_label_encoder(targets: pandas.DataFrame) Dict[str, int]

Iterate through target values and map them to numerics.

label_encoder_transform(targets: pandas.DataFrame, mapping: Dict[str, int], target_col: str | int | float | None = None) pandas.DataFrame

Transform target column from categorical to numerical representation.

fit_transform_target_labels(targets: pandas.DataFrame) pandas.DataFrame

Wrapper function that creates the mapping and transforms the target column.

transform_target_labels(targets: pandas.DataFrame, target_col: str | int | float | None = None) pandas.DataFrame

Transform the target column based on already created mappings.

label_encoder_reverse_transform(targets: pandas.Series) pandas.DataFrame

Reverse numerical encodings back to original categories.