tubular.numeric.ScalingTransformer

class tubular.numeric.ScalingTransformer(columns, scaler_type, scaler_kwargs={}, **kwargs)[source]

Bases: tubular.base.BaseTransformer

Transformer to perform scaling of numeric columns.

Transformer can apply min max scaling, max absolute scaling or standardisation (subtract mean and divide by std). The transformer uses the appropriate sklearn.preprocessing scaler.

Parameters
  • columns (str, list or None) – Name of the columns to apply scaling to.

  • scaler_type (str) – Type of scaler to use, must be one of ‘min_max’, ‘max_abs’ or ‘standard’. The corresponding sklearn.preprocessing scaler used in each case is MinMaxScaler, MaxAbsScaler or StandardScaler.

  • scaler_kwargs (dict, default = {}) – A dictionary of keyword arguments to be passed to the scaler object when it is initialised.

  • **kwargs – Arbitrary keyword arguments passed onto BaseTransformer.init().

__init__(columns, scaler_type, scaler_kwargs={}, **kwargs)None[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(columns, scaler_type[, scaler_kwargs])

Initialize self.

check_is_fitted(attribute)

Check if particular attributes are on the object.

check_numeric_columns(X)

Method to check all columns (specicifed in self.columns) in X are all numeric.

check_weights_column(X, weights_column)

Helper method for validating weights column in dataframe.

classname()

Method that returns the name of the current class when called.

columns_check(X)

Method to check that the columns attribute is set and all values are present in X.

columns_set_or_check(X)

Function to check or set columns attribute.

fit(X[, y])

Fit scaler to input data.

fit_transform(X[, y])

Fit to data, then transform it.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

transform(X)

Transform input data X with fitted scaler.

check_is_fitted(attribute)

Check if particular attributes are on the object. This is useful to do before running transform to avoid trying to transform data without first running the fit method.

Wrapper for utils.validation.check_is_fitted function.

Parameters

attributes (List) – List of str values giving names of attribute to check exist on self.

check_numeric_columns(X)[source]

Method to check all columns (specicifed in self.columns) in X are all numeric.

Parameters

X (pd.DataFrame) – Data containing columns to check.

static check_weights_column(X, weights_column)

Helper method for validating weights column in dataframe.

X (pd.DataFrame): df containing weight column weights_column (str): name of weight column

classname()

Method that returns the name of the current class when called.

columns_check(X)

Method to check that the columns attribute is set and all values are present in X.

Parameters

X (pd.DataFrame) – Data to check columns are in.

columns_set_or_check(X)

Function to check or set columns attribute.

If the columns attribute is None then set it to all columns in X. Otherwise run the columns_check method.

Parameters

X (pd.DataFrame) – Data to check columns are in.

fit(X, y=None)[source]

Fit scaler to input data.

Parameters
  • X (pd.DataFrame) – Dataframe with columns to learn scaling values from.

  • y (None) – Required for pipeline.

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

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 (array-like of shape (n_samples, n_features)) – Input samples.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs), default=None) – Target values (None for unsupervised transformations).

  • **fit_params (dict) – Additional fit parameters.

Returns

X_new – Transformed array.

Return type

ndarray array of shape (n_samples, n_features_new)

get_params(deep=True)

Get parameters for this estimator.

Parameters

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

dict

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters

**params (dict) – Estimator parameters.

Returns

self – Estimator instance.

Return type

estimator instance

transform(X)[source]

Transform input data X with fitted scaler.

Parameters

X (pd.DataFrame) – Dataframe containing columns to be scaled.

Returns

X – Input X with columns scaled.

Return type

pd.DataFrame