-
Notifications
You must be signed in to change notification settings - Fork 28
/
README.Rmd
112 lines (79 loc) · 3.53 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "tools/README-"
)
options(tibble.print_min = 5, tibble.print_max = 5)
```
# rfm
<!-- badges: start -->
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/rfm)](https://cran.r-project.org/package=rfm) [![R build status](https://github.com/rsquaredacademy/rfm/workflows/R-CMD-check/badge.svg)](https://github.com/rsquaredacademy/rfm/actions) [![Coverage Status](https://img.shields.io/codecov/c/github/rsquaredacademy/rfm/master.svg)](https://app.codecov.io/github/rsquaredacademy/rfm?branch=master)
<!-- badges: end -->
## Overview
Tools for customer segmentation using RFM (recency, frequency and monetary) analysis.
## Installation
```{r gh-installation, eval = FALSE}
# Install rfm from CRAN
install.packages("rfm")
# Or the development version from GitHub
# install.packages("pak")
pak::pak("rsquaredacademy/rfm")
```
```{r, echo=FALSE, message=FALSE}
library(rfm)
```
## Usage
**RFM** (recency, frequency, monetary) analysis is a behavior based technique used to segment customers by examining their transaction history such as:
- how recently a customer has purchased (recency)
- how often they purchase (frequency)
- how much the customer spends (monetary)
It is based on the marketing axiom that **80% of your business comes from 20% of your customers**. RFM analysis helps to identify customers who are more likely to respond to promotions by segmenting them into various categories.
To calculate the RFM score we need the following info for each customer:
- a unique customer id
- date of transaction/order
- transaction/order amount
```{r rfm_table_order}
# analysis date
analysis_date <- as.Date('2006-12-31')
# generate rfm score
rfm_result <- rfm_table_order(rfm_data_orders, customer_id, order_date,
revenue, analysis_date)
# rfm score
rfm_result
# segment names
segment_names <- c("Champions", "Potential Loyalist", "Loyal Customers",
"Promising", "New Customers", "Can't Lose Them",
"At Risk", "Need Attention", "About To Sleep", "Lost")
# segment intervals
recency_lower <- c(5, 3, 2, 3, 4, 1, 1, 1, 2, 1)
recency_upper <- c(5, 5, 4, 4, 5, 2, 2, 3, 3, 1)
frequency_lower <- c(5, 3, 2, 1, 1, 3, 2, 3, 1, 1)
frequency_upper <- c(5, 5, 4, 3, 3, 4, 5, 5, 3, 5)
monetary_lower <- c(5, 2, 2, 3, 1, 4, 4, 3, 1, 1)
monetary_upper <- c(5, 5, 4, 5, 5, 5, 5, 5, 4, 5)
# generate segments
segments <- rfm_segment(rfm_result, segment_names, recency_lower,
recency_upper, frequency_lower, frequency_upper, monetary_lower,
monetary_upper)
segments
```
### Plotting Engines
`rfm` supports the following plotting engines:
- [ggplot2](https://ggplot2.tidyverse.org)
- [plotly](https://plotly.com/r/)
- [gganimate](https://gganimate.com)
### Shiny App
`rfm` includes a shiny app for interactive RFM analysis. In the latest release, we have added project management features to allow users to save/clone their projects.
## Resources
- [Online Course](https://rsquared-academy.thinkific.com/courses/customer-segmentation-using-rfm-analysis)
- [YouTube Tutorial](https://www.youtube.com/watch?v=275X7yaSsoQ)
- [Blog](https://blog.rsquaredacademy.com/customer-segmentation-using-rfm-analysis/)
## Getting Help
If you encounter a bug, please file a minimal reproducible example using
[reprex](https://reprex.tidyverse.org/index.html) on github. For questions and
clarifications, use [StackOverflow](https://stackoverflow.com/).