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
memoryargument. 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_stepsorstepsto 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
fitmethod of each step, where each parameter name is prefixed such that parameterpfor stepshas keys__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
transformmethod of the intermediate steps as well, if requested, and if enable_metadata_routing=True is set viaset_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
predictcalled 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
transformmethod 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_stdorreturn_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
predictcalled 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
transformmethod of the intermediate steps as well, if requested, and if enable_metadata_routing=True is set viaset_config().See Metadata Routing User Guide for more details.
Note that while this may be used to return uncertainties from some models with
return_stdorreturn_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.
Inherited Methods
|
Transform the data, and apply decision_function with the final estimator. |
|
Fit the model and transform with the final estimator. |
|
Get output feature names for transformation. |
|
Get metadata routing of this object. |
|
Get parameters for this estimator. |
|
Apply inverse_transform for each step in a reverse order. |
|
Transform the data, and apply predict_log_proba with the final estimator. |
|
Transform the data, and apply predict_proba with the final estimator. |
|
Transform the data, and apply score with the final estimator. |
|
Transform the data, and apply score_samples with the final estimator. |
|
Set callbacks for the estimator. |
|
Set the output container when "transform" and "fit_transform" are called. |
|
Set the parameters of this estimator. |
|
Serializes triangle object to pickle. |
|
Transform the data, and apply transform with the final estimator. |