Pipeline#

class chainladder.Pipeline(steps, *, transform_input=None, memory=None, verbose=False)[source]#

This is a near direct of copy the scikit-learn Pipeline class.

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 to None. Read more in the User Guide.

Parameters:
steps: list

List of (name, transform) tuples (implementing fit/transform) that are chained, in the order in which they are chained, with the last object an estimator.

memory: None, str or object with the joblib.Memory interface, optional

Used to cache the fitted transformers of the pipeline. 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.

Attributes:
named_steps: bunch object, a dictionary with attribute access

Read-only attribute to access any step parameter by user given name. Keys are step names and values are steps parameters.

fit(X, y=None, sample_weight=None, **fit_params)[source]#

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:
Xiterable

Training data. Must fulfill input requirements of first step of the pipeline.

yiterable, default=None

Training targets. Must fulfill label requirements for all steps of the pipeline.

**paramsdict of str -> object
  • If enable_metadata_routing=False (default): Parameters 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.

  • If enable_metadata_routing=True: Parameters requested and accepted by steps. Each step must have requested certain metadata for these parameters to be forwarded to them.

Changed in version 1.4: Parameters are now passed to the transform method of the intermediate steps as well, if requested, and if enable_metadata_routing=True is set via set_config().

See Metadata Routing User Guide for more details.

Returns:
selfobject

Pipeline with fitted steps.

fit_predict(X, y=None, sample_weight=None, **fit_params)[source]#

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:
Xiterable

Training data. Must fulfill input requirements of first step of the pipeline.

yiterable, default=None

Training targets. Must fulfill label requirements for all steps of the pipeline.

**paramsdict of str -> object
  • If enable_metadata_routing=False (default): Parameters to the predict called at the end of all transformations in the pipeline.

  • If enable_metadata_routing=True: Parameters requested and accepted by steps. Each step must have requested certain metadata for these parameters to be forwarded to them.

Added in version 0.20.

Changed in version 1.4: Parameters are now passed to the transform method of the intermediate steps as well, if requested, and if enable_metadata_routing=True.

See Metadata Routing User Guide for more details.

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:
y_predndarray

Result of calling fit_predict on the final estimator.

predict(X, sample_weight=None, **predict_params)[source]#

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:
Xiterable

Data to predict on. Must fulfill input requirements of first step of the pipeline.

**paramsdict of str -> object
  • If enable_metadata_routing=False (default): Parameters to the predict called at the end of all transformations in the pipeline.

  • If enable_metadata_routing=True: Parameters requested and accepted by steps. Each step must have requested certain metadata for these parameters to be forwarded to them.

Added in version 0.20.

Changed in version 1.4: Parameters are now passed to the transform method of the intermediate steps as well, if requested, and if enable_metadata_routing=True is set via set_config().

See Metadata Routing User Guide for more details.

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:
y_predndarray

Result of calling predict on the final estimator.

to_json()[source]#

Serializes triangle object to json format

Returns:
string representation of object in json format

Inherited Methods

Pipeline.decision_function

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

Pipeline.fit_transform

Fit the model and transform with the final estimator.

Pipeline.get_feature_names_out

Get output feature names for transformation.

Pipeline.get_metadata_routing

Get metadata routing of this object.

Pipeline.get_params

Get parameters for this estimator.

Pipeline.inverse_transform

Apply inverse_transform for each step in a reverse order.

Pipeline.predict_log_proba

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

Pipeline.predict_proba

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

Pipeline.score

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

Pipeline.score_samples

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

Pipeline.set_callbacks

Set callbacks for the estimator.

Pipeline.set_output

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

Pipeline.set_params

Set the parameters of this estimator.

Pipeline.to_pickle

Serializes triangle object to pickle.

Pipeline.transform

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