{"id":2803,"date":"2025-01-24T20:40:26","date_gmt":"2025-01-24T20:40:26","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=2803"},"modified":"2025-01-24T20:40:32","modified_gmt":"2025-01-24T20:40:32","slug":"rfm-analysis-a-comprehensive-guide-to-customer-segmentation","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2025\/01\/24\/rfm-analysis-a-comprehensive-guide-to-customer-segmentation\/","title":{"rendered":"RFM Analysis: A Comprehensive Guide to Customer Segmentation"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-medium\"><img fetchpriority=\"high\" decoding=\"async\" width=\"300\" height=\"300\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2025\/01\/Bin-3-300x300.jpeg\" alt=\"\" class=\"wp-image-2805\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2025\/01\/Bin-3-150x150@2x.jpeg 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2025\/01\/Bin-3-1024x1024.jpeg 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2025\/01\/Bin-3-150x150.jpeg 150w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2025\/01\/Bin-3-1536x1536.jpeg 1536w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2025\/01\/Bin-3.jpeg 2048w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2025\/01\/Bin-3-300x300@2x.jpeg 600w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">What is RFM Analysis?<\/h2>\n\n\n\n<p>RFM (Recency, Frequency, Monetary) Analysis is a customer segmentation technique that uses three key metrics:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Recency: How recently a customer made a purchase<\/li>\n\n\n\n<li>Frequency: How often they purchase<\/li>\n\n\n\n<li>Monetary: Total amount spent<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Statistical Approach to Binning in RFM<\/h3>\n\n\n\n<p>Binning is critical in RFM to categorize customers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Divide each metric into quartiles (4 equal segments)<\/li>\n\n\n\n<li>Assign scores 1-4 for each dimension<\/li>\n\n\n\n<li>Create customer segments based on combined scores<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Python Example:<\/h2>\n\n\n\n<pre class=\"wp-block-code has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-9d883227e4ce0060fc2922dad18cdf5b\"><code>import pandas as pd\nimport numpy as np\n\ndef rfm_segmentation(df):\n    # Calculate RFM metrics\n    rfm = df.groupby('customer_id').agg({\n        'order_date': lambda x: (df&#91;'order_date'].max() - x.max()).days,\n        'order_id': 'count',\n        'total_amount': 'sum'\n    })\n    \n    # Rename columns\n    rfm.columns = &#91;'Recency', 'Frequency', 'Monetary']\n    \n    # Create quartile-based scoring\n    rfm&#91;'R_rank'] = pd.qcut(rfm&#91;'Recency'], q=4, labels=&#91;4,3,2,1])\n    rfm&#91;'F_rank'] = pd.qcut(rfm&#91;'Frequency'], q=4, labels=&#91;1,2,3,4])\n    rfm&#91;'M_rank'] = pd.qcut(rfm&#91;'Monetary'], q=4, labels=&#91;1,2,3,4])\n    \n    return rfm<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">R Example<\/h2>\n\n\n\n<pre class=\"wp-block-code has-black-color has-light-green-cyan-background-color has-text-color has-background has-link-color wp-elements-1c4f3a14dd70d04f0e81f4d01ac51db2\"><code>library(dplyr)\n\nrfm_analysis &lt;- function(data) {\n  rfm_result &lt;- data %>%\n    group_by(customer_id) %>%\n    summarise(\n      Recency = as.numeric(max(max_date) - max(order_date)),\n      Frequency = n_distinct(order_id),\n      Monetary = sum(total_amount)\n    ) %>%\n    mutate(\n      R_rank = ntile(Recency, 4),\n      F_rank = ntile(Frequency, 4),\n      M_rank = ntile(Monetary, 4)\n    )\n  \n  return(rfm_result)\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Customer Segments Created<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Champions: High scores across R, F, M<\/li>\n\n\n\n<li>At Risk: High historical value but haven&#8217;t purchased recently<\/li>\n\n\n\n<li>Hibernating: Low scores in all dimensions<\/li>\n\n\n\n<li>New Customers: High recency, low frequency\/monetary<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Specifically referenced from:\n<ul class=\"wp-block-list\">\n<li>Blattberg, R. C., &amp; Deighton, J. (1996). Customer Equity Framework<\/li>\n\n\n\n<li>Kumar, V., &amp; Reinartz, W. (2016). Customer Engagement Marketing<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is RFM Analysis? RFM (Recency, Frequency, Monetary) Analysis is a customer segmentation technique that uses three key metrics: Statistical Approach to Binning in RFM Binning is critical in RFM to categorize customers: Python Example: R Example Customer Segments Created References<\/p>\n","protected":false},"author":1,"featured_media":2804,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2803","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=2803"}],"version-history":[{"count":1,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2803\/revisions"}],"predecessor-version":[{"id":2806,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2803\/revisions\/2806"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/2804"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=2803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=2803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=2803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}