metric_forge.ecommerce.polars_ext.Ecommerce_Polars.customer_lifetime_value#

Ecommerce_Polars.customer_lifetime_value(
revenue_per_customer_column: str,
average_customer_lifetime_column: str,
method='basic',
**kwargs,
) Expr[source]#

Calculate Customer Lifetime Value (CLV).

Basic Method:

\[CLV = R \times L\]

where:

  • CLV is the customer lifetime value,

  • R is the average revenue per customer,

  • L is the average customer lifetime.

Discounted

\[CLV_{discounted} = \frac{R \times L}{(1 + d)}\]

where:

  • d is the discount rate.

Parameters:
revenue_per_customer_column

Total revenue per customer measured yearly.

average_customer_lifetime_column

Number of years the customer is expected to be a paying customer.

method

The CLV method used. Can be any of the following:

  • basic (default): Simple calculation. Does not take other factors into account.

  • discounted: takes into account the present value of future cash flows

  • predictive: uses probabilities and costs to estimate the lifetime value

Returns:
Expr

Examples

>>> from metric_forge.ecommerce import * 
... import polars as pl
... data = pl.read_csv('datasets/ecommerce_metrics.csv')
>>> data.select(pl.col('revenue_per_customer'),
...             pl.col('average_customer_lifetime'),
...             pl.col('*').forge_ecommerce.customer_lifetime_value(revenue_per_customer_column='revenue_per_customer',average_customer_lifetime_column='average_customer_lifetime',method='basic'))
shape: (12, 3)
┌──────────────────────┬───────────────────────────┬─────────────────────────┐
│ revenue_per_customer ┆ average_customer_lifetime ┆ customer_lifetime_value │
│ ---                  ┆ ---                       ┆ ---                     │
│ f64                  ┆ f64                       ┆ f64                     │
╞══════════════════════╪═══════════════════════════╪═════════════════════════╡
│ 202.427329           ┆ 3.159364                  ┆ 639.54169               │
│ 116.173436           ┆ 1.812245                  ┆ 210.534716              │
│ 384.265156           ┆ 4.771414                  ┆ 1833.488253             │
│ 144.356328           ┆ 3.395462                  ┆ 490.156408              │
│ 275.734601           ┆ 3.77914                   ┆ 1042.039585             │
│ …                    ┆ …                         ┆ …                       │
│ 290.148089           ┆ 2.182535                  ┆ 633.258286              │
│ 325.310229           ┆ 1.421977                  ┆ 462.583676              │
│ 378.206435           ┆ 2.826138                  ┆ 1068.863683             │
│ 155.732582           ┆ 1.873762                  ┆ 291.805755              │
│ 341.766952           ┆ 2.66604                   ┆ 911.164293              │
└──────────────────────┴───────────────────────────┴─────────────────────────┘