Skip to main content

scikit-link

PyPI version Python versions CI Documentation License: MIT Ruff

Machine learning on multiple related tables, with the scikit-learn API.

Plenty of data lives in several tables: a customer and their orders, a patient and their visits, a machine and its sensor readings, an account and its transactions. scikit-link learns from those related rows directly. Put one entity key per row in X, describe the tables and their keys in a Database, and fit estimators that follow the keys inside ordinary scikit-learn pipelines and cross-validation.

Drawn with sklink.plotting: a database of customers, orders, order items and products linked by keys, and a relational decision tree of depth two that first asks about each customer's express orders, then follows the orders to their products and asks about the share of items that are toys.

Website · Quickstart · Documentation · Case studies · Benchmarks · Comparison · Roadmap

  • No hand-written joins and group-bys. The estimators compute aggregates of the related rows themselves, such as count(orders[type == 'express']), and relational trees learn which rows to count and with which conditions.
  • No leakage. Every fold of a cross-validation learns its features from its own training rows, and a cutoff date per row of X hides the rows that happened after it.
  • Rules you can read. A relational tree prints its splits as questions about the related tables, and explain shows what one prediction used.
  • Everything you know from scikit-learn. fit, predict, Pipeline, GridSearchCV, ensembles and threshold tuning work as usual, and RelationalFeaturizer feeds any scikit-learn model, XGBoost or LightGBM.

Install

scikit-link requires Python 3.12 or later. Install it from PyPI:

pip install "scikit-link[pandas]"

The extra installs pandas, which the examples use; [polars] and [pyarrow] are the other table formats. Numba installs with the package and compiles the tree loops, with the same models. The distribution is called scikit-link and the import is sklink.

Quickstart

Open in Colab

from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.model_selection import cross_val_score
from sklearn.pipeline import make_pipeline
from sklink.datasets import make_relational_classification
from sklink.feature_extraction import RelationalFeaturizer
from sklink.inspection import export_text
from sklink.tree import RelationalDecisionTreeClassifier

# A Database of customers, orders, order items and products, and X with one
# row per customer. Build your own with sklink.Database(tables=...,
# primary_keys=..., relationships=[("orders.customer_id", "customers.customer_id")]).
db, X, likes_toys = make_relational_classification(
    1000, signal="multihop", random_state=0
)

# The label hides a rule across tables: customers who buy toys (order items
# and their products) and placed an express order above 100 (orders).
orders = db.table("orders")
big_express = orders.query("type == 'express' and amount > 100")["customer_id"]
y = (likes_toys & X["customer_id"].isin(big_express)).astype(int)

# 1. Relational features for any scikit-learn estimator.
pipe = make_pipeline(
    RelationalFeaturizer(db, entity="customers", key="customer_id"),
    HistGradientBoostingClassifier(),
)
print(f"accuracy {cross_val_score(pipe, X, y, cv=5).mean():.3f}")

# 2. A decision tree that learns conditions across tables.
tree = RelationalDecisionTreeClassifier(
    db, entity="customers", key="customer_id", max_depth=2, min_impurity_decrease=0.01
)
print(export_text(tree.fit(X, y)))
accuracy 0.959
|--- exists(orders[amount > 100.55 & type == 'express']) <= 0.500
|   |--- class: 0
|--- exists(orders[amount > 100.55 & type == 'express']) >  0.500
|   |--- proportion(orders.order_items[products.category == 'toys']) <= 0.100
|   |   |--- class: 0
|   |--- proportion(orders.order_items[products.category == 'toys']) >  0.100
|   |   |--- class: 1

What you can do

