Documentation
Classes
Pipeline

Pipeline

Pipeline of transforms with a final estimator.

Sequentially apply a list of transforms and a final estimator. 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 (opens in a new tab)

Constructors

constructor()

Signature

new Pipeline(opts?: object): Pipeline;

Parameters

NameTypeDescription
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, transform) tuples (implementing fit/transform) that are chained in sequential order. The last transform must be an estimator.
opts.verbose?booleanIf true, the time elapsed while fitting each step will be printed as it is completed. Default Value false

Returns

Pipeline

Defined in: generated/pipeline/Pipeline.ts:29 (opens in a new tab)

Methods

decision_function()

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.

Signature

decision_function(opts: object): Promise<ArrayLike[]>;

Parameters

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

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/pipeline/Pipeline.ts:105 (opens in a new tab)

fit()

Fit the model.

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

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?anyTraining data. Must fulfill input requirements of first step of the pipeline.
opts.fit_params?anyParameters passed to the fit method of each step, where each parameter name is prefixed such that parameter p for step s has key s\_\_p.
opts.y?anyTraining targets. Must fulfill label requirements for all steps of the pipeline.

Returns

Promise<any>

Defined in: generated/pipeline/Pipeline.ts:159 (opens in a new tab)

fit_predict()

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.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?anyTraining data. Must fulfill input requirements of first step of the pipeline.
opts.fit_params?anyParameters passed to the fit method of each step, where each parameter name is prefixed such that parameter p for step s has key s\_\_p.
opts.y?anyTraining targets. Must fulfill label requirements for all steps of the pipeline.

Returns

Promise<ArrayLike>

Defined in: generated/pipeline/Pipeline.ts:206 (opens in a new tab)

fit_transform()

Fit the model and transform with the final estimator.

Fits all the transformers one after the other and transform the data. Then uses fit\_transform on transformed data with the final estimator.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?anyTraining data. Must fulfill input requirements of first step of the pipeline.
opts.fit_params?anyParameters passed to the fit method of each step, where each parameter name is prefixed such that parameter p for step s has key s\_\_p.
opts.y?anyTraining targets. Must fulfill label requirements for all steps of the pipeline.

Returns

Promise<ArrayLike[]>

Defined in: generated/pipeline/Pipeline.ts:253 (opens in a new tab)

get_feature_names_out()

Get output feature names for transformation.

Transform input features using the pipeline.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns

Promise<any>

Defined in: generated/pipeline/Pipeline.ts:300 (opens in a new tab)

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Signature

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

Parameters

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

Returns

Promise<any>

Defined in: generated/pipeline/Pipeline.ts:337 (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/pipeline/Pipeline.ts:64 (opens in a new tab)

inverse_transform()

Apply inverse\_transform for each step in a reverse order.

All estimators in the pipeline must support inverse\_transform.

Signature

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

Parameters

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

predict()

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.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.
opts.predict_params?anyParameters to the predict called at the end of all transformations in the pipeline. Note that while this may be used to return uncertainties from some models with return_std or return_cov, uncertainties that are generated by the transformations in the pipeline are not propagated to the final estimator.

Returns

Promise<ArrayLike>

Defined in: generated/pipeline/Pipeline.ts:407 (opens in a new tab)

predict_log_proba()

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.

Signature

predict_log_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.
opts.predict_log_proba_params?anyParameters to the predict\_log\_proba called at the end of all transformations in the pipeline.

Returns

Promise<ArrayLike[]>

Defined in: generated/pipeline/Pipeline.ts:447 (opens in a new tab)

predict_proba()

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.

Signature

predict_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.
opts.predict_proba_params?anyParameters to the predict\_proba called at the end of all transformations in the pipeline.

Returns

Promise<ArrayLike[]>

Defined in: generated/pipeline/Pipeline.ts:489 (opens in a new tab)

score()

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.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?anyData to predict on. Must fulfill input requirements of first step of the pipeline.
opts.sample_weight?ArrayLikeIf not undefined, this argument is passed as sample\_weight keyword argument to the score method of the final estimator.
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:529 (opens in a new tab)

score_samples()

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.

Signature

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

Parameters

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

set_output()

Set the output container when "transform" and "fit\_transform" are called.

Calling set\_output will set the output of all estimators in steps.

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/pipeline/Pipeline.ts:611 (opens in a new tab)

set_score_request()

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:

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.sample_weight?string | booleanMetadata routing for sample\_weight parameter in score.

Returns

Promise<any>

Defined in: generated/pipeline/Pipeline.ts:648 (opens in a new tab)

transform()

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.

Signature

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

Parameters

NameTypeDescription
optsobject-
opts.X?anyData to transform. Must fulfill input requirements of first step of the pipeline.

Returns

Promise<ArrayLike[]>

Defined in: generated/pipeline/Pipeline.ts:685 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/pipeline/Pipeline.ts:27 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/pipeline/Pipeline.ts:26 (opens in a new tab)

_py

PythonBridge

Defined in: generated/pipeline/Pipeline.ts:25 (opens in a new tab)

id

string

Defined in: generated/pipeline/Pipeline.ts:22 (opens in a new tab)

opts

any

Defined in: generated/pipeline/Pipeline.ts:23 (opens in a new tab)

Accessors

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/pipeline/Pipeline.ts:51 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/pipeline/Pipeline.ts:55 (opens in a new tab)