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.
Constructors
new FunctionTransformer()
new FunctionTransformer(
opts
?):FunctionTransformer
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.accept_sparse ? | boolean | Indicate 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 ? | boolean | 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. |
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 ? | any | The 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 ? | any | Dictionary of additional keyword arguments to pass to inverse_func. |
opts.inverse_func ? | any | 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 undefined , then inverse_func will be the identity function. |
opts.kw_args ? | any | Dictionary of additional keyword arguments to pass to func. |
opts.validate ? | boolean | Indicate that the input X array should be checked before calling func . The possibilities are: |
Returns FunctionTransformer
Defined in generated/preprocessing/FunctionTransformer.ts:25
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/FunctionTransformer.ts:23 |
_isInitialized | boolean | false | generated/preprocessing/FunctionTransformer.ts:22 |
_py | PythonBridge | undefined | generated/preprocessing/FunctionTransformer.ts:21 |
id | string | undefined | generated/preprocessing/FunctionTransformer.ts:18 |
opts | any | undefined | generated/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
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | Input array. |
opts.y ? | any | Not 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional fit parameters. |
opts.X ? | ArrayLike [] | Input samples. |
opts.y ? | ArrayLike | Target 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Input 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A 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
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/preprocessing/FunctionTransformer.ts:91
inverse_transform()
inverse_transform(
opts
):Promise
<ArrayLike
>
Transform X using the inverse function.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | Input 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
Parameter | Type | Description |
---|---|---|
opts | object | - |
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
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | any | Input array. |
Returns Promise
<ArrayLike
>
Defined in generated/preprocessing/FunctionTransformer.ts:390