Skip to contents

Getting Client Data

The hardest part about any Appraise project is this first step. Getting the data we require into the right format can be very challenging, and will differ client to client. In fact, we’ve developed a set of guidelines* that we send to our client to get ahead of this challenge, and hope they can provide the data in a format that we can quickly work with.

Appraise requires at a minimum three sets of data inputs:

  1. Transactional history of each customer
  2. Customer metadata
  3. Strategic information

*Note; don’t edit the template directly!

Transactional History

The transactional history should have the following properties:

  • The number of rows per customer should correspond to the total number of transactions made by the customer
  • The customer ID should map to the ID in the customer metadata file
  • Should (if possible) include the number of returns, and the value of the returned items. This can also be a separate data frame if it has the transaction ID attached

See the example below for a good dataset, which comes with the g6tr.appraise package;

head(elog, 10)
               cust       date items     sales
1  0770000000007791 2019-06-10     4 125.00000
2  0010000000517647 2020-08-06     3 112.33000
3  0010000000517647 2021-01-04     4 103.54746
4  0332000000630213 2020-10-07     2  77.00165
5  0332000000630213 2021-01-15     1  59.00140
6  0010000000075961 2019-01-21     2 201.87000
7  0010000000075961 2019-06-21     3 130.00000
8  0010000000075961 2019-07-04     4  92.01000
9  0010000000075961 2019-12-17     1  30.00000
10 0010000000075961 2020-02-25     2  76.80000

And a separate example of the items-returns table;

head(returns, 10)
               cust items returns
1  0770000000007791     4      NA
2  0010000000517647     7      NA
3  0332000000630213     3      NA
4  0010000000075961    16      NA
5  1020718000000648     1      NA
6  0010000000500785     6      NA
7  1080817000447980     1      NA
8  0010000000318635     4      NA
9  0010000000075159     6      NA
10 0010000000156065     3      NA

Customer Metadata

The customer metadata should have the following properties: * Only one row per customer * The customer ID should map to the ID in the transactional history file

See the example below for a good dataset, which comes with the g6tr.appraise package;

head(cust_acquisition, 10)

