Recency, Frequency, Monetary (RFM) analysis - Last Quarter


Recency, Frequency, Monetary (RFM) is a simple model to segment existing customers based on a few data points within your transaction data.

Recency - When was the customer’s last purchase?

Frequency - How often does the customer make purchases?

Monetary - How much has the customer purchased within a time period?

Each term is scored into five segments. The terms are grouped and then ordered with 555 being the highly valued customers and 111 being the least.

RFM has two key advantages in a corporate environment.

  1. Easy to communicate to a broad audience. Marketing, operations, executive decision makers can understand the principles behind the model.
  2. Performs well with transaction data. If your core customers are trend obsessed, it can track fast moving segment shifts.

Recency, Frequency, Monetary (RFM) analysis - This Quarter


The heat maps show the quarter to quarter difference. Last quarter was the Christmas holiday season and it reflects the increased monetary intensity within the top right hand quadrant for the highly valued customers.

Market Basket Analysis using Association Rules


Market Basket Analysis attempts to learn about the product relationships in the customer’s transactions. If a customer purchased item A, what can I learn about item B?

Association Rules are written such as

A ==> B

Association rules have three important metrics: Support, Confidence, Lift

Support is the probability both items are in a basket. It answers the question “What percent of all the customer baskets contain A and B”?

Confidence is the conditional probability that B is in the basket given that A is present. It expresses validity for the rule. Expected confidence is the probability that B is in a basket.

Lift is the confidence divided by expected confidence. It is the ratio of the likelihood of B being in a basket with A to the likelihood of B being in any basket. When lift is greater than 1, A is believed to lift the presence of B above what we would normally expect to see.

This network graph shows the product item sets for the top 10 association rules with the highest lift. This visualization’s strength is to show the product relationships. Product 5620 has five related products. 5621 ==> 5620 has support of .49 which means this item set can be found in 49% of all customer transactions.

Recommendation engine evaluation


Five recommendation algorithms are evaluated to determine which ones work best with our item set data. These include:

The algorithms are evaluated by looking at the top N items for 1,3,5,10,15,20 product recommendation. The evaluation routine computes the confusion matrix for each algorithm.

This graph shows the results from the recommendation algorithms evaluation. It plots the True Positive Rate (TPR) and False Positive Rates (FPR) for each of the algorithms. For the first five recommended items, three algorithms appear to be equal, Popular, Association Rules (AR), and User-Based Collaborative Filter (UBCF). As you starting increasing the number of items in the recommendation suggestions, separation starts to occur after 10 items. The Item-Based Collaborative Filter (IBCF) algorithm stopped after ten items.

---
title: "Customer Affinity Analytic Pathway"
output: 
  flexdashboard::flex_dashboard:
    storyboard: true
    social: menu
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(highcharter)
library(arulesViz)
library(recommenderlab)
```

### Recency, Frequency, Monetary (RFM) analysis - Last Quarter


```{r}

load("C:\\\\Users\\Campanell\\Documents\\R\\rfm_lastqtr_visdf.Rda")
load("C:\\\\Users\\Campanell\\Documents\\R\\rfm_thisqtr_visdf.Rda")

#-----------------   Last QTR   --------------------------------------#
data_lastqtr <- list.parse2(select(rfm_lastqtr_visdf,frequency_rank,recency_rank,avgrev))


hc_lastqtr <- highchart() %>% 
              hc_chart(type = "heatmap") %>% 
              hc_title(text = "RFM Last QTR") %>% 
              hc_xAxis(categories = c(0,1,2,3,4), title = list(text = "Frequency")) %>% 
              hc_yAxis(categories = c(0,1,2,3,4), title = list(text = "Recency")) %>% 
              hc_add_series(name = "monetary", data = data_lastqtr) %>%
              hc_tooltip(pointFormat = "${point.value:.0f}")

hc_colorAxis(hc_lastqtr, minColor = "#f2f0f7", maxColor = "#54278f")

