Skip to navigation

Make Predictions

View as Markdown

Use this workflow to request a prediction from Kumo Relational after you prepare your data and build and validate a graph. Describe the prediction task in Predictive Query Language (PQL), the query language that specifies what to predict and for which entities. Then associate the graph with a RelationalClient, the Python client for a Kumo Relational endpoint, and call predict(). To supply labeled context examples directly instead of deriving them from a PQL query, refer to Predict with Custom Context.

1. Write the query

This example asks Kumo Relational to predict the total value of orders that customer 101 will place over the next 30 days:

query = (
"PREDICT SUM(orders.amount, 0, 30, days) "
"FOR customers.customer_id=101"
)

The query identifies the target, entity, and - when applicable - the future horizon. Refer to Write Predictive Queries for the complete authoring workflow.

2. Run the prediction

Create a client for your Kumo Relational endpoint, associate it with the validated graph, and submit the query:

from kumo_relational_client import RelationalClient
with RelationalClient(url="http://localhost:8000") as client:
result = client.relational(graph).predict(query, run_mode="fast")
print(result)

Pass the api_key parameter to RelationalClient when an authenticating gateway protects the endpoint. Use HTTPS for authenticated remote deployments.

3. Predict for multiple entities

To request the same prediction for several entities, use FOR EACH in the query and pass their IDs through indices:

with RelationalClient(url="http://localhost:8000") as client:
result = client.relational(graph).predict(
"PREDICT SUM(orders.amount, 0, 30, days) "
"FOR EACH customers.customer_id",
indices=[101, 102, 103],
run_mode="fast",
)

Kumo Relational accepts no more than 1,000 entity IDs per inference call. Refer to Batch Prediction for larger jobs.

4. Read the result

The returned pandas DataFrame uses ENTITY to identify the requested entity and PREDICTION for a scalar output. Temporal requests can also include ANCHOR_TIMESTAMP, and some prediction types return additional fields. See Prediction Results for the complete result schema.

Next steps