MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
RFM (Recency, Frequency, Monetary) Customer Segmentation0%
Study MaterialsCheatsheet
Advanced Analytics & Machine LearningProgress 0%
1.1Downcasting Dtypes & Category Encoding for 10x Memory Savings1.2Method Chaining (pipe, assign) for Clean Production Pipelines1.3Window Functions & Moving Averages in Pandas1.4Modern Pandas 2.x/3.0: PyArrow Backend & Copy-on-Write
5.1K-Means Clustering & The Elbow Method5.2RFM (Recency, Frequency, Monetary) Customer Segmentation
HomeTutorialsAdvanced Analytics & Machine LearningRFM (Recency, Frequency, Monetary) Customer Segmentation
Business Problem Definition & KPI Scoping

RFM (Recency, Frequency, Monetary) Customer Segmentation

Advanced8 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

RFM (Recency, Frequency, Monetary) Analysis is an empirically proven behavioral segmentation framework used by premier e-commerce, banking, and retail enterprises. By transforming transactional purchase histories into three quantitative pillars, businesses can identify top VIP spenders, churn-risk accounts, and reactivation targets for precision marketing campaigns.


1. The Three Pillars of RFM

DimensionDefinitionCalculationStrategic Business Meaning
Recency ($R$)Days since customer's last purchase$\text{Reference Date} - \text{Last Purchase Date}$Customers who bought recently are vastly more responsive to promotions.
Frequency ($F$)Total number of completed orders$\text{COUNT(DISTINCT Order ID)}$Measures customer loyalty, habituation, and brand affinity.
Monetary ($M$)Cumulative gross revenue spend$\text{SUM(Order Value)}$Identifies top revenue drivers and high-margin accounts.

2. Computing RFM Metrics in Pandas

1import pandas as pd
2import datetime as dt
3 
4# Set snapshot reference date (typically 1 day after latest transaction)
5snapshot_date = df['order_date'].max() + dt.timedelta(days=1)
6 
7# Group transactions by customer
8rfm = df.groupby('customer_id').agg({
9 'order_date': lambda x: (snapshot_date - x.max()).days,
10 'order_id': 'nunique',
11 'total_amount': 'sum'
12}).rename(columns={
13 'order_date': 'Recency',
14 'order_id': 'Frequency',
15 'total_amount': 'Monetary'
16})

3. Binning Scores with Quantiles (pd.qcut)

Segment customers by assigning quintile scores from 1 to 5:

  • Recency: Lower days = Higher score (Score 5 is most recent!).
  • Frequency & Monetary: Higher volume/spend = Higher score (Score 5 is highest!).
1# Recency: reversed labels (lowest recency days = best score 5)
2r_labels = [5, 4, 3, 2, 1]
3f_labels = [1, 2, 3, 4, 5]
4m_labels = [1, 2, 3, 4, 5]
5 
6rfm['R_Score'] = pd.qcut(rfm['Recency'], q=5, labels=r_labels).astype(int)
7rfm['F_Score'] = pd.qcut(rfm['Frequency'].rank(method='first'), q=5, labels=f_labels).astype(int)
8rfm['M_Score'] = pd.qcut(rfm['Monetary'], q=5, labels=m_labels).astype(int)
9 
10# Create combined RFM Segment string
11rfm['RFM_Segment'] = rfm['R_Score'].astype(str) + rfm['F_Score'].astype(str) + rfm['M_Score'].astype(str)

4. Mapping Executive Customer Personas

1def map_rfm_persona(df):
2 r, f = df['R_Score'], df['F_Score']
3 if r >= 4 and f >= 4:
4 return "Champions (VIPs)"
5 elif r >= 3 and f >= 3:
6 return "Loyal Customers"
7 elif r >= 4 and f <= 2:
8 return "Recent New Customers"
9 elif r <= 2 and f >= 4:
10 return "At Risk / Can't Lose Them"
11 elif r <= 2 and f <= 2:
12 return "Lost / Dormant"
13 else:
14 return "Potential Loyalists"
15 
16rfm['Customer_Segment'] = rfm.apply(map_rfm_persona, axis=1)

Marketing Action Plan:

  • Champions (555, 554): VIP early access, no discount erosion, invite to loyalty club.
  • At Risk (145, 155): High spenders who stopped buying! Send personalized re-activation calls or big discount vouchers.
  • Lost (111, 112): Low lifetime value, inactive; minimize ad spend.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why are the quintile score labels for Recency assigned in reverse order ($5, 4, 3, 2, 1$) compared to Frequency and Monetary?
Question 2
A customer has an RFM score of 155 (Recency: 1, Frequency: 5, Monetary: 5). What customer segment do they represent?
Question 3
Which Pandas method is best suited for segmenting continuous monetary spend into 5 quantile-based bins with roughly equal sample counts per bin?
Question 4
What is the main strategic marketing advantage of combining RFM Segmentation with K-Means clustering?
Question 5
In RFM data preparation, why is the snapshot reference date commonly chosen as max_order_date + 1 day rather than today's actual system date when analyzing historical datasets?

Next Lesson

Business Problem Definition & KPI Scoping

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
K-Means Clustering & The Elbow MethodBusiness Problem Definition & KPI Scoping

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

12-Month Data Analysis Mastery Program

Master Full-Stack Data Analytics (Excel, SQL, Python, Power BI & Tableau)

Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext