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
inverse_transform(X) SparseCumlArray[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.

transform(X) SparseCumlArray[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.