# FunctionTransformer

### *class* cuml.preprocessing.FunctionTransformer(\*args, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_function_transformer.py#L27)

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:**
  **func**
  : 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_func**
  : 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_sparse**
  : 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_inverse**
  : 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_args**
  : Dictionary of additional keyword arguments to pass to func.

  **inv_kw_args**
  : Dictionary of additional keyword arguments to pass to inverse_func.

### Methods

| [`fit`](#cuml.preprocessing.FunctionTransformer.fit)(X[, y])          | Fit transformer by checking X.          |
|-----------------------------------------------------------------------|-----------------------------------------|
| [`inverse_transform`](#cuml.preprocessing.FunctionTransformer.inverse_transform)(X) | Transform X using the inverse function. |
| [`transform`](#cuml.preprocessing.FunctionTransformer.transform)(X)         | Transform X using the forward function. |

### Examples

```pycon
>>> 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...]])
```

<!-- !! processed by numpydoc !! -->

#### fit(X, y=None) → [FunctionTransformer](#cuml.preprocessing.FunctionTransformer)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_function_transformer.py#L100)

Fit transformer by checking X.

* **Parameters:**
  **X**
  : Input array.
* **Returns:**
  self

<!-- !! processed by numpydoc !! -->

#### fit_transform(X, y=None, \*\*fit_params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/utils/skl_dependencies.py#L42)

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**

  **y**
  : Target values.

  **\*\*fit_params**
  : Additional fit parameters.
* **Returns:**
  **X_new**
  : Transformed array.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

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

<!-- !! processed by numpydoc !! -->

#### inverse_transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_function_transformer.py#L135)

Transform X using the inverse function.

* **Parameters:**
  **X**
  : Input array.
* **Returns:**
  **X_out**
  : Transformed input.

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

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

<!-- !! processed by numpydoc !! -->

#### transform(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/_thirdparty/sklearn/preprocessing/_function_transformer.py#L119)

Transform X using the forward function.

* **Parameters:**
  **X**
  : Input array.
* **Returns:**
  **X_out**
  : Transformed input.

<!-- !! processed by numpydoc !! -->
