Class: Pipeline

A sequence of data transformers with an optional final predictor.

Pipeline allows you to sequentially apply a list of transformers to preprocess the data and, if desired, conclude the sequence with a final predictor for predictive modeling.

Intermediate steps of the pipeline must be ‘transforms’, that is, they must implement fit and transform methods. The final estimator only needs to implement fit. The transformers in the pipeline can be cached using memory argument.

The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters. For this, it enables setting parameters of the various steps using their names and the parameter name separated by a '__', as in the example below. A step’s estimator may be replaced entirely by setting the parameter with its name to another estimator, or a transformer removed by setting it to 'passthrough' or undefined.

For an example use case of Pipeline combined with GridSearchCV, refer to Selecting dimensionality reduction with Pipeline and GridSearchCV. The example Pipelining: chaining a PCA and a logistic regression shows how to grid search on a pipeline using '__' as a separator in the parameter names.

Read more in the User Guide.

Python Reference

Constructors

new Pipeline()

new Pipeline(opts?): Pipeline

Parameters

ParameterTypeDescription
opts?object-
opts.memory?stringUsed to cache the fitted transformers of the pipeline. The last step will never be cached, even if it is a transformer. By default, no caching is performed. If a string is given, it is the path to the caching directory. Enabling caching triggers a clone of the transformers before fitting. Therefore, the transformer instance given to the pipeline cannot be inspected directly. Use the attribute named_steps or steps to inspect estimators within the pipeline. Caching the transformers is advantageous when fitting is time consuming.
opts.steps?anyList of (name of step, estimator) tuples that are to be chained in sequential order. To be compatible with the scikit-learn API, all steps must define fit. All non-last steps must also define transform. See Combining Estimators for more details.
opts.verbose?booleanIf true, the time elapsed while fitting each step will be printed as it is completed.

Returns Pipeline

Defined in generated/pipeline/Pipeline.ts:31

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/pipeline/Pipeline.ts:29
_isInitializedbooleanfalsegenerated/pipeline/Pipeline.ts:28
_pyPythonBridgeundefinedgenerated/pipeline/Pipeline.ts:27
idstringundefinedgenerated/pipeline/Pipeline.ts:24
optsanyundefinedgenerated/pipeline/Pipeline.ts:25

Accessors

py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/pipeline/Pipeline.ts:53

Methods

decision_function()

decision_function(opts): Promise<ArrayLike[]>

Transform the data, and apply decision_function with the final estimator.

Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls decision_function method. Only valid if the final estimator implements decision_function.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters requested and accepted by steps. Each step must have requested certain metadata for these parameters to be forwarded to them.
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.

Returns Promise<ArrayLike[]>

Defined in generated/pipeline/Pipeline.ts:123


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/pipeline/Pipeline.ts:104


fit()

fit(opts): Promise<any>

Fit the model.

Fit all the transformers one after the other and sequentially transform the data. Finally, fit the transformed data using the final estimator.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyIf enable_metadata_routing=False (default):
opts.X?anyTraining data. Must fulfill input requirements of first step of the pipeline.
opts.y?anyTraining targets. Must fulfill label requirements for all steps of the pipeline.

Returns Promise<any>

Defined in generated/pipeline/Pipeline.ts:162


fit_predict()

fit_predict(opts): Promise<ArrayLike>

Transform the data, and apply fit_predict with the final estimator.

Call fit_transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls fit_predict method. Only valid if the final estimator implements fit_predict.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyIf enable_metadata_routing=False (default):
opts.X?anyTraining data. Must fulfill input requirements of first step of the pipeline.
opts.y?anyTraining targets. Must fulfill label requirements for all steps of the pipeline.

Returns Promise<ArrayLike>

Defined in generated/pipeline/Pipeline.ts:206


fit_transform()

fit_transform(opts): Promise<ArrayLike[]>

Fit the model and transform with the final estimator.

Fit all the transformers one after the other and sequentially transform the data. Only valid if the final estimator either implements fit_transform or fit and transform.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyIf enable_metadata_routing=False (default):
opts.X?anyTraining data. Must fulfill input requirements of first step of the pipeline.
opts.y?anyTraining targets. Must fulfill label requirements for all steps of the pipeline.

