|
1 | 1 | .. _user_guide_data_ops_index: |
2 | 2 |
|
3 | | -Complex multi-table pipelines with Data Ops |
4 | | -=========================================== |
5 | | - |
6 | | -Skrub provides an easy way to build complex, flexible machine learning pipelines. |
7 | | -There are several needs that are not easily addressed with standard scikit-learn |
8 | | -tools such as :class:`~sklearn.pipeline.Pipeline` and |
9 | | -:class:`~sklearn.compose.ColumnTransformer`, and for which the skrub DataOps offer |
10 | | -a solution: |
11 | | - |
12 | | -- Multiple tables: We often have several tables of different shapes (for |
13 | | - example, "Customers", "Orders", and "Products" tables) that need to be |
14 | | - processed and assembled into a design matrix ``X``. The target ``y`` may also |
15 | | - be the result of some data processing. Standard scikit-learn estimators do not |
16 | | - support this, as they expect right away a single design matrix ``X`` and a |
17 | | - target array ``y``, with one row per observation. |
18 | | -- DataFrame wrangling: Performing typical DataFrame operations such as |
19 | | - projections, joins, and aggregations should be possible and allow leveraging |
20 | | - the powerful and familiar APIs of `Pandas <https://pandas.pydata.org>`_ or |
21 | | - `Polars <https://docs.pola.rs/>`_. |
22 | | -- Hyperparameter tuning: Choices of estimators, hyperparameters, and even |
23 | | - the pipeline architecture can be guided by validation scores. Specifying |
24 | | - ranges of possible values outside of the pipeline itself (as in |
25 | | - :class:`~sklearn.model_selection.GridSearchCV`) is difficult in complex |
26 | | - pipelines. |
27 | | -- Iterative development: Building a pipeline step by step while inspecting |
28 | | - intermediate results allows for a short feedback loop and early discovery of |
29 | | - errors. |
30 | | - |
31 | | -In this section we cover all about the skrub Data Ops, from starting out with a |
32 | | -simple example, to more advanced concepts like parameter tuning and and pipeline |
33 | | -validation. |
| 3 | +.. currentmodule:: skrub |
| 4 | + |
| 5 | +Building complete pipelines with DataOps |
| 6 | +======================================== |
| 7 | + |
| 8 | +A skrub DataOp is a complete machine learning pipeline —from data loading and |
| 9 | +wrangling to the final prediction— in a single object that can be fitted, tuned, |
| 10 | +cross-validated, and saved in a file like any scikit-learn estimator. |
| 11 | + |
| 12 | +By integrating the whole data processing, DataOps help to validate pipelines |
| 13 | +while **avoiding data leakage**, to **tune complex modelling choices**, and to keep |
| 14 | +track of important **fitted (learned) state**. |
| 15 | + |
| 16 | +To solve a machine-learning task we often need to combine multiple operations |
| 17 | +such as loading and filtering data, joining tables and computing aggregations, |
| 18 | +extracting numerical features, and fitting a classifier or regressor. |
| 19 | + |
| 20 | +**Storing state** Each of those operations may need to be fitted: to learn some |
| 21 | +information from training data and reuse it to apply consistent transformations |
| 22 | +to new data. This is the case for transformers like the |
| 23 | +:class:`~sklearn.preprocessing.StandardScaler` and :class:`TableVectorizer` and |
| 24 | +estimators like :class:`~sklearn.ensemble.RandomForestClassifier`. |
| 25 | + |
| 26 | +**Tuning** Moreover, each processing step may involve decisions that need to be |
| 27 | +tuned (*tuning* means finding the value that gives the best predictive |
| 28 | +performance), for example: what weather forecast features should I include to |
| 29 | +predict the load on an electric grid? How should I encode a product description |
| 30 | +to help predict the product's category? What learning rate to set on a |
| 31 | +:class:`~sklearn.ensemble.HistGradientBoostingRegressor`? |
| 32 | + |
| 33 | +**Validation** Finally, the quality of predictions must be evaluated on |
| 34 | +held-out data (with a train/test split or cross-validation), taking care to |
| 35 | +**avoid leakage** of test data into the training set. |
| 36 | + |
| 37 | +Separating the data wrangling from the fitted estimator prevents correctly |
| 38 | +handling the tasks above. Skrub DataOps help by binding an arbitrary set of |
| 39 | +transformations of any number of inputs in a single estimator. These |
| 40 | +transformations can be easily parametrized with tunable choices. The resulting |
| 41 | +objects have built-in methods for cross-validation and tuning with either Optuna |
| 42 | +or scikit-learn, and for inspecting runs and intermediate results. Once fitted, |
| 43 | +they can be saved in a file, loaded, applied to new data as easily as a single |
| 44 | +:class:`~sklearn.linear_model.LogisticRegression`. |
| 45 | + |
| 46 | +.. dropdown:: Going beyond the scikit-learn Pipeline |
| 47 | + :color: primary |
| 48 | + |
| 49 | + To some extent, the DataOps exist for the same reasons as the simpler |
| 50 | + scikit-learn :class:`sklearn.pipeline.Pipeline` used in other parts of this |
| 51 | + documentation. However the Pipeline is too limited for many real-world problems: |
| 52 | + it can only represent a linear sequence of scikit-learn transformers, the design |
| 53 | + matrix and target variables must be constructed and divided into training and |
| 54 | + testing sets outside of the pipeline and the number of rows cannot change, only |
| 55 | + a single table can be handled, hyperparameter choices are difficult to define, |
| 56 | + etc. . Skrub DataOps remove those limitations and add several useful features |
| 57 | + such as interactive previews and integration with Optuna. |
34 | 58 |
|
35 | 59 | Data Ops basic concepts |
36 | 60 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
0 commit comments