sklearndf.transformation.OrdinalEncoderDF#

class sklearndf.transformation.OrdinalEncoderDF(*, categories='auto', dtype=<class 'numpy.float64'>, handle_unknown='error', unknown_value=None, encoded_missing_value=nan)[source]#

Encode categorical features as an integer array.

Note

This class is a wrapper around class sklearn.preprocessing.OrdinalEncoder. It provides enhanced support for pandas data frames, and otherwise delegates all attribute access and method calls to an associated OrdinalEncoder instance.

Bases

ColumnPreservingTransformerWrapperDF [OrdinalEncoder]

Metaclasses

EstimatorWrapperDFMeta, ABCMeta

Method summary

clone

Make an unfitted clone of this estimator.

fit

Fit this estimator using the given inputs.

fit_transform

Fit this transformer using the given inputs, then transform the inputs.

from_fitted

Make a new wrapped DF estimator, delegating to a given native estimator that has already been fitted.

get_params

Get the parameters for this estimator.

inverse_transform

Inverse-transform the given inputs.

set_output

See sklearn.utils.set_output()

set_params

Set the parameters of this estimator.

to_expression

Render this object as an expression.

transform

Transform the given inputs.

Attribute summary

COL_FEATURE

Name assigned to an Index or a Series with the names of the features used to fit a EstimatorDF.

COL_FEATURE_ORIGINAL

Name assigned to a Series with the original feature names before transformation.

feature_names_in_

The pandas column index with the names of the features used to fit this estimator.

feature_names_original_

A pandas series, mapping the output features resulting from the transformation to the original input features.

feature_names_out_

A pandas column index with the names of the features produced by this transformer

is_fitted

True if this object is fitted, False otherwise.

n_features_in_

The number of features used to fit this estimator.

n_outputs_

The number of outputs used to fit this estimator.

native_estimator

The native estimator that this wrapper delegates to.

output_names_

The name(s) of the output(s) this estimator was fitted to, or None if this estimator was not fitted to any outputs.

Definitions

clone()#

Make an unfitted clone of this estimator.

Return type

OrdinalEncoderDF

Returns

the unfitted clone

fit(X, y=None, **fit_params)#

Fit this estimator using the given inputs.

Parameters
  • X (Union[DataFrame, Series]) – input data frame with observations as rows and features as columns

  • y (Union[Series, DataFrame, None]) – an optional series or data frame with one or more outputs

  • fit_params (Any) – additional keyword parameters as required by specific estimator implementations

Return type

OrdinalEncoderDF

Returns

self

fit_transform(X, y=None, **fit_params)#

Fit this transformer using the given inputs, then transform the inputs.

Parameters
  • X (Union[Series, DataFrame]) – input data frame with observations as rows and features as columns

  • y (Optional[Series]) – an optional series or data frame with one or more outputs

  • fit_params (Any) – additional keyword parameters as required by specific transformer implementations

Return type

DataFrame

Returns

the transformed inputs

classmethod from_fitted(estimator, features_in, n_outputs)#

Make a new wrapped DF estimator, delegating to a given native estimator that has already been fitted.

Parameters
  • estimator (OrdinalEncoder) – the fitted native estimator to use as the delegate

  • features_in (Index) – the column names of X used for fitting the estimator

  • n_outputs (int) – the number of outputs in y used for fitting the estimator

Return type

OrdinalEncoderDF

Returns

the wrapped data frame estimator

get_params(deep=True)#

Get the parameters for this estimator.

Parameters

deep (bool) – if True, return the parameters for this estimator, and for any sub-estimators contained in this estimator

Return type

Mapping[str, Any]

Returns

a mapping of parameter names to their values

inverse_transform(X)#

Inverse-transform the given inputs.

The inputs must have the same features as the inputs used to fit this transformer. The features can be provided in any order since they are identified by their column names.

Parameters

X (Union[Series, DataFrame]) – input data frame with observations as rows and features as columns

Return type

DataFrame

Returns

the reverse-transformed inputs

set_output(*, transform=None)#

See sklearn.utils.set_output()

set_params(**params)#

Set the parameters of this estimator.

Valid parameter keys can be obtained by calling get_params().

Parameters

params (Any) – the estimator parameters to set

Return type

OrdinalEncoderDF

Returns

self

to_expression()#

Render this object as an expression.

Return type

Expression

Returns

the expression representing this object

transform(X)#

Transform the given inputs.

The inputs must have the same features as the inputs used to fit this transformer. The features can be provided in any order since they are identified by their column names.

Parameters

X (Union[Series, DataFrame]) – input data frame with observations as rows and features as columns

Return type

DataFrame

Returns

the transformed inputs

property feature_names_in_: pandas.Index#

The pandas column index with the names of the features used to fit this estimator.

Raises

AttributeError – this estimator is not fitted

Return type

Index

property feature_names_original_: pandas.Series#

A pandas series, mapping the output features resulting from the transformation to the original input features.

The index of the resulting series consists of the names of the output features; the corresponding values are the names of the original input features.

Raises

AttributeError – this transformer is not fitted

Return type

Series

property feature_names_out_: pandas.Index#

A pandas column index with the names of the features produced by this transformer

Raises

AttributeError – this transformer is not fitted

Return type

Index

property is_fitted: bool#

True if this object is fitted, False otherwise.

Return type

bool

property n_features_in_: int#

The number of features used to fit this estimator.

Raises

AttributeError – this estimator is not fitted

Return type

int

property n_outputs_: int#

The number of outputs used to fit this estimator.

Raises

AttributeError – this estimator is not fitted

Return type

int

property native_estimator: sklearndf.wrapper.T_NativeEstimator#

The native estimator that this wrapper delegates to.

Return type

TypeVar(T_NativeEstimator, bound= BaseEstimator)

property output_names_: Optional[List[str]]#

The name(s) of the output(s) this estimator was fitted to, or None if this estimator was not fitted to any outputs.

Raises

AttributeError – this estimator is not fitted

Return type

Optional[List[str]]