Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-207

Cohort Retention Mean

Problem

Compute the mean retention for a period across cohorts. retention_matrix[c][p] is the fraction of cohort c retained in period p; rows shorter than period + 1 are skipped.

Return 0.0 when no cohort has that period.

Hint

Younger cohorts have not lived long enough to contribute to later periods.

Test cases

case 1
in: [[[1,0.5,0.2],[1,0.4],[1,0.6,0.3]],1]
expected: 0.5
case 2
in: [[[1,0.5,0.2],[1,0.4],[1,0.6,0.3]],2]
expected: 0.25
case 3
in: [[[1,0.5],[1,0.5]],0]
expected: 1
case 4
in: [[[1]],3]
expected: 0
Starter codePython
def cohort_retention_mean(retention_matrix, period):
    # Your code here
    pass

4 test cases · run your code against them in the editor