Skip to content
Notifications
Clear all

How do I get started with custom metrics for business KPIs?

1 Posts
1 Users
0 Reactions
1 Views
(@consulting_contractor_mike)
Estimable Member
Joined: 4 months ago
Posts: 123
Topic starter   [#6391]

Based on several recent client engagements migrating from in-house model monitoring to Arize, I've found the "out-of-the-box" drift and performance metrics are necessary but insufficient. The real business value often comes from instrumenting custom metrics that tie model behavior directly to operational and financial outcomes. Arize's platform is flexible enough to handle this, but the path isn't always obvious from the documentation alone.

The core concept is that you need to join your model's inference logs (sent to Arize via the `log_prediction` API call) with subsequent ground truth or business events. This often requires a two-step process: logging the prediction with a custom `prediction_id`, and later sending a matching `log_actual` or `log_valuation` call. The "valuation" terminology here is key—it's how Arize frames the concept of scoring a prediction based on a business outcome.

Let's walk through a concrete example. Suppose you have a fraud detection model. Your primary business KPI isn't just AUC; it's the **false positive cost**, where a legitimate transaction is declined. You need to calculate the monetary value lost per false positive.

**Step 1: Log the prediction with a unique key and any necessary metadata.**
```python
# At inference time
arize.log_prediction(
model_id="fraud-model-v2",
prediction_id=transaction_id,
features={"amount": 1500.00, "user_country": "US", ...},
prediction_label="decline", # model's decision
prediction_score=0.87, # model's confidence
tags={"transaction_amount_usd": 1500.00} # Crucial: log the amount for later calculation
)
```

**Step 2: Later, when the business outcome is known, log the actual and the valuation.**
This is where you compute the custom metric. The valuation score could be the actual dollar amount lost.
```python
# In a separate batch or event-driven process, after manual review/chargeback data is in
if was_false_positive: # Model said 'decline', but transaction was legitimate
# Calculate cost. Maybe a fixed fee + lost amount.
cost_kpi = transaction_amount + 10.00

arize.log_actual(
model_id="fraud-model-v2",
prediction_id=transaction_id,
actual_label="approve" # The correct outcome
)

arize.log_valuation(
model_id="fraud-model-v2",
prediction_id=transaction_id,
valuation_name="false_positive_cost_usd",
valuation_score=cost_kpi
)
```

**Key Implementation Pitfalls:**
* **Idempotency:** Ensure your `prediction_id` is truly unique and stable across the `log_prediction` and `log_valuation` calls. Duplicate IDs can cause data corruption.
* **Latency:** Business outcomes may arrive hours or days later. Your pipeline for `log_valuation` must handle this delay. Arize will join the data asynchronously.
* **Aggregation:** Once logged, you'll create a **Custom Metric** in the Arize UI. You'll define the aggregation (e.g., `SUM`, `AVG`) of your valuation scores. This is where you'd create a dashboard widget for "Total False Positive Cost Last 7 Days."
* **Attribution:** Use tags and features logged at prediction time to slice these custom metrics. For instance, you might want to see false positive cost by `user_country` or by `transaction_amount_usd` bucket.

The most powerful patterns I've seen involve using these custom valuations to drive automated actions. By setting monitors on the custom KPI metric (e.g., "false positive cost exceeds $X per hour"), you can trigger alerts or even feed data back into your model retraining pipeline. The main limitation is that you are responsible for the correctness and reliability of the pipeline that calculates and sends the valuation score—Arize provides the bucket, but you have to fill it.

For teams just starting, I recommend instrumenting one critical business KPI first. The fraud cost example is a classic. Another is **recommendation system gross merchandise value (GMV)** per user session, where you value each prediction based on whether the recommended item was clicked and purchased.

What specific business KPI are you trying to capture? The approach can vary significantly between, say, LTV predictions and supply chain forecasting.

- Mike


Mike


   
Quote