[38;5;246m# A tibble: 10 × 5
[39m
   cust  first_order_date second_order_date third_order_date first_order_channel
   
[3m
[38;5;246m<chr>
[39m
[23m 
[3m
[38;5;246m<IDate>
[39m
[23m          
[3m
[38;5;246m<IDate>
[39m
[23m           
[3m
[38;5;246m<IDate>
[39m
[23m          
[3m
[38;5;246m<chr>
[39m
[23m              

[38;5;250m 1
[39m 0010… 2018-03-10       
[31mNA
[39m                
[31mNA
[39m               US RETAIL          

[38;5;250m 2
[39m 0010… 2018-03-03       2018-03-08        2018-04-11       US RETAIL          

[38;5;250m 3
[39m 0010… 2018-03-22       
[31mNA
[39m                
[31mNA
[39m               US RETAIL          

[38;5;250m 4
[39m 0010… 2018-03-22       2018-03-24        2018-04-02       US RETAIL          

[38;5;250m 5
[39m 0010… 2018-03-12       2018-08-02        2018-09-05       US RETAIL          

[38;5;250m 6
[39m 0010… 2018-03-12       2018-03-27        2018-06-07       US RETAIL          

[38;5;250m 7
[39m 0010… 2018-03-14       2018-03-28        2018-04-07       US RETAIL          

[38;5;250m 8
[39m 0010… 2018-05-22       2018-06-05        
[31mNA
[39m               US RETAIL          

[38;5;250m 9
[39m 0010… 2018-05-18       
[31mNA
[39m                
[31mNA
[39m               US RETAIL          

[38;5;250m10
[39m 0010… 2018-09-12       2018-09-17        2018-09-20       US RETAIL          

Strategic Information

In order to make your Appraise project a success, you’ll need some strategic information to guide our models and outputs. In the sections below, we’ll go through each of the arguments in the appraise_configure() function so you have a better understanding of the parameters.

config <- appraise_configure(sample = TRUE,
                             sample_size = 5000,
                             unified_horizon = 5,
                             pred_periods = c(0.5, 1.5, 2.5, 3.5, 4.5),
                             cpa = c(25, 50, 75, 100, 125, 150, 200),      
                             cm =  c(.2, .3, .432, .5),
                             currency = '$',
                             n_forecast =  5*52)

config
$SAMPLE
[1] TRUE

$SAMPLE_SIZE
[1] 5000

$HOLDOUT_DATE
[1] NA

$UNIFIED_HORIZON
[1] 5

$CPA
[1]  25  50  75 100 125 150 200

$CM
[1] 0.200 0.300 0.432 0.500

$MIN_CPA
[1] 25 25 25 25 25 25 25

$MAX_CPA
[1] 200 200 200 200 200 200 200

$CURRENCY
[1] "$"

$PRED_PERIODS
[1] 0.5 1.5 2.5 3.5 4.5

$N_PRED_PERIODS
[1] 5

$N_FORECAST
[1] 260

$USE_PRIORS
[1] 0

$AWS_BUCKET
[1] NA

$GOOGLE_DRIVE_ID
[1] NA

Unified Horizon

Our model is going to estimate Customer Lifetime Value (CLV) for each of the customers in the clients’ database. If we just went ahead and did that without accounting for the time a customer has been a customer, we are going to:

  1. Overvalue customers that have been a customer for longer (if high sales)
  2. Undervalue customers that have only just been acquired because we have limited data

In order to put every customer on the same playing field, we can set a unified horizon, which is simply the number of years we want to take into account when creating the CLV estimates.

Consider the data for the following two customers:

[1] "1010117000229368"
[1] "0332000001531285"
elog %>%
  filter(cust == "1020117000320431" |  cust == "0332000001531285")
              cust       date items    sales
1 1020117000320431 2017-01-02     1 30.00000
2 0332000001531285 2021-06-03     1 32.86411

They have both bought one item worth ~$30. However, the first customer has been a customer for 5 years, while the more recent customer has only been a customer for a month (the max date of the data is 2021-07).

If we put both customers on a unified_horizon of 5 years, it means that for the first customer, we’ll regard the one transaction as the total. For the second customer, we’ll add 4 years’ worth of data of the “average” customer, considering that we have no other information about the customer.

To recap;

The unified horizon puts all customers on the same year scale. If a customer was acquired in the fourth year, and the unified_horizon is set to 5 years, it will add 4 estimated years. If a customer was acquired in the first year, it will use all of his actual sales.

Prediction Periods

Periods to predict in the forecasting model in unit of years. If your prediction periods are in months, divide by 12. If they are in weeks, divide by 52. If they are in specific periods, calculate it by taking the time difference in years.

This will typically be provided by the client, and will often be in months. An example entry could be something like:

prediction_periods <- prediction_periods %>% 
  mutate(pred_period = lubridate::time_length(difftime(dmy(period_end), dmy(period_start)), unit = "year"),
         pred_period = cumsum(pred_period))

prediction_periods %>% head()

[38;5;246m# A tibble: 6 × 5
[39m
   year month    period_start period_end pred_period
  
[3m
[38;5;246m<int>
[39m
[23m 
[3m
[38;5;246m<chr>
[39m
[23m    
[3m
[38;5;246m<chr>
[39m
[23m        
[3m
[38;5;246m<chr>
[39m
[23m            
[3m
[38;5;246m<dbl>
[39m
[23m

[38;5;250m1
[39m  
[4m2
[24m022 January  1-1-2022     31-1-2022       0.082
[4m1
[24m

[38;5;250m2
[39m  
[4m2
[24m022 February 1-2-2022     28-2-2022       0.156 

[38;5;250m3
[39m  
[4m2
[24m022 March    1-3-2022     31-3-2022       0.238 

[38;5;250m4
[39m  
[4m2
[24m022 April    1-4-2022     30-4-2022       0.318 

[38;5;250m5
[39m  
[4m2
[24m022 May      1-5-2022     31-5-2022       0.400 

[38;5;250m6
[39m  
[4m2
[24m022 June     1-6-2022     30-6-2022       0.479 

You would then simply assign the prediction periods as pred_periods = prediction_periods$pred_period.

N Forecasts

The number of prediction periods. Most of the time, this is simply n_forecast = length(pred_periods)

Contribution Margin (CM)

In order to estimate how profitable a client’s customers are we need to understand their current CM. The CM is the selling price per unit, minus the variable cost per unit on average. We typically take that value as a percentage of the whole, which means that the higher the CM, the better (e.g., a CM of 60% means that 60% of your selling price is profit).

Cost Per Acquisition (CPA)

In addition to the CM, we’ll need to understand their average CPA and, if possible, channel-specific CPA’s. This way, we’ll be able to better estimate which channels are profitable as lead generators, and which ones are not.

Validating data inputs

Considering that we can’t control how we obtain the data, and we’re thus unable to create functions to help with data processing, we decided to build functions that can validate if your data processing pipeline was correct. This is done by a set of validate_ functions.

Validating the ELOG & Items and Returns

The ELOG needs to meet a few assumptions, which is why we’ve created a validation function to make sure that your data is correct.

  1. Sum of a customers’ sales must be above 0
  2. Sum of a customers’ items must be above 0
  3. Number of items returned must be lower than the number of items bought
elog_validated <- validate_elog(elog)
Checking sales data...
-------------------------

[31mFollowing `elog` issues were found:

[39mnonpos_items nonpos_sales 
           1          188 
items_and_return_validated <- validate_items_returns(returns)

Checking returns data...
-------------------------

[31mFollowing `items_and_returns` issues were found:

[39mmore_returns 
           5