Task How it works
Turn related rows into features for any estimator RelationalFeaturizer aggregates the related rows of each entity into columns, such as the number of visits or the mean transaction amount, one row per sample, for any scikit-learn model.
Classify or regress directly on related tables Relational decision trees, random forests and gradient boosting learn which related rows to aggregate while they fit. A split can ask whether an entity has any related row above a learned threshold within a learned category.
Cluster entities or find anomalies, without labels RelationalKMeans and RelationalClusteringTree group entities by their related rows; RelationalIsolationForest ranks the entities whose related rows look unlike anyone else's.
Prepare the tables with scikit-learn TransformedTablesEstimator fits scikit-learn transformers, such as a text embedding or a scaler, on the related rows that the training samples reach, and the model learns from the transformed tables.
Predict at a point in time without leakage Give each sample a cutoff date so only earlier rows are used, and validate on later periods with TemporalCutoffSplit. Every fold learns its categories and thresholds from its training samples only.
Explain a prediction sklink.inspection traces the decision path of one sample, groups feature importances by table or column, and exports fitted rules as text or JSON.
Plot the schema and the model sklink.plotting draws the tables and keys, a fitted tree, importances and the path of one prediction, as in the gallery below.
Use the tables you already have A Database takes pandas, Polars or PyArrow tables, dictionaries of NumPy columns, or Parquet file paths, read a few columns at a time to keep memory low on large tables. Composite keys, several levels of relationships and dated rows are supported.
Add your own aggregations Register a custom primitive, such as the spread between the largest and smallest value, and request it by name.
Save and deploy a model sklink.detach drops the tables before pickling, and sklink.rebind attaches fresh tables to score new entities.
Fit faster The tree loops are compiled with Numba, which installs with the package, and n_jobs grows forest trees in parallel, with the same fitted model.

The examples use a small shop, with customers, orders, order items and products, because it is easy to follow; the same code applies to any tables linked by keys.

These four sklink.plotting displays use the customers and orders from sklink.datasets.load_shop(). The target marks customers who placed at least three orders. Select a figure for the full-size view or see how to create it in the plotting reference.

The customer primary key links 24 customers to 56 orders.
Database schema
The selected customer follows the branch for more than 2.5 orders.
Decision tree
A flow diagram breaks down forest importance by table, column and aggregation.
Feature importance
Order count occurs on 10 of the 16 decision paths for this customer.
One prediction

Learn by example

How it compares

scikit-link Featuretools getML community skrub
scikit-learn estimator API Yes Partial No Yes
Learns conditions inside aggregations Yes No No No
Native trees, forests and gradient boosting on related tables Yes No No No
Install on Windows and macOS without Docker Yes Yes No Yes

skrub and scikit-link are meant to work together. The comparison page explains when to use each one, and the benchmarks compare scikit-link with gradient boosting on hand-built features, on the same splits and tuning budget.

Contribute

scikit-link is young, and contributions of every size help:

  • Share your schema. Tell us about your tables and task in Discussions; real use cases decide what comes next.
  • Report a bug or ask for a feature in Issues.
  • Add an aggregation. A new primitive is a small, self-contained first pull request; see custom primitives.
  • Add a benchmark dataset or a documentation example.

CONTRIBUTING.md covers the development setup, the checks and the testing policy. Security reports follow SECURITY.md. If scikit-link is useful to you, a star on GitHub helps others find it.

Citing

If scikit-link helps your research, please cite it. GitHub's "Cite this repository" button reads CITATION.cff; in BibTeX:

@software{arenas_scikit_link,
  author  = {Arenas, Rodrigo},
  title   = {scikit-link: Machine learning on multiple related tables, with the scikit-learn API},
  year    = {2026},
  url     = {https://github.com/rodrigo-arenas/scikit-link},
  license = {MIT}
}

License

MIT

Metadata

Release files for scikit-link 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scikit-link 0.1.0
File Size Uploaded Provenance Actions
scikit_link-0.1.0.tar.gz 496.9 kB With provenance Details for scikit_link-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scikit-link 0.1.0
File Interpreter ABI Platform Actions
scikit_link-0.1.0-py3-none-any.whl Python 3 none any Details for scikit_link-0.1.0-py3-none-any.whl

Total release size: 883.0 kB

Security for scikit-link 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page