Machine learning with dataframes

skrub is a Python library to ease preprocessing and feature engineering for tabular machine learning.
We directly connect database tables to machine learning.

Interactive Data Exploration

Explore your dataframes interactively with TableReport.

from skrub import TableReport
TableReport(df)

Try it on your dataset →

Click anywhere on the table

Please enable javascript

The skrub table reports need javascript to display correctly. If you are displaying a report in a Jupyter notebook and you see this message, you may need to re-execute the cell or to trust the notebook (button on the top right or "File > Trust notebook").

Effortless Tabular Learning

The Table Vectorizer

Turn your mixed-type dataframe into a numeric feature matrix with the TableVectorizer. Automatically performs preprocessing of the data, such as standardizing missing values and parsing dates, before encoding based on whether a column contains numbers, strings, or datetimes.

The Tabular Pipeline

Choose regression or classification and let tabular_pipeline do the rest. Use the power of the TableVectorizer to immediately create a scikit-learn baseline model with good defaults for each column
based on the datetype.

Given a complex dataframe df: (expand for full code)
from skrub.datasets import fetch_employee_salaries
dataset = fetch_employee_salaries()
df = dataset.X
y = dataset.y
df
gender department department_name division assignment_category employee_position_title date_first_hired year_first_hired
1 M FRS Fire and Rescue Services Third Battalion - Administration Fulltime-Regular Fire/Rescue Lieutenant 06/07/2004 2004
2 M HHS Department of Health and Human Services Environmental Health and Regulatory Services Fulltime-Regular Environmental Health Specialist III 02/20/2007 2007
... ... ... ... ... ... ... ... ...
9226 M DGS Department of General Services Facilities Maintenance Fulltime-Regular Master Plumber 03/26/2001 2001
9227 F HHS Department of Health and Human Services Infants and Toddlers Fulltime-Regular Program Specialist II 03/25/2013 2013
from sklearn.model_selection import cross_val_score
from skrub import tabular_pipeline

pipeline = tabular_pipeline('regressor')
Pipeline(steps=[('tablevectorizer',
                 TableVectorizer(low_cardinality=ToCategorical())),
                ('histgradientboostingregressor',
                 HistGradientBoostingRegressor())])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
cross_val_score(pipeline, df, y)
array([0.89370447, 0.89279068, 0.92282557, 0.92319094, 0.92162666])

Powerful Feature Engineering

Encode text and high cardinality categorical data:

Extract temporal features with:

Robustly scale and clip numerical features with:

Many more transformations, all scikit-learn
compatible
. All transformers can be applied
to a custom selection of columns using ApplyToCols.

The skrub DataOps framework

Custom trainable pipelines

Discover the skrub DataOps →

Leakproof cross-validation

  • Include the construction of X and y in the pipeline itself.
  • Evaluate without data leakage with the built-in cross-validation.
  • Tune data pipeline decisions, not only hyperparameters:
    • Combine and nest the choose_* functions to build extensive hyperparameter grids with no effort.
    • Explore the hyperparameter space with scikit-learn or Optuna.

Tune and validate your pipelines →

features = order_ids.skb.apply_func(    join_orders_products,    vectorized_products,-    agg_func="mean",+    agg_func=skrub.choose_from(["mean", "sum"]),)pred = features.skb.apply(-    HistGradientBoostingClassifier(learning_rate=0.1),+    HistGradientBoostingClassifier(+        learning_rate=skrub.choose_float(0.01, 0.5, log=True)+    ),    y=fraud_flags,)

Our Community

The skrub project is powered by the efforts of a world-wide community of contributors. Here we display a randomly selected group of 30 contributors.

Try it yourself!

Ready to write less code and get more insights? Dive into skrub now and be part of an emerging community!