---
url: /faq.md
description: >-
  Answers about machine learning on related tables in Python: scikit-learn,
  Featuretools, leakage, explanations, clustering, text columns and
  installation.
---

# Frequently asked questions

**Short answers about training models on several related tables with
scikit-link and scikit-learn.** Each answer links to the page that covers it
in depth, and the [glossary](./glossary) defines the terms.

## Can scikit-learn train on multiple tables?

Not directly: every scikit-learn estimator expects one table with one row per
sample. With several tables, such as customers and their orders, you either
flatten them first with `groupby` and `merge`, or use scikit-link, whose
transformer and models read the related tables and still behave like
scikit-learn estimators in pipelines, grid searches and cross-validation.
[How to train a scikit-learn model on multiple tables](./blog/scikit-learn-multiple-tables)
walks through both.

## What is scikit-link?

scikit-link (`import sklink`) is an open-source Python library, MIT licensed,
for machine learning on tables linked by keys. `RelationalFeaturizer` turns
the related rows of each sample into columns for any estimator, and
relational decision trees, random forests and gradient boosting learn
aggregates and conditions, such as `count(orders[type == 'express'])`, while
they fit. Relational k-means and clustering trees group entities without a
label. It runs on a CPU.

## How is scikit-link different from Featuretools?

Both compute aggregates of related rows, an idea Featuretools popularized as
Deep Feature Synthesis. scikit-link's featurizer is a scikit-learn
transformer, so it is fitted inside each cross-validation fold and learns its
categories from the training rows only. Its trees, forests and boosted models also learn the
conditions inside an aggregate instead of choosing from a fixed list.
Featuretools has the larger catalog of primitives. The
[side-by-side comparison](./compare/featuretools) and the
[migration guide](https://scikit-link.rodrigo-arenas.com/stable/guides/migrate-from-featuretools)
map one to the other.

## How is it different from skrub and getML?

skrub joins and aggregates tables in the way you describe, inside
scikit-learn pipelines; scikit-link searches which paths, aggregations and
conditions to use, and the two can be combined. getML is a fast C++ engine
with its own API; its algorithms that learn conditions are in paid editions.
See the [comparison](./compare/).

## What is a relational decision tree?

A decision tree whose questions are about related rows, not only the columns
of one table: "does this customer have more than two express orders over
100?" At each node it searches the paths, aggregations and conditions on the
related tables and keeps the question that best separates the labels.
[Relational decision trees, explained](./blog/relational-decision-trees)
shows one step by step.

## How does scikit-link prevent data leakage?

In two ways. Everything learned from data, such as frequent categories and
split thresholds, is learned in `fit` from the training samples, so a
pipeline or a cross-validation fold never sees the test rows. And when each
sample has a cutoff date, only rows dated before it are visible to features
and splits; `TemporalCutoffSplit` then trains on earlier cutoffs and tests on
later ones. [Data leakage in multi-table features](./blog/leakage-multi-table-features)
explains both.

## Does scikit-link need a GPU or a database server?

No. It runs on a CPU, on tables in memory or in Parquet files, with NumPy
under the hood. Graph neural networks and relational foundation models are
the options that usually need a GPU.

## Which table formats does it accept?

pandas, Polars and PyArrow tables, Parquet files and dictionaries of NumPy
arrays, mixed freely in one `Database`. The predictions and features come
back as NumPy arrays, like scikit-learn's.

## Can I use XGBoost, LightGBM or any scikit-learn model?

Yes. `RelationalFeaturizer` is a transformer: put it in a `Pipeline` before
any estimator that accepts numeric input with missing values, such as
`HistGradientBoostingClassifier`, XGBoost or LightGBM; for others, add a
`SimpleImputer` first. The relational trees, forests and gradient boosting models are estimators of
their own.

## Does it handle regression and more than two classes?

Yes. There are classifiers and regressors for trees, forests and gradient
boosting, and the classifiers handle any number of classes, as in
scikit-learn. Gradient boosting also offers quantile regression, to predict a
range: see [relational gradient boosting](https://scikit-link.rodrigo-arenas.com/stable/tutorials/relational-gradient-boosting).

## Can it cluster or find anomalies without labels?

Yes. `RelationalKMeans` runs k-means on aggregates of each entity's related
rows, such as the transactions of an account or the readings of a machine.
`RelationalClusteringTree` finds clusters that each have a short definition
on the related tables, such as `count(orders) > 2.5`, which you can turn into
a SQL filter. See [cluster entities](https://scikit-link.rodrigo-arenas.com/stable/tutorials/clustering).
To find unusual entities instead, such as accounts whose payments are much
larger than everyone else's, `RelationalIsolationForest` runs an isolation
forest on the same aggregates. See
[find unusual entities](https://scikit-link.rodrigo-arenas.com/stable/tutorials/anomaly-detection).

## How do I explain a prediction?

`sklink.inspection.aggregate_importances` groups a model's importances by
table or by expression, such as `mean(orders.amount)`. For one sample,
`explain` gives a relational tree's decision path, or the expressions a
forest or gradient boosting model used, with their values at that sample's
cutoff; for gradient boosting, it also gives each expression's signed effect
on the prediction. `export_text` prints a relational tree as rules. See [inspect and explain](https://scikit-link.rodrigo-arenas.com/stable/tutorials/inspect-and-explain).

## Can it use text columns or scikit-learn transformers on the tables?

Yes. `sklink.compose.TransformedTablesEstimator` fits scikit-learn
transformers, such as a `TfidfVectorizer` on a review column or a
`StandardScaler`, on the columns of a related table, using only the rows that
the training samples reach. The relational model then learns from the new
columns. See
[use scikit-link with scikit-learn](https://scikit-link.rodrigo-arenas.com/stable/guides/scikit-learn#transform-the-tables-with-scikit-learn).

## Is there a complete example from raw tables to a deployed model?

Yes. The [case studies](https://scikit-link.rodrigo-arenas.com/stable/case-studies/) combine several features on one
problem each: churn prediction with temporal validation and deployment,
ensembles and cost-based thresholds with scikit-learn, forecasts with
calibrated prediction intervals, and segments and anomalies without labels.

## How do I install it?

scikit-link needs Python 3.12 or later:

```bash
pip install "scikit-link[pandas]"
```

The extra installs pandas; use `[polars]` or `[pyarrow]` for those formats.
The [installation guide](https://scikit-link.rodrigo-arenas.com/stable/getting-started/installation)
covers the details.
