R/f_interface_predict_clvfittedspending.R
predict.clv.fitted.spending.Rd
Infer customer's mean spending per transaction and compare it to the actual mean spending in the holdout period.
The fitted model can also be used to estimate the spending that a single, (fictional), average newly alive customer is expected to make at the moment of the first transaction. This is, for a customer which has no existing order history and that just "came alive".
The data on which the model was fit and which is stored in it is NOT used for this prediction. See examples and newcustomer.spending for more details.
# S3 method for class 'clv.fitted.spending'
predict(
object,
newdata = NULL,
uncertainty = c("none", "boots"),
level = 0.9,
num.boots = 100,
verbose = TRUE,
...
)
# S4 method for class 'clv.fitted.spending'
predict(
object,
newdata = NULL,
uncertainty = c("none", "boots"),
level = 0.9,
num.boots = 100,
verbose = TRUE,
...
)
A fitted spending model for which prediction is desired.
A clv.data
object or data for the new customer prediction (see newcustomer.spending).
If none or NULL is given, predictions are made for the data on which the model was fit.
Method to produce confidence intervals of the predictions (parameter uncertainty). Either "none" (default) or "boots".
Required confidence level, if uncertainty="boots"
.
Number of bootstrap repetitions, if uncertainty="boots"
. A low number may not produce intervals for all customers if they are not sampled.
Show details about the running of the function.
Ignored
An object of class data.table
with columns:
The respective customer identifier
Actual mean spending per transaction in the holdout period. Only if there is a holdout period otherwise it is not reported.
The mean spending per transaction as predicted by the fitted spending model.
If predicting for new customers (using newcustomer.spending()
), a numeric scalar
indicating the expected spending is returned instead.
If newdata
is provided, the individual customer statistics underlying the model are calculated
the same way as when the model was fit initially. Hence, if remove.first.transaction
was TRUE
,
this will be applied to newdata
as well.
To predict for new customers, the output of newcustomer.spending has to be given to newdata
. See examples.
Bootstrapping is used to provide confidence intervals of all predicted metrics.
These provide an estimate of parameter uncertainty.
To create bootstrapped data, customer ids are sampled with replacement until reaching original
length and all transactions of the sampled customers are used to create a new clv.data
object.
A new model is fit on the bootstrapped data with the exact same specification as used when
fitting object
(incl. start parameters and `optimx.args`) and it is then used to predict on this data.
It is highly recommended to fit the original model (object
) with a robust optimization
method, such as Nelder-Mead (optimx.args=list(method='Nelder-Mead')
).
This ensures that the model can also be fit on the bootstrapped data.
All prediction parameters, incl prediction.end
and continuous.discount.factor
, are forwarded
to the prediction on the bootstrapped data.
Per customer, the boundaries of the confidence intervals of each predicted metric are the
sample quantiles (quantile(x, probs=c((1-level)/2, 1-(1-level)/2)
).
See clv.bootstrapped.apply to create a custom bootstrapping procedure.
# \donttest{
data("apparelTrans")
# Fit gg model on data
apparel.holdout <- clvdata(apparelTrans, time.unit="w",
estimation.split = 52, date.format = "ymd")
apparel.gg <- gg(apparel.holdout)
#> Starting estimation...
#> Estimation finished!
# Estimate customers' mean spending per transaction
predict(apparel.gg)
#> Key: <Id>
#> Id actual.mean.spending predicted.mean.spending
#> <char> <num> <num>
#> 1: 1 104.82000 63.77959
#> 2: 10 31.65500 38.10316
#> 3: 100 37.03889 37.12434
#> 4: 101 0.00000 33.08404
#> 5: 102 0.00000 37.12434
#> ---
#> 596: 95 22.76000 28.29614
#> 597: 96 84.53667 37.12434
#> 598: 97 0.00000 37.12434
#> 599: 98 0.00000 34.87739
#> 600: 99 13.99000 16.11315
# Estimate the mean spending per transaction a single,
# fictional, average new customer is expected to make
# See ?newcustomer.spending() for more examples
predict(apparel.gg, newdata=newcustomer.spending())
#> [1] 37.12434
# }