FunctionTransformer#

class cuml.preprocessing.FunctionTransformer(*args, **kwargs)[source]#

Constructs a transformer from an arbitrary callable.

A FunctionTransformer forwards its X (and optionally y) arguments to a user-defined function or function object and returns the result of this function. This is useful for stateless transformations such as taking the log of frequencies, doing custom scaling, etc.

Note: If a lambda is used as the function, then the resulting transformer will not be pickleable.

Parameters:
funccallable, default=None

The callable to use for the transformation. This will be passed the same arguments as transform, with args and kwargs forwarded. If func is None, then func will be the identity function.

inverse_funccallable, default=None

The callable to use for the inverse transformation. This will be passed the same arguments as inverse transform, with args and kwargs forwarded. If inverse_func is None, then inverse_func will be the identity function.

accept_sparsebool, default=False

Indicate that func accepts a sparse matrix as input. Otherwise, if accept_sparse is false, sparse matrix inputs will cause an exception to be raised.

check_inversebool, default=True

Whether to check that or func followed by inverse_func leads to the original inputs. It can be used for a sanity check, raising a warning when the condition is not fulfilled.

kw_argsdict, default=None

Dictionary of additional keyword arguments to pass to func.

inv_kw_argsdict, default=None

Dictionary of additional keyword arguments to pass to inverse_func.

Methods

fit(X[, y])

Fit transformer by checking X.

inverse_transform(X)

Transform X using the inverse function.

transform(X)

Transform X using the forward function.

Examples

>>> import cupy as cp
>>> from cuml.preprocessing import FunctionTransformer
>>> transformer = FunctionTransformer(func=cp.log1p)
>>> X = cp.array([[0, 1], [2, 3]])
>>> transformer.transform(X)
array([[0.       , 0.6931...],
       [1.0986..., 1.3862...]])
fit(
X,
y=None,
) FunctionTransformer[source]#

Fit transformer by checking X.

Parameters:
X{array-like, sparse matrix}, shape (n_samples, n_features)

Input array.

Returns:
self
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{array-like, sparse matrix, dataframe} of shape (n_samples, n_features)
yndarray of shape (n_samples,), default=None

Target values.

**fit_paramsdict

Additional fit parameters.

Returns:
X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

get_params(deep=True)[source]#

Returns a dict of all params owned by this class. If the child class has appropriately overridden the _get_param_names method and does not need anything other than what is there in this method, then it doesn’t have to override this method

inverse_transform(X)[source]#

Transform X using the inverse function.

Parameters:
X{array-like, sparse matrix}, shape (n_samples, n_features)

Input array.

Returns:
X_out{array-like, sparse matrix}, shape (n_samples, n_features)

Transformed input.

set_params(**params)[source]#

Accepts a dict of params and updates the corresponding ones owned by this class. If the child class has appropriately overridden the _get_param_names method and does not need anything other than what is, there in this method, then it doesn’t have to override this method

transform(X)[source]#

Transform X using the forward function.

Parameters:
X{array-like, sparse matrix}, shape (n_samples, n_features)

Input array.

Returns:
X_out{array-like, sparse matrix}, shape (n_samples, n_features)

Transformed input.