encode_one_hot#

class usencrypt.ai.preprocessing.encode_one_hot(input_data, classes=None)#

Encodes categorical features as a one-hot numeric array based on the unique values in each feature.

Parameters
  • input_data (list or numpy.ndarray) – The input to be encoded.

  • classes (list or numpy.ndarray) – The set of all unique labels in the dataset. If it is None, a list of classes will be generated. Defaults to None.

Returns

The encoded input.

Return type

numpy.ndarray

Examples
>>> import pandas as pd
>>> import usencrypt as ue
>>> df = pd.DataFrame.from_dict(
        {
            'Name': ['Joan', 'Matt', 'Jeff', 'Melissa', 'Devi'],
            'Gender': ['Female', 'Male', 'Male', 'Female', 'Female'],
            'House Type': ['Apartment', 'Detached', 'Apartment', 'Semi-Detached', 'Semi-Detached']
        }
    )
>>> encoded = ue.preprocessing.encode_one_hot(df['Gender'], ['Female', 'Male'])
>>> encoded
array([[1, 0],
       [0, 1],
       [0, 1],
       [1, 0],
       [1, 0]])