Documentation
Classes
FunctionTransformer

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 (opens in a new tab)

Constructors

constructor()

Signature

new FunctionTransformer(opts?: object): FunctionTransformer;

Parameters

NameTypeDescription
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. Default Value false
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. Default Value true
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: Default Value false

Returns

FunctionTransformer

Defined in: generated/preprocessing/FunctionTransformer.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/preprocessing/FunctionTransformer.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/preprocessing/FunctionTransformer.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/preprocessing/FunctionTransformer.ts:21 (opens in a new tab)

id

string

Defined in: generated/preprocessing/FunctionTransformer.ts:18 (opens in a new tab)

opts

any

Defined in: generated/preprocessing/FunctionTransformer.ts:19 (opens in a new tab)

Accessors

feature_names_in_

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

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/FunctionTransformer.ts:436 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/preprocessing/FunctionTransformer.ts:409 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/preprocessing/FunctionTransformer.ts:78 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/preprocessing/FunctionTransformer.ts:82 (opens in a new tab)

Methods

dispose()

Disposes of the underlying Python resources.

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

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/preprocessing/FunctionTransformer.ts:145 (opens in a new tab)

fit()

Fit transformer by checking X.

If validate is true, X will be checked.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
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:164 (opens in a new tab)

fit_transform()

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit\_params and returns a transformed version of X.

Signature

fit_transform(opts: object): Promise<any[]>;

Parameters

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

Returns

Promise<any[]>

Defined in: generated/preprocessing/FunctionTransformer.ts:206 (opens in a new tab)

get_feature_names_out()

Get output feature names for transformation.

This method is only defined if feature\_names\_out is not undefined.

Signature

get_feature_names_out(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.input_features?anyInput feature names.

Returns

Promise<any>

Defined in: generated/preprocessing/FunctionTransformer.ts:259 (opens in a new tab)

init()

Initializes the underlying Python resources.

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

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/preprocessing/FunctionTransformer.ts:91 (opens in a new tab)

inverse_transform()

Transform X using the inverse function.

Signature

inverse_transform(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?anyInput array.

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/FunctionTransformer.ts:297 (opens in a new tab)

set_output()

Set output container.

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

Signature

set_output(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.transform?"default" | "pandas"Configure output of transform and fit\_transform.

Returns

Promise<any>

Defined in: generated/preprocessing/FunctionTransformer.ts:337 (opens in a new tab)

transform()

Transform X using the forward function.

Signature

transform(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?anyInput array.

Returns

Promise<ArrayLike>

Defined in: generated/preprocessing/FunctionTransformer.ts:374 (opens in a new tab)