Data Preparation Best Practices
Use these practices to prepare source tables before building a Kumo Relational schema.
Table Structure and Entity Design
Apply the following practices when you design tables. The examples are fragments that operate on an existing DataFrame named df:
-
Model one entity type or event type per table:
-
Use a single event-time column per table:
-
Model many-to-many relationships with junction tables:
Data Preparation
Apply the following practices when you prepare the data:
-
Modify dtypes at the
pandas.DataFramelevel before building a schema: -
Use consistent naming conventions:
Relationship inference links a column only to a primary key of exactly the same name, so
orders.user_idfindsusers.user_idbut notusers.id. A name shared by more than one table’s primary key is ambiguous and links nothing. -
Keep primary keys unique and non-null:
Plan Semantic Types
Before building the schema, determine how Kumo Relational must interpret important columns:
- Identifiers and relationship keys must use
ID. - Leave free-form descriptions out of the request. The model does not read
textfeatures, and the endpoint refuses a request that includes atextcolumn. Refer to Data Types. - Labels from a finite set must use
categorical. - Quantities and measurements must use
numerical. - Event times must use
timestamp.
After building the schema, review and correct the inferred semantic types.
Plan Prediction-Ready Relationships
Consider the PQL queries that you want to run when preparing source tables. For example, predicting future transaction activity for each user requires an entity table for users, a timestamped event table for transactions, and a key that relates each transaction to a user.
Common Data Modeling Patterns
Entity-Event Pattern
The following example pairs a users entity table with a transactions event table:
Hierarchical Entities
The following example models a company, department, and employee hierarchy as three linked tables:
Junction Table for a Many-to-Many Relationship
The following example relates products and categories through a junction table:
Pairs Table for Ranking Over a Fixed Candidate Set
The following example builds one row per customer and product pair that you want scored:
Refer to Prediction Types for why this pattern scales better than ranking a raw candidate list.
Summary
Following these best practices helps ensure that your Kumo Relational datasets are well-structured, validated, and optimized for performance.
Table design:
- Model one entity type or event type per table.
- Use a single event-time column per table.
- Use unique primary keys with consistent key names.
- Model many-to-many relationships with junction tables.
Data preparation:
- Set the appropriate pandas dtypes before building the schema.
- Plan meaningful semantic types such as
ID,categorical, andnumerical, and plan to leave outtextcolumns.
Relationship planning:
- Prepare consistent key columns for meaningful relationships between entities.
- Consider PQL query requirements when structuring the data.
These patterns help produce source data that is ready for schema building.