data.one_hot_encoder#
The one_hot_encoder module contains a lightweight implementation of a one-hot encoder.
We include it to avoid the dependency on heavy frameworks like sklearn for a trivial task.
- class soulsai.data.one_hot_encoder.OneHotEncoder(allow_unknown: bool = False)#
Encode categorical data as one hot numpy arrays.
Just like the sklearn encoder (which this class imitates), the encoder first has to be fit to data before it can be used to convert between the representations.
- fit(data: Collection[Hashable])#
Fit the encoder to the training data.
- Parameters:
data – A collection of hashable categories
- transform(data: Hashable) ndarray#
Transform categorical data to a one hot encoded array.
- Parameters:
data – A categorical data sample.
- Returns:
The corresponding one hot encoded array.
- Raises:
ValueError – An unknown category was provided without setting allow_unknown to True.
- inverse_transform(data: ndarray) Hashable#
Transform one-hot encoded data to its corresponding category.
- Parameters:
data – A one-hot encoded data sample.
- Returns:
The corresponding category.
- Raises:
ValueError – An unknown category was provided.