NumPy allowed · plain Python earns 10 bonus points
Computed matrix × vector transformation
Track customer cohort lifecycles and retention decay over elapsed time periods.
Implement build_cohort_retention_matrix(events): each event contains user_id, cohort_month, and activity_month. Calculate period = activity_month - cohort_month. The base size of a cohort is its total unique users. Compute retention percentage (active_users_in_period / cohort_base_size) * 100.0. Return nested dictionary {str(cohort): {'period_0': pct, ...}} with percentages rounded to 4 decimals.
build_cohort_retention_matrix(events: list[dict]) -> dict[str, dict[str, float]]