What Is a Modeling Pipeline?
A pipeline is a linear sequence of data preparation options, modeling operations, and prediction transform operations.
It allows the sequence of steps to be specified, evaluated, and used as an atomic unit.
- Pipeline: A linear sequence of data preparation and modeling steps that can be treated as an atomic unit.
To make the idea clear, let’s look at two simple examples:
The first example uses data normalization for the input variables and fits a logistic regression model:
- [Input], [Normalization], [Logistic Regression], [Predictions]
The second example standardizes the input variables, applies RFE feature selection, and fits a support vector machine.
- [Input], [Standardization], [RFE], [SVM], [Predictions]
You can imagine other examples of modeling pipelines.
As an atomic unit, the pipeline can be evaluated using a preferred resampling scheme such as a train-test split or k-fold cross-validation.
This is important for two main reasons:
- Avoid data leakage.
- Consistency and reproducibility.
A modeling pipeline avoids the most common type of data leakage where data preparation techniques, such as scaling input values, are applied to the entire dataset. This is data leakage because it shares knowledge of the test dataset (such as observations that contribute to a mean or maximum known value) with the training dataset, and in turn, may result in overly optimistic model performance.
Instead, data transforms must be prepared on the training dataset only, then applied to the training dataset, test dataset, validation dataset, and any other datasets that require the transform prior to being used with the model.
A modeling pipeline ensures that the sequence of data preparation operations performed is reproducible.
Without a modeling pipeline, the data preparation steps may be performed manually twice: once for evaluating the model and once for making predictions. Any changes to the sequence must be kept consistent in both cases, otherwise differences will impact the capability and skill of the model.
A pipeline ensures that the sequence of operations is defined once and is consistent when used for model evaluation or making predictions.
The Python scikit-learn machine learning library provides a machine learning modeling pipeline via the Pipeline class.