mirror of
https://gitlab.com/cief-data/dbt_cloud.git
synced 2026-08-19 04:14:00 +00:00
Debug calculation formula to avoid infinity when log(0) is encountered
This commit is contained in:
@@ -107,7 +107,6 @@ compute_censored_subjects AS (
|
||||
|
||||
),
|
||||
|
||||
|
||||
compute_probability AS (
|
||||
|
||||
SELECT
|
||||
@@ -115,15 +114,25 @@ compute_probability AS (
|
||||
|
||||
-- The survival probability represents the probability of customers that will not churn up to a specific tenure
|
||||
-- Example: survival_day = 61, survival_prob = 95%. For customers with 61 days of tenure, the customer has a 95% chance of not churning.
|
||||
EXP(SUM(LN(1 - events / at_risk)) OVER (
|
||||
-- When events / at_risk = 1, we replace value 1 with a value very near to 1, to prevent log 0 which causes infinity value
|
||||
EXP(SUM(LN
|
||||
(
|
||||
CASE WHEN (1 - events / at_risk) = 0 THEN 0.999999 ELSE (1 - events / at_risk) END
|
||||
))
|
||||
OVER (
|
||||
ORDER BY survival_time_days ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
|
||||
)) AS survival_probability,
|
||||
|
||||
100 * (1 - EXP(SUM(LN(1 - events / at_risk)) OVER (
|
||||
100 * (1 - EXP(SUM(LN
|
||||
(
|
||||
CASE WHEN (1 - events / at_risk) = 0 THEN 0.999999 ELSE (1 - events / at_risk) END
|
||||
))
|
||||
OVER (
|
||||
ORDER BY survival_time_days ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
|
||||
))) AS conversion_percentage,
|
||||
|
||||
SUM(events / at_risk) OVER (
|
||||
SUM(events / at_risk)
|
||||
OVER (
|
||||
ORDER BY survival_time_days ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
|
||||
) AS cumulative_hazard,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user