> ## Documentation Index
> Fetch the complete documentation index at: https://kumo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Make Predictions

> Guide to make predictions using RFM

Once you have created your graph, the next step is to frame a predictive problem — defining what you want to predict, who to predict for, and under what context.

Kumo provides a simple, declarative way to do this using the Predictive Query Language (PQL).

<Info>
  If you are familiar with Predictive query, scroll down to section "5. Run & fetch results" to get the code to make prediction on your graph
</Info>

## What is PQL?

**Predictive Query Language (PQL)** is a **declarative, SQL-like syntax** that lets you describe an entire machine learning task in a single statement.

A **predictive query** defines:

* The **target** value to predict,
* The **entity** or set of entities to make predictions for,
* And optionally, **filters** that refine the feature context.

Once defined, RFM automatically handles feature computation, time alignment, and train table generation - all based on your underlying graph.

## Anatomy of a Predictive Query

At its core, a predictive query follows this structure:

```python theme={null}
PREDICT <target_expression>
FOR <entity_specification>
[WHERE <filters>]
```

| Component            | Purpose                                                                                                                                                                                   |
| :------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PREDICT`            | Declares the **target** - the value you want the model to output. This can be a column or an aggregation over a *future* window (e.g., total spend in the next 30 days).                  |
| `FOR`                | Specifies **who** to predict for - the main entity of interest (e.g., customer, user, account). You provide an explicit ID or an `IN (...)` list.                                         |
| `WHERE` *(optional)* | Applies **contextual filters** to the data used for feature generation. Unlike `FOR`, it doesn’t limit which entities are predicted for - it only shapes the feature computation context. |

## Writing Queries in Kumo

To write a predictive query in Kumo, follow these five steps:

### 1. **Choose your entity**

Select the **table** and **primary key** column that represent the entity you’ll predict for.

Example:

```python theme={null}
FOR customer_id
```

This tells RFM to make predictions for each customer\_id

### 2. **Define the target**

The target defines **what outcome or value** the model should predict.\
It can be:

* A **raw column**, e.g., `PREDICT customer_churn_flag`
* Or an **aggregation over a future horizon**, e.g.:

```python theme={null}
PREDICT SUM(orders.PRICE, 0,30, days)
```

This tells RFM to predict total transaction amount over the next 30 days for each customer.

### 3. **Pin the entity list**

You can specify one entity or a group of entities explicitly:

```python theme={null}
FOR customer_id = 101
```

OR

```python theme={null}
FOR customer_id IN (101, 102, 103, 104)
```

This ensures RFM generates predictions only for the entities you care about.

### 4. **(Optional) Refine the context**

Use the `WHERE` clause to **control the feature generation window** or **apply static filters**.\
For example:

```python theme={null}
WHERE region = 'North America'
```

This does **not** change the entities you’re predicting for - it simply limits which historical data RFM uses when building features.

### 5. **Run & fetch results**

Execute your predictive query using the RFM client:

```python theme={null}
model = rfm.KumoRFM(graph)

query = """PREDICT SUM(orders.PRICE, 0, 30, days)
FOR customers.customer_id = 101
"""
prediction_result = model.predict(query)
print(prediction_result)
```

<Info>
  To see more examples on predictive query refer to [predictive query reference](https://kumo.ai/docs/examples/predictive-query/)
</Info>
