OneHotEncoder#
- class cuml.dask.preprocessing.OneHotEncoder(*, client=None, verbose=False, **kwargs)[source]#
Encode categorical features as a one-hot numeric array.
The input to this transformer should be an array-like of integers or strings, denoting the values taken on by categorical (discrete) features. The features are encoded using a one-hot (aka ‘one-of-K’ or ‘dummy’) encoding scheme. This creates a binary column for each category and returns a sparse matrix or dense array (depending on the
sparse_outputparameter).By default, the encoder derives the categories based on the unique values in each feature. Alternatively, you can also specify the
categoriesmanually.- Parameters:
- categories‘auto’ or a list of array-like, default=’auto’
Categories (unique values) per feature:
‘auto’ : Determine categories automatically from the training data.
list :
categories[i]holds the categories expected in the ith column.
- drop‘first’, None, or array-like of shape (n_features,), default=None
Specifies a methodology to use to drop one of the categories per feature. This is useful in situations where perfectly collinear features cause problems, such as when feeding the resulting data into an unregularized linear regression model.
However, dropping one category breaks the symmetry of the original representation and can therefore induce a bias in downstream models, for instance for penalized linear classification or regression models.
None : retain all features (the default).
‘first’ : drop the first category in each feature. If only one category is present, the feature will be dropped entirely.
array :
drop[i]is the category in featureX[:, i]that should be dropped.
- sparse_outputbool, default=True
When
True, transform returns a sparse matrix/array in CSR format.- dtypedtype, default=np.float32
Desired dtype of transformed output.
- handle_unknown{‘error’, ‘ignore’}, default=’error’
Specifies the way unknown categories are handled during
transform().‘error’ : Raise an error if an unknown category is present during transform.
‘ignore’ : When an unknown category is encountered during transform, the resulting one-hot encoded columns for this feature will be all zeros. In the inverse transform, an unknown category will be denoted as None.
Methods
fit(X)Fit a multi-node multi-gpu OneHotEncoder to X.
inverse_transform(X[, delayed])Convert the data back to the original representation.
transform(X[, delayed])Transform X using one-hot encoding.
- fit(X)[source]#
Fit a multi-node multi-gpu OneHotEncoder to X.
- Parameters:
- XDask cuDF DataFrame or CuPy backed Dask Array
The data to determine the categories of each feature.
- Returns:
- self
- fit_transform(X, delayed=True)[source]#
Fit the encoder to X, then transform X. Equivalent to fit(X).transform(X).
- Parameters:
- XDask cuDF DataFrame or CuPy backed Dask Array
The data to encode.
- delayedbool (default = True)
Whether to execute as a delayed task or eager.
- Returns:
- outDask cuDF DataFrame or CuPy backed Dask Array
Distributed object containing the transformed data
- get_combined_model()[source]#
Return single-GPU model for serialization
- Returns:
- modelTrained single-GPU model or None if the model has not
yet been trained.
- inverse_transform(X, delayed=True)[source]#
Convert the data back to the original representation.
- Parameters:
- XCuPy backed Dask Array, shape [n_samples, n_encoded_features]
The transformed data.
- delayedbool (default = True)
Whether to execute as a delayed task or eager.
- Returns:
- X_trDask cuDF DataFrame or CuPy backed Dask Array
Distributed object containing the inverse transformed array.
- transform(X, delayed=True)[source]#
Transform X using one-hot encoding.
- Parameters:
- XDask cuDF DataFrame or CuPy backed Dask Array
The data to encode.
- delayedbool (default = True)
Whether to execute as a delayed task or eager.
- Returns:
- outDask cuDF DataFrame or CuPy backed Dask Array
Distributed object containing the transformed input.