Skip to content

What is relational machine learning? ​

Relational machine learning uses records from tables linked by keys to make a prediction for each sample. For a customer, the model can use the customer's country together with the amounts and types of their orders.

From related records to one feature row ​

customersentity

PKcustomer_idcountry
c07CO
c12MX

ordersrelated

FKcustomer_idamount
c0724
c1242
c0736

featuresone row per customer

customer_idmean_amount
c0730
c1242
For customer c07, the mean order amount is (24 + 36) / 2 = 30.

A model that predicts once per customer needs one feature row per customer. The source tables describe different things, so they have different numbers of rows linked to that customer.

TableRows per customerExample columns
customers1customer_id, country, signup_channel
orders0 to hundredscustomer_id, amount, type
order_itemsmany per orderorder_id, product_id, quantity
products0 or more through order items, shared across customersproduct_id, category, price

A model that only sees customers can use country but has no order history. An aggregation can add that history as a feature, such as the number of express orders or the mean order amount. A direct join to orders would repeat the customer row and its label for every order. Before training a tabular model, summarize those orders at the level you predict for.

The three main approaches ​

Two related tables aggregated into one wide tableΣ

Propositionalization

Deep Feature Synthesis, Featuretools

Compute columns such as order count and mean purchase amount. The model receives one feature row per customer.

A related table feeding a decision tree whose split is a condition on its rowscount(orders[…]) > 2standardpremium

Relational learners

TILDE, relational trees and forests

At a split, search for an order condition that separates the labels. A customer follows a branch based on how many orders match.

Rows as nodes of a graph passing messages into an embedding vectorembedding

Relational deep learning

Graph neural networks, RelGT

Represent customers and orders as nodes connected by keys. A graph model combines information from neighboring nodes to predict for a customer.

scikit-link covers the first two approaches with the scikit-learn API.
  1. Propositionalization (flattening). Compute aggregations along each relationship, such as count, mean, mode or nunique, and join them into one row per sample. Use those features to fit a tabular model. The choice of features determines which information the model gets. For example, the number of express orders and the largest order amount leave out whether the largest order was express.
  2. Relational learners. Models whose splits or rules are themselves relational, like first-order decision trees (TILDE), multi-relational decision trees and first-order random forests. A split can learn to check whether a customer placed an express order over 100. The fitted rule names the rows and values it uses.
  3. Relational deep learning. Graph neural networks and transformers that treat rows as nodes and foreign-key links as edges. These models learn numerical representations from the graph. Explaining a prediction requires tools that can work with those representations. See task-level scores and the protocols behind them on the benchmarks page.

The main pitfall: leakage ​

Information can leak through the training split or the records used to compute a feature.

✕ Feature catalog fitted before splitting

c01c02c03c04c05c06
Choose order categories from all six customers.

A category seen only for c05 or c06 can enter the catalog used for evaluation.

✓ Feature catalog fitted on the training fold

c01c02c03c04
Choose order categories from c01 through c04.

Transform c05 and c06 with that catalog. Their orders can supply feature values during prediction.

training fold test fold
  • Between folds. When the training step chooses categories, thresholds or features, it can learn from held-out customers if it sees their rows first. Fit those choices inside each training fold. A fixed per-customer count can be computed in advance if it uses only records available for that sample.
  • Across time. If a sample uses orders placed after the prediction cutoff, its evaluation score comes from information the model would lack when making that prediction.

The split defines which samples may teach the model. The cutoff defines which timestamped records each sample can see. A temporal task usually needs both.

scikit-link covers the first two approaches with the scikit-learn API:

  • RelationalFeaturizer produces a table of features for the samples in X. Each column has a name such as mean(orders.amount).
  • Relational decision trees, random forests and gradient boosting learn conditions across tables directly.
  • Relational k-means and clustering trees group entities without a label, and a relational isolation forest finds unusual ones.
  • Both fit within scikit-learn cross-validation. They learn from rows reachable from the training samples and use per-sample cutoffs when configured.

scikit-link is in early development. See the roadmap and the comparison with other libraries.

Further reading ​

Glossary ​

The glossary defines these and more terms, each with a link you can cite.

  • Entity table. One row per entity, such as customers.
  • Population table (X). One row per sample. Each row names its entity and can carry a prediction cutoff. Several samples can refer to the same entity.
  • Relationship. A foreign key from a child table to a parent table, such as orders.customer_id → customers.customer_id.
  • Aggregation. A function that summarizes related rows for a sample, such as count(orders) or mean(orders.amount).
  • Cutoff time. The point in time a prediction represents. scikit-link excludes timestamped rows at or after the cutoff by default.

Released under the MIT License.