vastorbit.machine_learning.memmodel.preprocessing.OneHotEncoder¶
- class vastorbit.machine_learning.memmodel.preprocessing.OneHotEncoder(categories: Annotated[list | ndarray, 'Array Like Structure'], column_naming: Literal['indices', 'values', 'values_relaxed'] = 'indices', drop_first: bool = True)¶
InMemoryModelimplementation of one-hot encoder.- Parameters:
categories (ArrayLike) – ArrayLike of the categories of the different features.
column_naming (str, optional) –
Appends categorical levels to column names according to the specified method:
- indices:
Uses integer indices to represent categorical levels.
- values | values_relaxed:
Both methods use categorical level names. If duplicate column names occur, the function attempts to disambiguate them by appending _n, where n is a zero-based integer index (_0, _1,…).
drop_first (bool, optional) – If set to
False, the first dummy of each category is dropped.note:: (..) –
OneHotEncoderare defined entirely by their attributes. For example,categoriesto encode defines aOneHotEncodermodel. You can optionally providecolumn_namingcriteria and adrop_firstflag to denote whether to drop first dummy of each category.rubric: (..) – Attributes:
input (Attributes are identical to the)
parameters
underscore (followed by an)
('_').
Examples
Initalization
Import the required module.
from vastorbit.machine_learning.memmodel.preprocessing import OneHotEncoder
A OneHotEncoder model is defined by categories, column naming criteria and
drop_firstflag.Let’s create a
OneHotEncodermodel.model_ohe = OneHotEncoder( categories = [["male", "female"], [1, 2, 3]], drop_first = False, column_naming = None, )
Create a dataset.
data = [["male", 1], ["female", 3]]
Making In-Memory Transformation
Use
transform()method to do transformation.model_ohe.transform(data)
Deploy SQL Code
Let’s use the following column names:
cnames = ['sex', 'pclass']
Use
transform_sql()method to get the SQL code needed to deploy the model using its attributes.model_ohe.transform_sql(cnames)
Hint
This object can be pickled and used in any in-memory environment, just like scikit-learn models.
- __init__(categories: Annotated[list | ndarray, 'Array Like Structure'], column_naming: Literal['indices', 'values', 'values_relaxed'] = 'indices', drop_first: bool = True) None¶
Methods
__init__(categories[, column_naming, drop_first])Returns the model attributes.
set_attributes(**kwargs)Sets the model attributes.
transform(X)Transforms and applies the
OneHotEncodermodel to the input matrix.Transforms and returns the SQL needed to deploy the
Scaler.Attributes
Must be overridden in child class