Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/clv_template_controlflow_predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ clv.controlflow.predict.add.uncertainty.estimates <- function(clv.fitted, dt.pre
dt.boots[, Id := sub("_BOOTSTRAP_ID_[0-9]+$", "", Id)]

# quantiles for each predicted quantity: select only the existing ones
cols.predictions <- c("PAlive", "CET", "DERT", "DECT", "predicted.mean.spending", "predicted.period.spending", "predicted.CLV")
cols.predictions <- c("PAlive", "CET", "DERT", "DECT",
"predicted.mean.spending", "predicted.period.spending",
"predicted.CLV", "predicted.period.CLV")
cols.predictions <- cols.predictions[cols.predictions %in% colnames(dt.boots)]

# Long-format for easier handling of different prediction columns
Expand Down
6 changes: 4 additions & 2 deletions R/f_generics_clvfittedtransactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ setMethod("clv.controlflow.predict.add.actuals", signature(clv.fitted="clv.fitte
# .clv.controlflow.predict.post.process.prediction.table ------------------------------------------------------------------------------
setMethod("clv.controlflow.predict.post.process.prediction.table", signature = signature(clv.fitted="clv.fitted.transactions"), function(clv.fitted, dt.predictions, has.actuals, verbose, predict.spending, ...){
predicted.mean.spending <- i.predicted.mean.spending <- actual.period.spending <- i.actual.period.spending <- predicted.period.spending <- NULL
predicted.CLV <- CET <- DECT <- DERT <- NULL
predicted.CLV <- predicted.period.CLV <- CET <- DECT <- DERT <- NULL

# Predict spending ---------------------------------------------------------------------------------------
# depends on content of predict.spending:
Expand Down Expand Up @@ -289,7 +289,7 @@ setMethod("clv.controlflow.predict.post.process.prediction.table", signature = s
if("DERT" %in% colnames(dt.predictions))
dt.predictions[, predicted.CLV := DERT * predicted.mean.spending]
if("DECT" %in% colnames(dt.predictions))
dt.predictions[, predicted.CLV := DECT * predicted.mean.spending]
dt.predictions[, predicted.period.CLV := DECT * predicted.mean.spending]

# If spending is predicted, also add predicted.period.spending
dt.predictions[, predicted.period.spending := predicted.mean.spending * CET]
Expand All @@ -316,6 +316,8 @@ setMethod("clv.controlflow.predict.post.process.prediction.table", signature = s

if("predicted.CLV" %in% colnames(dt.predictions))
cols <- c(cols, "predicted.CLV")
if("predicted.period.CLV" %in% colnames(dt.predictions))
cols <- c(cols, "predicted.period.CLV")

setcolorder(dt.predictions, cols)

Expand Down
3 changes: 2 additions & 1 deletion R/f_interface_predict_clvfittedtransactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
#' \item{actual.period.spending}{Actual total spending until prediction.end. Only if there is a holdout period and the prediction ends in it, otherwise not reported.}
#' \item{predicted.mean.spending}{The mean spending per transactions as predicted by the spending model.}
#' \item{predicted.period.spending}{The predicted total spending until prediction.end (\code{CET*predicted.mean.spending}).}
#' \item{predicted.CLV}{Customer Lifetime Value based on \code{DERT/DECT} and \code{predicted.mean.spending}.}
#' \item{predicted.CLV}{Customer Lifetime Value based on \code{DERT*predicted.mean.spending}.}
#' \item{predicted.period.CLV}{Customer Lifetime Value until prediction.end based on \code{DECT*predicted.mean.spending}.}
#'
#' If predicting for new customers (using \code{newcustomer()}), a numeric scalar indicating the expected
#' number of transactions is returned instead.
Expand Down
3 changes: 2 additions & 1 deletion man/predict.clv.fitted.transactions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion tests/testthat/helper_testthat_consistency.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ fct.testthat.consistency.cov.params.0.predict.same <- function(fitted.nocov, fit
fct.compare.prediction.result <- function(dt.pred.nocov, dt.pred.cov){
if(is.dyncov == TRUE){
# DERT unequal to DECT because only predict short period!
expect_silent(data.table::setnames(dt.pred.cov, old="DECT",new = "DERT"))
expect_silent(data.table::setnames(
dt.pred.cov,
old=c("DECT", "predicted.period.CLV"),
new = c("DERT", "predicted.CLV")))
expect_true(isTRUE(all.equal(dt.pred.nocov[, !c("DERT", "predicted.CLV")],
dt.pred.cov[, !c("DERT", "predicted.CLV")])))
}else{
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper_testthat_inputchecks_nocov.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fct.testthat.inputchecks.cannot.predict.without.spending <- function(method, is.
regexp = "there is no spending data")
# but works without spending
expect_silent(dt.pred <- predict(clv.spending, newdata=clv.cdnow.nospending, predict.spending=FALSE, verbose=FALSE))
expect_false(any(c("predicted.mean.spending","predicted.CLV") %in% colnames(dt.pred)))
expect_false(any(c("predicted.mean.spending","predicted.CLV", "predicted.period.CLV") %in% colnames(dt.pred)))
}
})
}
Expand Down
Loading