RFM Scores

earmijoearmijo Member Posts: 263   Unicorn
edited November 2018 in Help
I teach Data Mining at a Business School and sometimes we use the RFM Model (http://www.b-eye-network.com/view/10256) as a benchmark against which we compare the performance of our statistical models. The RFM model needs to compute the percentiles of recency, frequency and monetary. There is no operator in RapidMiner to compute them (Feature Request!). However, I learned a trick from Marius (can't find the reference). You can use Discretize by Frequency to achieve the same goal.

Here's a process to compute the RFM-score starting from the basic variables (recency, frequency, monetary). The variables are defined as follows:

recency: periods since last purchase
frequency: number of purchases in recent past or lifetime
monetary: amount purchased by customer in recent past or lifetime


I hope somebody finds it useful.

BTW, if anybody can do it in a simpler way, please share it with us.

DATASET:

https://s3.amazonaws.com/mirlitus/test-rfm.csv

CODE:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.005">
 <context>
   <input/>
   <output/>
   <macros/>
 </context>
 <operator activated="true" class="process" compatibility="5.3.005" expanded="true" name="Process">
   <process expanded="true">
     <operator activated="true" class="read_csv" compatibility="5.3.005" expanded="true" height="60" name="Read CSV" width="90" x="45" y="30">
       <parameter key="csv_file" value="/Users/Carlos/Desktop/test-rfm.csv"/>
       <parameter key="column_separators" value=","/>
       <parameter key="first_row_as_names" value="false"/>
       <list key="annotations">
         <parameter key="0" value="Name"/>
       </list>
       <parameter key="encoding" value="MacRoman"/>
       <list key="data_set_meta_data_information">
         <parameter key="0" value="id.true.integer.id"/>
         <parameter key="1" value="Recency.true.integer.attribute"/>
         <parameter key="2" value="Frequency.true.integer.attribute"/>
         <parameter key="3" value="Monetary.true.integer.attribute"/>
         <parameter key="4" value="Purchase.true.integer.label"/>
       </list>
     </operator>
     <operator activated="true" class="discretize_by_frequency" compatibility="5.3.005" expanded="true" height="94" name="Discretize-R" width="90" x="45" y="210">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="Recency"/>
       <parameter key="number_of_bins" value="5"/>
       <parameter key="range_name_type" value="short"/>
     </operator>
     <operator activated="true" class="nominal_to_numerical" compatibility="5.3.005" expanded="true" height="94" name="Nominal to Numerical" width="90" x="45" y="345">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="Recency"/>
       <parameter key="coding_type" value="unique integers"/>
       <list key="comparison_groups"/>
     </operator>
     <operator activated="true" class="discretize_by_frequency" compatibility="5.3.005" expanded="true" height="94" name="Discretize-F" width="90" x="179" y="210">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="Frequency"/>
       <parameter key="number_of_bins" value="5"/>
       <parameter key="range_name_type" value="short"/>
     </operator>
     <operator activated="true" class="nominal_to_numerical" compatibility="5.3.005" expanded="true" height="94" name="Nominal to Numerical (2)" width="90" x="179" y="345">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="Frequency"/>
       <parameter key="coding_type" value="unique integers"/>
       <list key="comparison_groups"/>
     </operator>
     <operator activated="true" class="discretize_by_frequency" compatibility="5.3.005" expanded="true" height="94" name="Discretize-M" width="90" x="313" y="210">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="Monetary"/>
       <parameter key="number_of_bins" value="5"/>
       <parameter key="range_name_type" value="short"/>
     </operator>
     <operator activated="true" class="nominal_to_numerical" compatibility="5.3.005" expanded="true" height="94" name="Nominal to Numerical (3)" width="90" x="313" y="345">
       <parameter key="attribute_filter_type" value="single"/>
       <parameter key="attribute" value="Monetary"/>
       <parameter key="coding_type" value="unique integers"/>
       <list key="comparison_groups"/>
     </operator>
     <operator activated="true" class="generate_attributes" compatibility="5.3.005" expanded="true" height="76" name="GenerateRFM-Score" width="90" x="447" y="210">
       <list key="function_descriptions">
         <parameter key="rfm_score" value="100*(5-Recency)+10*(Frequency+1)+(Monetary+1)"/>
       </list>
     </operator>
     <connect from_op="Read CSV" from_port="output" to_op="Discretize-R" to_port="example set input"/>
     <connect from_op="Discretize-R" from_port="example set output" to_op="Nominal to Numerical" to_port="example set input"/>
     <connect from_op="Nominal to Numerical" from_port="example set output" to_op="Discretize-F" to_port="example set input"/>
     <connect from_op="Discretize-F" from_port="example set output" to_op="Nominal to Numerical (2)" to_port="example set input"/>
     <connect from_op="Nominal to Numerical (2)" from_port="example set output" to_op="Discretize-M" to_port="example set input"/>
     <connect from_op="Discretize-M" from_port="example set output" to_op="Nominal to Numerical (3)" to_port="example set input"/>
     <connect from_op="Nominal to Numerical (3)" from_port="example set output" to_op="GenerateRFM-Score" to_port="example set input"/>
     <connect from_op="GenerateRFM-Score" from_port="example set output" to_port="result 1"/>
     <portSpacing port="source_input 1" spacing="0"/>
     <portSpacing port="sink_result 1" spacing="0"/>
     <portSpacing port="sink_result 2" spacing="0"/>
   </process>
 </operator>
</process>

Answers

  • ojuarezojuarez Member Posts: 5 Contributor II
    Hello

    Thanks for your post, it was reallly helpful.

    You used this formula.

    rfm = 100*(5-Recency)+10*(Frequency+1)+(Monetary+1)

    Is that a standard formula or did adjust it to your needs?

    Thanks
Sign In or Register to comment.