Returns Promise<ArrayLike[]>

Defined in generated/pipeline/Pipeline.ts:250


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

Transform input features using the pipeline.

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns Promise<any>

Defined in generated/pipeline/Pipeline.ts:294


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 MetadataRouter encapsulating routing information.

Returns Promise<any>

Defined in generated/pipeline/Pipeline.ts:330


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/pipeline/Pipeline.ts:66


inverse_transform()

inverse_transform(opts): Promise<ArrayLike[]>

Apply inverse_transform for each step in a reverse order.

All estimators in the pipeline must support inverse_transform.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters requested and accepted by steps. Each step must have requested certain metadata for these parameters to be forwarded to them.
opts.X?ArrayLike[]Data samples, where n_samples is the number of samples and n_features is the number of features. Must fulfill input requirements of last step of pipeline’s inverse_transform method.
opts.Xt?ArrayLike[]Data samples, where n_samples is the number of samples and n_features is the number of features. Must fulfill input requirements of last step of pipeline’s inverse_transform method.

Returns Promise<ArrayLike[]>

Defined in generated/pipeline/Pipeline.ts:364


predict()

predict(opts): Promise<ArrayLike>

Transform the data, and apply predict with the final estimator.

Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls predict method. Only valid if the final estimator implements predict.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyIf enable_metadata_routing=False (default):
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.

Returns Promise<ArrayLike>

Defined in generated/pipeline/Pipeline.ts:408


predict_log_proba()

predict_log_proba(opts): Promise<ArrayLike[]>

Transform the data, and apply predict_log_proba with the final estimator.

Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls predict_log_proba method. Only valid if the final estimator implements predict_log_proba.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyIf enable_metadata_routing=False (default):
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.

Returns Promise<ArrayLike[]>

Defined in generated/pipeline/Pipeline.ts:447


predict_proba()

predict_proba(opts): Promise<ArrayLike[]>

Transform the data, and apply predict_proba with the final estimator.

Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls predict_proba method. Only valid if the final estimator implements predict_proba.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyIf enable_metadata_routing=False (default):
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.

Returns Promise<ArrayLike[]>

Defined in generated/pipeline/Pipeline.ts:486


score()

score(opts): Promise<number>

Transform the data, and apply score with the final estimator.

Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls score method. Only valid if the final estimator implements score.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters requested and accepted by steps. Each step must have requested certain metadata for these parameters to be forwarded to them.
opts.sample_weight?ArrayLikeIf not undefined, this argument is passed as sample_weight keyword argument to the score method of the final estimator.
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.
opts.y?anyTargets used for scoring. Must fulfill label requirements for all steps of the pipeline.

Returns Promise<number>

Defined in generated/pipeline/Pipeline.ts:525


score_samples()

score_samples(opts): Promise<ArrayLike>

Transform the data, and apply score_samples with the final estimator.

Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls score_samples method. Only valid if the final estimator implements score_samples.

Parameters

ParameterTypeDescription
optsobject-
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.

Returns Promise<ArrayLike>

Defined in generated/pipeline/Pipeline.ts:574


set_output()

set_output(opts): Promise<any>

Set the output container when "transform" and "fit_transform" are called.

Calling set_output will set the output of all estimators in steps.

Parameters

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

Returns Promise<any>

Defined in generated/pipeline/Pipeline.ts:608


set_score_request()

set_score_request(opts): Promise<any>

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

Parameters

ParameterTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample_weight parameter in score.

Returns Promise<any>

Defined in generated/pipeline/Pipeline.ts:644


transform()

transform(opts): Promise<ArrayLike[]>

Transform the data, and apply transform with the final estimator.

Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls transform method. Only valid if the final estimator implements transform.

This also works where final estimator is undefined in which case all prior transformations are applied.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters requested and accepted by steps. Each step must have requested certain metadata for these parameters to be forwarded to them.
opts.X?anyData to transform. Must fulfill input requirements of first step of the pipeline.

Returns Promise<ArrayLike[]>

Defined in generated/pipeline/Pipeline.ts:680