rsquaredacademy / rfm

Tools for Customer Segmentation using RFM Analysis
https://rfm.rsquaredacademy.com/
Other
59 stars 28 forks source link

User specified threshold for scores #58

Closed aravindhebbali closed 4 years ago

aravindhebbali commented 5 years ago

Users should be able to specify the lower & upper threshold based on which the recency, frequency & monetary scores are generated. Similar to the lower & upper boundaries in rfm_segment(). The modified API will be as shown below:

rfm_table_order(data = NULL, customer_id = NULL, order_date = NULL, revenue = NULL, analysis_date = NULL, recency_bins = 5, frequency_bins = 5, monetary_bins = 5, recency_lower = NULL, recency_upper = NULL, frequency_lower = NULL, frequency_upper = NULL, monetary_lower = NULL, monetary_upper = NULL)

gfagherazzi commented 5 years ago

Great!

gfagherazzi commented 4 years ago

Hi aravindhebbali, any chance to have this enhancement? It would be really usefull for me Thank you for your work! G.

aravindhebbali commented 4 years ago

@gfagherazzi I will work on it this week. Should be ready by the weekend.

aravindhebbali commented 4 years ago

Hi @gfagherazzi Sorry for the delay in looking into this but looks like the package was already able to handle it but just needed a few internal changes. Below we look at the same example using the number of bins as well as custom threshold

> analysis_date <- lubridate::as_date('2006-12-31', tz = 'UTC')
> 
> # default method
> rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date)
# A tibble: 995 x 9
   customer_id date_most_recent recency_days transaction_cou~ amount recency_score frequency_score monetary_score rfm_score
   <chr>       <date>                  <dbl>            <dbl>  <dbl>         <int>           <int>          <int>     <dbl>
 1 Abbey O'Re~ 2006-06-09                205                6    472             3               4              3       343
 2 Add Senger  2006-08-13                140                3    340             4               1              2       412
 3 Aden Lesch~ 2006-06-20                194                4    405             3               2              3       323
 4 Admiral Se~ 2006-08-21                132                5    448             4               3              3       433
 5 Agness O'K~ 2006-10-02                 90                9    843             5               5              5       555
 6 Aileen Bar~ 2006-10-08                 84                9    763             5               5              5       555
 7 Ailene Her~ 2006-03-25                281                8    699             3               5              5       355
 8 Aiyanna Br~ 2006-04-29                246                4    157             3               2              1       321
 9 Ala Schmid~ 2006-01-16                349                3    363             2               1              2       212
10 Alannah Bo~ 2005-04-21                619                4    196             1               2              1       121
# ... with 985 more rows
>
> # using custom threshold
> rfm_table_order(rfm_data_orders, customer_id, order_date, revenue, analysis_date,
+ recency_bins = c(115, 181, 297, 482), frequency_bins = c(4, 5, 6, 8),
+ monetary_bins = c(256, 382, 506, 666))
# A tibble: 995 x 9
   customer_id date_most_recent recency_days transaction_cou~ amount recency_score frequency_score monetary_score rfm_score
   <chr>       <date>                  <dbl>            <dbl>  <dbl>         <int>           <int>          <int>     <dbl>
 1 Abbey O'Re~ 2006-06-09                205                6    472             3               4              3       343
 2 Add Senger  2006-08-13                140                3    340             4               1              2       412
 3 Aden Lesch~ 2006-06-20                194                4    405             3               2              3       323
 4 Admiral Se~ 2006-08-21                132                5    448             4               3              3       433
 5 Agness O'K~ 2006-10-02                 90                9    843             5               5              5       555
 6 Aileen Bar~ 2006-10-08                 84                9    763             5               5              5       555
 7 Ailene Her~ 2006-03-25                281                8    699             3               5              5       355
 8 Aiyanna Br~ 2006-04-29                246                4    157             3               2              1       321
 9 Ala Schmid~ 2006-01-16                349                3    363             2               1              2       212
10 Alannah Bo~ 2005-04-21                619                4    196             1               2              1       121

I will write a detailed post on how to specify the custom threshold and add a link here. Again, sorry for the delay in fixing this.