R - F - M Segmentation

Market segmentation entails breaking down your target market into distinct, approachable groups. This process involves creating market subsets based on factors such as demographics, needs, priorities, common interests, and other psychographic or behavioral criteria to gain a deeper understanding of the target audience.

RFM analysis is a technique that segments customer behavior using data. RFM stands for recency, frequency, and monetary value.

Untitled

Sources

Code Sources:

https://github.com/HoangNguyen5897/rfm_project

Business requirements

To better understand their customers and craft targeted campaigns, businesses need to divide their customers into different segments. Effective customer segmentation will be based on three key factors: R (recency) - the time since the last purchase, F (frequency) - the number of purchases, and M (monetary) - the total spending.

By combining Recency, Frequency, and Monetary (RFM) values, I will classify all customers into 11 unique groups, each with distinct characteristics. The details are outlined in the table below.

rfm.jpg

Process

1. Creating Table & Import Data

I start by creating tables and import data into PostgreSQL

create table sales_dataset_rfm_prj
(
  ordernumber varchar,
  quantityordered varchar,
  priceeach        varchar,
  orderlinenumber  varchar,
  sales            varchar,
  orderdate        varchar,
  status           varchar,
  productline      varchar,
  msrp             varchar,
  productcode      varchar,
  customername     varchar,
  phone            varchar,
  addressline1     varchar,
  addressline2     varchar,
  city             varchar,
  state            varchar,
  postalcode       varchar,
  country          varchar,
  territory        varchar,
  contactfullname  varchar,
  dealsize         varchar
) 

Once the data is entered, I start adjusting the data types of the table's columns to enhance analytical capabilities.

In PostgreSQL, converting a VARCHAR data type directly to a numeric type isn't feasible. Therefore, I employ the 'ALTER TABLE... ALTER COLUMN... TYPE... USING' syntax to perform an explicit data type cast.