Skip to content

scikit-link documentation ​

Use scikit-link when one prediction draws on several tables, such as a customer and their orders, a patient and their visits, or a machine and its sensor readings. Each row of X identifies one entity, and a Database holds the tables and the keys that connect them. The guides use a small shop of customers and orders because it is easy to follow; the same code works for any tables linked by keys.

You could compute such columns yourself with groupby and merge. scikit-link does it inside a scikit-learn pipeline, so each cross-validation fold learns its features only from its training rows, and with dates it uses only the rows that existed at each prediction date. Its trees can also learn which related rows to count, such as express orders above an amount, instead of using a fixed list of aggregates. New to the idea? Read what relational machine learning is.

Run your first model ​

  1. Install scikit-link with pandas.
  2. Fit a model on the shop dataset. The data comes with the package. By the end you can read the rule that predicts a customer's label.
  3. Learn the core ideas: the database, the entity table, X, canonical names and cutoffs.
  4. Describe your own database. Choose the table you predict for and connect a second table by its foreign key.
  5. Build X and y from your own tables: one row per prediction, and a label that does not leak.

How orders become features ​

A customer can appear on several order rows. To use order amounts in a customer model, follow the customer key and compute one value for that customer.

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 featurizer does this calculation for a scikit-learn pipeline. A relational tree can also learn which orders to include in a split, for example only express orders above a certain amount.

Find what you need ​

For terminology, read core concepts. If you already work with scikit-learn, use scikit-link with scikit-learn shows pipelines, searches, ensembles and transformers on the tables. If you use Featuretools, start with the migration guide.

Released under the MIT License.