toad.transform module

class toad.transform.Transformer[source]

Bases: sklearn.base.TransformerMixin, toad.utils.mixin.SaveMixin

Base class for transformers

fit()

fit method, see details in fit_ method

transform(X, *args, **kwargs)[source]

transform method, see details in transform_ method

export(**kwargs)[source]
fit_transform(X, y=None, **fit_params)[source]

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
  • X (numpy array of shape [n_samples, n_features]) – Training set.
  • y (numpy array of shape [n_samples]) – Target values.
  • **fit_params (dict) – Additional fit parameters.
Returns:

X_new – Transformed array.

Return type:

numpy array of shape [n_samples, n_features_new]

load(rules, update=False, **kwargs)[source]
class toad.transform.WOETransformer[source]

Bases: toad.transform.Transformer

WOE transformer

fit_(X, y)[source]

fit WOE transformer

Parameters:
  • X (DataFrame|array-like) –
  • y (str|array-like) –
  • select_dtypes (str|numpy.dtypes) – ‘object’, ‘number’ etc. only selected dtypes will be transform
transform_(rule, X, default='min')[source]

transform function for single feature

Parameters:
  • X (array-like) –
  • default (str) – ‘min’(default), ‘max’ - the strategy to be used for unknown group
Returns:

array-like

export(**kwargs)[source]
fit()

fit method, see details in fit_ method

fit_transform(X, y=None, **fit_params)[source]

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
  • X (numpy array of shape [n_samples, n_features]) – Training set.
  • y (numpy array of shape [n_samples]) – Target values.
  • **fit_params (dict) – Additional fit parameters.
Returns:

X_new – Transformed array.

Return type:

numpy array of shape [n_samples, n_features_new]

load(rules, update=False, **kwargs)[source]
transform(X, *args, **kwargs)[source]

transform method, see details in transform_ method

class toad.transform.Combiner[source]

Bases: toad.transform.Transformer

Combiner for merge data

fit_(X, y=None, method='chi', empty_separate=False, **kwargs)[source]

fit combiner

Parameters:
  • X (DataFrame|array-like) – features to be combined
  • y (str|array-like) – target data or name of target in X
  • method (str) – the strategy to be used to merge X, same as .merge, default is chi
  • n_bins (int) – counts of bins will be combined
  • empty_separate (bool) – if need to combine empty values into a separate group
transform_(rule, X, labels=False, **kwargs)[source]

transform X by combiner

Parameters:
  • X (DataFrame|array-like) – features to be transformed
  • labels (bool) – if need to use labels for resulting bins, False by default
Returns:

array-like

set_rules(map, reset=False)[source]

set rules for combiner

Parameters:
  • map (dict|array-like) – map of splits
  • reset (bool) – if need to reset combiner
Returns:

self

export(**kwargs)[source]
fit()

fit method, see details in fit_ method

fit_transform(X, y=None, **fit_params)[source]

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
  • X (numpy array of shape [n_samples, n_features]) – Training set.
  • y (numpy array of shape [n_samples]) – Target values.
  • **fit_params (dict) – Additional fit parameters.
Returns:

X_new – Transformed array.

Return type:

numpy array of shape [n_samples, n_features_new]

load(rules, update=False, **kwargs)[source]
transform(X, *args, **kwargs)[source]

transform method, see details in transform_ method

class toad.transform.GBDTTransformer[source]

Bases: toad.transform.Transformer

GBDT transformer

fit_(X, y, **kwargs)[source]

fit GBDT transformer

Parameters:
  • X (DataFrame|array-like) –
  • y (str|array-like) –
  • select_dtypes (str|numpy.dtypes) – ‘object’, ‘number’ etc. only selected dtypes will be transform,
transform_(rules, X)[source]

transform woe

Parameters:X (DataFrame|array-like) –
Returns:array-like
export(**kwargs)[source]
fit()

fit method, see details in fit_ method

fit_transform(X, y=None, **fit_params)[source]

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters:
  • X (numpy array of shape [n_samples, n_features]) – Training set.
  • y (numpy array of shape [n_samples]) – Target values.
  • **fit_params (dict) – Additional fit parameters.
Returns:

X_new – Transformed array.

Return type:

numpy array of shape [n_samples, n_features_new]

load(rules, update=False, **kwargs)[source]
transform(X, *args, **kwargs)[source]

transform method, see details in transform_ method