DocumentationClassesFunctionTransformer

Class: FunctionTransformer

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.

Python Reference

Constructors

new FunctionTransformer()

new FunctionTransformer(opts?): FunctionTransformer

Parameters

ParameterTypeDescription
opts?object-
opts.accept_sparse?booleanIndicate that func accepts a sparse matrix as input. If validate is false, this has no effect. Otherwise, if accept_sparse is false, sparse matrix inputs will cause an exception to be raised.
opts.check_inverse?booleanWhether 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.
opts.feature_names_out?"one-to-one"Determines the list of feature names that will be returned by the get_feature_names_out method. If it is ‘one-to-one’, then the output feature names will be equal to the input feature names. If it is a callable, then it must take two positional arguments: this FunctionTransformer (self) and an array-like of input feature names (input_features). It must return an array-like of output feature names. The get_feature_names_out method is only defined if feature_names_out is not undefined. See get_feature_names_out for more details.
opts.func?anyThe callable to use for the transformation. This will be passed the same arguments as transform, with args and kwargs forwarded. If func is undefined, then func will be the identity function.
opts.inv_kw_args?anyDictionary of additional keyword arguments to pass to inverse_func.
opts.inverse_func?anyThe 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 undefined, then inverse_func will be the identity function.
opts.kw_args?anyDictionary of additional keyword arguments to pass to func.
opts.validate?booleanIndicate that the input X array should be checked before calling func. The possibilities are:

Returns FunctionTransformer

Defined in generated/preprocessing/FunctionTransformer.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/preprocessing/FunctionTransformer.ts:23
_isInitializedbooleanfalsegenerated/preprocessing/FunctionTransformer.ts:22
_pyPythonBridgeundefinedgenerated/preprocessing/FunctionTransformer.ts:21
idstringundefinedgenerated/preprocessing/FunctionTransformer.ts:18
optsanyundefinedgenerated/preprocessing/FunctionTransformer.ts:19

Accessors

feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/FunctionTransformer.ts:451


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit.

Returns Promise<number>

Defined in generated/preprocessing/FunctionTransformer.ts:424


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/preprocessing/FunctionTransformer.ts:78

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/preprocessing/FunctionTransformer.ts:134


fit()

fit(opts): Promise<any>

Fit transformer by checking X.

If validate is true, X will be checked.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyInput array.
opts.y?anyNot used, present here for API consistency by convention.

Returns Promise<any>

Defined in generated/preprocessing/FunctionTransformer.ts:153


fit_transform()

fit_transform(opts): Promise<any[]>

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

ParameterTypeDescription
optsobject-
opts.fit_params?anyAdditional fit parameters.
opts.X?ArrayLike[]Input samples.
opts.y?ArrayLikeTarget values (undefined for unsupervised transformations).

Returns Promise<any[]>

Defined in generated/preprocessing/FunctionTransformer.ts:194


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

This method is only defined if feature_names_out is not undefined.

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyInput feature names.

Returns Promise<any>

Defined in generated/preprocessing/FunctionTransformer.ts:242


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRequest encapsulating routing information.

Returns Promise<any>

Defined in generated/preprocessing/FunctionTransformer.ts:280


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/preprocessing/FunctionTransformer.ts:91


inverse_transform()

inverse_transform(opts): Promise<ArrayLike>

Transform X using the inverse function.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyInput array.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/FunctionTransformer.ts:316


set_output()

set_output(opts): Promise<any>

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/preprocessing/FunctionTransformer.ts:354


transform()

transform(opts): Promise<ArrayLike>

Transform X using the forward function.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyInput array.

Returns Promise<ArrayLike>

Defined in generated/preprocessing/FunctionTransformer.ts:390