RFM Analysis

RFM Analysis#

rfm_res = df_sales.analysis.rfm(
    user_id_col='customer_unique_id'
    , order_id_col='order_id'
    , date_col='order_purchase_dt'
    , revenue_col='total_payment'
    , upper_quantile=0.99
    , return_rfm=True
)

Let’s examine the distributions of Recency, Frequency, and Monetary.

rfm_res['hist']
../../_images/907bb3074faee07062959baf738515d836315151aa1a93ec07dc1e6006560f34.jpg

Let’s look at the RFM heatmap where color represents Monetary.

fig = rfm_res['heat']
pb.to_slide(fig)
fig.show()
../../_images/7a367ef850d71317deb1d8072b619b461aeb8f36a33d94d49641f2ff3c886f7f.jpg

Key Observations:

  • The FR segment 33 generates the highest payments - frequent recent buyers.

Let’s examine the distribution of customers by RFM pairwise combinations.

fig = rfm_res['heat_pairs']
pb.to_slide(fig)
fig.show()
../../_images/c6b07ee2c2cb343f651b2d8788cecfde49987362ef402fb5b4fc77d5d30a5d4c.jpg

Key Observations:

  • The FM segment 33 clearly stands out in terms of customer count - frequent high-value buyers.

Let’s examine slices of the FM pair by R.

fig = rfm_res['heat_sliced']
pb.to_slide(fig)
fig.show()
../../_images/31b13cbcd405e789a7938f2a9ba6ee2cafb2b1118b81c37f3bda620dba2eb0cb.jpg

Key Observations:

  • The FM33 segment contains the most R=3 customers - frequent recent high-value buyers.

Let’s look at the distribution by segments.

fig_tree = rfm_res['seg_tree']
fig_bar = rfm_res['seg_bar']
pb.to_slide(fig_tree, '_treemap')
pb.to_slide(fig_bar, '_bar')
fig_tree.show()
fig_bar.show()
../../_images/38f12def1eb8dcad1d19ddb85bd6a7b3d069b66ece96ec6a79f5c3722d40dd13.jpg ../../_images/c5f9ceea67a59e85154c05ad1672e0cfb5dcd7c3fa80526869be0b962a908465.jpg

Key Observations:

  • Largest segments: Hibernating (22%), About to Sleep (18%), Promising (14%) - mostly inactive customers.

  • Champions: 4%, Loyal: 7%, Lost: 4%.

Save the RFM dataframe for clustering.

df_rfm = rfm_res['df_rfm']
del rfm_res