```

***

Recency, Frequency, Monetary (RFM) is a simple model to segment existing customers based on a few data points within your transaction data.

**Recency** - When was the customer's last purchase?

**Frequency** - How often does the customer make purchases?

**Monetary** - How much has the customer purchased within a time period?

Each term is scored into five segments.   The terms are grouped and then ordered with 555 being the highly valued customers and 111 being the least.

RFM has two key advantages in a corporate environment.

1. Easy to communicate to a broad audience.  Marketing, operations, executive decision makers can understand the principles behind the model.
2. Performs well with transaction data.   If your core customers are trend obsessed, it can track fast moving segment shifts.

### Recency, Frequency, Monetary (RFM) analysis - This Quarter

```{r}
#-----------------   This QTR   ------------------------------------#
data_thisqtr <- list.parse2(select(rfm_thisqtr_visdf,frequency_rank,recency_rank,avgrev))


hc_thisqtr <- highchart() %>% 
              hc_chart(type = "heatmap") %>% 
              hc_title(text = "RFM This QTR") %>% 
              hc_xAxis(categories = c(0,1,2,3,4), title = list(text = "Frequency")) %>% 
              hc_yAxis(categories = c(0,1,2,3,4), title = list(text = "Recency")) %>% 
              hc_add_series(name = "monetary", data = data_thisqtr) %>%
              hc_tooltip(pointFormat = "${point.value:.0f}")
              
hc_colorAxis(hc_thisqtr, minColor = "#f2f0f7", maxColor = "#54278f")


```

***

The heat maps show the quarter to quarter difference.   Last quarter was the Christmas holiday season and it reflects the increased monetary intensity within the top right hand quadrant for the highly valued customers. 

### Market Basket Analysis using Association Rules

```{r}

load("C:\\\\Users\\Campanell\\Documents\\R\\top10lift.Rda")

plot(top10lift, method="graph", main="Top 10 Item Sets by Lift")

```

***

Market Basket Analysis attempts to learn about the product relationships in the customer's transactions.  If a customer purchased item A, what can I learn about item B?

Association Rules are written such as

**A ==> B**

Association rules have three important metrics: **Support, Confidence, Lift** 

**Support** is the probability both items are in a basket.   It answers the question "What percent of all the customer baskets contain A and B"?

**Confidence** is the conditional probability that B is in the basket given that A is present. It expresses validity for the rule.  Expected confidence is the probability that B is in a basket.


**Lift** is the confidence divided by expected confidence.   It is the ratio of the likelihood of B being in a basket with A to the likelihood of B being in any basket.     When lift is greater than 1, A is believed to *lift* the presence of B above what we would normally expect to see.

This network graph shows the product item sets for the top 10 association rules with the highest lift. This visualization's strength is to show the product relationships.  Product 5620 has five related products.   5621 ==> 5620 has support of .49 which means this item set can be found in 49% of all customer transactions. 

### Recommendation engine evaluation

```{r}

load("C:\\\\Users\\Campanell\\Documents\\R\\results_binary.Rda")

plot(results_binary, annotate=c(1,3), legend="topright")

```

***
Five recommendation algorithms are evaluated to determine which ones work best with our item set data.   These include:

- Random (used as the baseline)
- Association Rules
- Popular
- Item Based Collaborative Filter
- User Based Collaborative Filter

The algorithms are evaluated by looking at the top N items for 1,3,5,10,15,20 product recommendation.   The evaluation routine computes the confusion matrix for each algorithm.

This graph shows the results from the recommendation algorithms evaluation.   It plots the True Positive Rate (TPR) and False Positive Rates (FPR) for each of the algorithms.   For the first five recommended items, three algorithms appear to be equal, Popular, Association Rules (AR), and User-Based Collaborative Filter (UBCF).   As you starting increasing the number of items in the recommendation suggestions, separation starts to occur after 10 items.   The Item-Based Collaborative Filter (IBCF) algorithm stopped after ten items.