# Description Creates 2 new models in the scope of flagging: how good are we at identifying "at risk" bookings vs. 1) the number of claims generated and 2) the number of submitted payouts? This only applies for Protected Bookings in New Dash that have been completed (14 days after the check-out) with potential resolutions appearing in Resolutions Center. The first table `int_flagging_booking_categorisation` contains all the heavy logic to categorise the bookings. The second view `int_flagging_performance_analysis` computes standard binary classification scores, for the 2 possible ways of tracking. Tables are already in prod to help you understand while reviewing. You'll see that the figures are still quite low, specially due to small amount of claims/submitted payouts. This makes the true positives being just... 1. There's heavy test and documentation coverage to ensure there's no mistakes on the computation. # Checklist - [X] The edited models and dependants run properly with production data. - [X] The edited models are sufficiently documented. - [X] The edited models contain PK tests, and I've ran and passed them. - [X] I have checked for DRY opportunities with other models and docs. - [X] I've picked the right materialization for the affected models. **Materialising as table the first model despite being just 1 record since otherwise tests takes ages** # Other - [ ] Check if a full-refresh is required after this PR is merged. Related work items: #29284
106 lines
4.6 KiB
SQL
106 lines
4.6 KiB
SQL
with
|
|
int_flagging_booking_categorisation as (
|
|
select * from {{ ref("int_flagging_booking_categorisation") }}
|
|
)
|
|
select
|
|
'RISK_VS_CLAIM' as flagging_analysis_type,
|
|
completed_bookings as count_total,
|
|
-- TP
|
|
completed_risk_with_claim_bookings as count_true_positive,
|
|
-- TN
|
|
completed_no_risk_without_claim_bookings as count_true_negative,
|
|
-- FP
|
|
completed_risk_without_claim_bookings as count_false_positive,
|
|
-- FN
|
|
completed_no_risk_with_claim_bookings as count_false_negative,
|
|
-- TP %
|
|
cast(completed_risk_with_claim_bookings as decimal)
|
|
/ completed_bookings as true_positive_score,
|
|
-- TN %
|
|
cast(completed_no_risk_without_claim_bookings as decimal)
|
|
/ completed_bookings as true_negative_score,
|
|
-- FP %
|
|
cast(completed_risk_without_claim_bookings as decimal)
|
|
/ completed_bookings as false_positive_score,
|
|
-- FN %
|
|
cast(completed_no_risk_with_claim_bookings as decimal)
|
|
/ completed_bookings as false_negative_score,
|
|
-- RECALL: TP / (TP + FN)
|
|
cast(completed_risk_with_claim_bookings as decimal) / (
|
|
completed_risk_with_claim_bookings + completed_no_risk_with_claim_bookings
|
|
) as recall_score,
|
|
-- PRECISION: TP / (TP + FP)
|
|
cast(completed_risk_with_claim_bookings as decimal) / (
|
|
completed_risk_with_claim_bookings + completed_risk_without_claim_bookings
|
|
) as precision_score,
|
|
-- FALSE POSITIVE RATE: FP / (FP + TN)
|
|
cast(completed_risk_without_claim_bookings as decimal) / (
|
|
completed_risk_without_claim_bookings + completed_no_risk_without_claim_bookings
|
|
) as false_positive_rate_score,
|
|
-- F1 SCORE: 2*TP / (2*TP + FN + FP)
|
|
cast(2 * completed_risk_with_claim_bookings as decimal) / (
|
|
2 * completed_risk_with_claim_bookings
|
|
+ completed_no_risk_with_claim_bookings
|
|
+ completed_risk_without_claim_bookings
|
|
) as f1_score,
|
|
-- F2 SCORE: 5*TP / (5*TP + 4*FN + FP)
|
|
cast(5 * completed_risk_with_claim_bookings as decimal) / (
|
|
5 * completed_risk_with_claim_bookings
|
|
+ 4 * completed_no_risk_with_claim_bookings
|
|
+ completed_risk_without_claim_bookings
|
|
) as f2_score
|
|
from int_flagging_booking_categorisation
|
|
|
|
union all
|
|
|
|
select
|
|
'RISK_VS_SUBMITTED_PAYOUT' as flagging_analysis_type,
|
|
completed_not_awaiting_resolution_bookings as count_total,
|
|
-- TP
|
|
completed_risk_with_submitted_payout_bookings as count_true_positive,
|
|
-- TN
|
|
completed_no_risk_without_submitted_payout_bookings as count_true_negative,
|
|
-- FP
|
|
completed_risk_without_submitted_payout_bookings as count_false_positive,
|
|
-- FN
|
|
completed_no_risk_with_submitted_payout_bookings as count_false_negative,
|
|
-- TP %
|
|
cast(completed_risk_with_submitted_payout_bookings as decimal)
|
|
/ completed_not_awaiting_resolution_bookings as true_positive_score,
|
|
-- TN %
|
|
cast(completed_no_risk_without_submitted_payout_bookings as decimal)
|
|
/ completed_not_awaiting_resolution_bookings as true_negative_score,
|
|
-- FP %
|
|
cast(completed_risk_without_submitted_payout_bookings as decimal)
|
|
/ completed_not_awaiting_resolution_bookings as false_positive_score,
|
|
-- FN %
|
|
cast(completed_no_risk_with_submitted_payout_bookings as decimal)
|
|
/ completed_not_awaiting_resolution_bookings as false_negative_score,
|
|
-- RECALL: TP / (TP + FN)
|
|
cast(completed_risk_with_submitted_payout_bookings as decimal) / (
|
|
completed_risk_with_submitted_payout_bookings
|
|
+ completed_no_risk_with_submitted_payout_bookings
|
|
) as recall_score,
|
|
-- PRECISION: TP / (TP + FP)
|
|
cast(completed_risk_with_submitted_payout_bookings as decimal) / (
|
|
completed_risk_with_submitted_payout_bookings
|
|
+ completed_risk_without_submitted_payout_bookings
|
|
) as precision_score,
|
|
-- FALSE POSITIVE RATE: FP / (FP + TN)
|
|
cast(completed_risk_without_submitted_payout_bookings as decimal) / (
|
|
completed_risk_without_submitted_payout_bookings
|
|
+ completed_no_risk_without_submitted_payout_bookings
|
|
) as false_positive_rate_score,
|
|
-- F1 SCORE: 2*TP / (2*TP + FN + FP)
|
|
cast(2 * completed_risk_with_submitted_payout_bookings as decimal) / (
|
|
2 * completed_risk_with_submitted_payout_bookings
|
|
+ completed_no_risk_with_submitted_payout_bookings
|
|
+ completed_risk_without_submitted_payout_bookings
|
|
) as f1_score,
|
|
-- F2 SCORE: 5*TP / (5*TP + 4*FN + FP)
|
|
cast(5 * completed_risk_with_submitted_payout_bookings as decimal) / (
|
|
5 * completed_risk_with_submitted_payout_bookings
|
|
+ 4 * completed_no_risk_with_submitted_payout_bookings
|
|
+ completed_risk_without_submitted_payout_bookings
|
|
) as f2_score
|
|
from int_flagging_booking_categorisation
|