Comments (4)
demo("pareto-ggg")
demo(pareto-ggg)
---- ~~~~~~~~~~
Type to start :
#' Load transaction records of 1525 grocery customers.
data("groceryElog", envir = environment())
head(groceryElog)
cust date
1 1 2006-01-01
2 2 2006-01-01
3 2 2006-12-19
4 3 2006-01-01
5 3 2006-01-10
6 3 2006-02-01
range(groceryElog$date)
[1] "2006-01-01" "2007-12-30"
#' Convert from event log to customer-by-sufficient-statistic summary.
#' Split into 52 weeks calibration, and 52 weeks holdout period.
cbs <- elog2cbs(groceryElog, T.cal = "2006-12-31", T.tot = "2007-12-30")
head(cbs)
cust x t.x litt first T.cal T.star x.star
1 1 0 0.00000 0.000000 2006-01-01 52.00000 52 0
2 2 1 50.28571 3.917721 2006-01-01 52.00000 52 0
3 3 19 48.57143 16.952179 2006-01-01 52.00000 52 14
4 4 0 0.00000 0.000000 2006-01-01 52.00000 52 0
5 5 2 40.42857 6.012667 2006-01-01 52.00000 52 3
6 6 5 47.57143 11.178735 2006-01-02 51.85714 52 6
x <- readline("Estimate Pareto/NBD (HB) and Pareto/GGG (press Enter)")
Estimate Pareto/NBD (HB) and Pareto/GGG (press Enter)
#' Draw Pareto/NBD parameters and compare median estimates with Pareto/NBD
#' implementation from BTYD package.
pnbd.draws <- pnbd.mcmc.DrawParameters(cal.cbs = cbs, mc.cores = 1)
set param_init: 0.7024, 4.9372, 0.3586, 6.2808
Error in .Call("_BTYDplus_slice_sample_gamma_parameters", PACKAGE = "BTYDplus", :
程序包"BTYDplus"里"_BTYDplus_slice_sample_gamma_parameters"不适用于.Call()
from btydplus.
library(BTYDplus)
demo('cdnow')
demo(cdnow)
---- ~~~~~
Type to start :
#' Load transaction records of 2357 CDNow customers.
cdnowElog <- read.csv(system.file("data/cdnowElog.csv", package = "BTYD"),
-
stringsAsFactors = FALSE,
-
col.names = c("cust", "sampleid", "date", "cds", "sales"))
cdnowElog$date <- as.Date(as.character(cdnowElog$date), format = "%Y%m%d")
head(cdnowElog)
cust sampleid date cds sales
1 4 1 1997-01-01 2 29.33
2 4 1 1997-01-18 2 29.73
3 4 1 1997-08-02 1 14.96
4 4 1 1997-12-12 2 26.48
5 21 2 1997-01-01 3 63.34
6 21 2 1997-01-13 1 11.77
range(cdnowElog$date)
[1] "1997-01-01" "1998-06-30"
#' Convert from event log to customer-by-sufficient-statistic summary.
#' Split into 39 weeks calibration, and 39 weeks holdout period.
cbs <- elog2cbs(cdnowElog, T.cal = "1997-09-30", T.tot = "1998-06-30")
head(cbs)
cust x t.x litt sales sales.x first T.cal T.star x.star
1 4 2 30.428571 4.2195077 74.02 44.69 1997-01-01 38.85714 39 1
2 18 0 0.000000 0.0000000 14.96 0.00 1997-01-04 38.42857 39 0
3 21 1 1.714286 0.5389965 75.11 11.77 1997-01-01 38.85714 39 0
4 50 0 0.000000 0.0000000 6.79 0.00 1997-01-01 38.85714 39 0
5 60 0 0.000000 0.0000000 21.75 0.00 1997-02-01 34.42857 39 0
6 71 0 0.000000 0.0000000 13.97 0.00 1997-01-01 38.85714 39 0
sales.star
1 26.48
2 0.00
3 0.00
4 0.00
5 0.00
6 0.00
#' Report some basic summary stats for calibration and holdout period.
summary(cbs[, c("x", "sales", "x.star", "sales.star")])
x sales x.star sales.star
Min. : 0.000 Min. : 0.00 Min. : 0.0000 Min. : 0.00
1st Qu.: 0.000 1st Qu.: 15.99 1st Qu.: 0.0000 1st Qu.: 0.00
Median : 0.000 Median : 36.11 Median : 0.0000 Median : 0.00
Mean : 1.042 Mean : 73.45 Mean : 0.7985 Mean : 30.11
3rd Qu.: 1.000 3rd Qu.: 75.11 3rd Qu.: 1.0000 3rd Qu.: 16.99
Max. :29.000 Max. :6552.70 Max. :34.0000 Max. :1295.52
x <- readline("Estimate NBD model (press Enter)")
Estimate NBD model (press Enter)
Estimate NBD model parameters.
(params.nbd <- nbd.EstimateParameters(cbs))
r alpha
0.3847659 12.0720137
Predict transactions at customer level with NBD model.
cbs$xstar.nbd <- nbd.ConditionalExpectedTransactions(
-
params = params.nbd,
-
T.star = cbs$T.star,
-
x = cbs$x,
-
T.cal = cbs$T.cal)
Estimate total transactions during holdout, based on NBD model.
sum(cbs$xstar.nbd)
[1] 2929.82
x <- readline("Estimate MBG/CNBD-k model (press Enter)")
Estimate MBG/CNBD-k model (press Enter)
Estimate MBG/CNBD-k model parameters.
(params.mbgcnbd <- mbgcnbd.EstimateParameters(cbs))
k r alpha a b
1.0000000 0.5248436 6.1830928 0.8913878 1.6140483
#' k=1 -> no regularity detected for CDNow
Predict transactions at customer level with MBG/CNBD-k model.
cbs$xstar.mbgcnbd <- mbgcnbd.ConditionalExpectedTransactions(
-
params = params.mbgcnbd,
-
T.star = cbs$T.star,
-
x = cbs$x,
-
t.x = cbs$t.x,
-
T.cal = cbs$T.cal)
Estimate total transactions during holdout, based on MBG/CNBD-k model.
sum(cbs$xstar.mbgcnbd)
[1] 1576.712
Estimate probabilty of being still a customer at end of calibration period.
cbs$palive.mbgcnbd <- mbgcnbd.PAlive(
-
params = params.mbgcnbd,
-
x = cbs$x,
-
t.x = cbs$t.x,
-
T.cal = cbs$T.cal)
Estimate share of retained customers at end of calibration period.
mean(cbs$palive.mbgcnbd)
[1] 0.4487195
x <- readline("Compare Log-Likelihoods of various models (press Enter)")
Compare Log-Likelihoods of various models (press Enter)
params.pnbd <- BTYD::pnbd.EstimateParameters(cbs) # estimate Pareto/NBD
params.bgcnbd <- bgcnbd.EstimateParameters(cbs) # estimate BG/CNBD-k
(ll <- c(
NBD
= nbd.cbs.LL(params.nbd, cbs),
-
`Pareto/NBD` = BTYD::pnbd.cbs.LL(params.pnbd, cbs),
-
`BG/CNBD-k` = bgcnbd.cbs.LL(params.bgcnbd, cbs),
-
`MBG/CNBD-k` = mbgcnbd.cbs.LL(params.mbgcnbd, cbs))) NBD Pareto/NBD BG/CNBD-k MBG/CNBD-k
-9763.658 -9594.976 -9582.429 -9582.136
names(which.max(ll))
[1] "MBG/CNBD-k"
-> MBG/CNBD-k provides best fit according to log-likelihood
x <- readline("Plot Frequency in Calibration (press Enter)")
Plot Frequency in Calibration (press Enter)
op <- par(mfrow = c(1, 2))
nil <- mbgcnbd.PlotFrequencyInCalibration(params.mbgcnbd, cbs, censor = 7, title = "MBG/CNBD-k")
Error in .Call("_BTYDplus_xbgcnbd_pmf_cpp", PACKAGE = "BTYDplus", params, :
程序包"BTYDplus"里"_BTYDplus_xbgcnbd_pmf_cpp"不适用于.Call()
from btydplus.
did you do a clean uninstall / install? also try re-installing Rcpp. I assume your Rcpp installation is (for some reason) broken on your system.
from btydplus.
closing this due to inactivity
from btydplus.
Related Issues (20)
- Add "m.x" to elog2cbs() output HOT 2
- mcmc.PlotTrackingCum throws error for Pareto/NBD (Abe)
- add tests for recoverability of Pareto/NBD (Abe) parameters with custom covariates
- Throw error for empty data frame? HOT 1
- slice_sample_cpp loop does not finish
- accept tibbles as input
- bgcnbd.PlotTrackingCum / mbgcnbd.PlotTrackingCum HOT 3
- Could not find mbgnbd.ConditionalExpectedTransactions HOT 3
- mbgcnbd.PlotTrackingInc legend parameter
- Python version HOT 2
- data.table.rdb is corrupt error on installing BTYDplus HOT 4
- Why are hyper_priors all 0.001? HOT 1
- Use of table in xbgcnbd.PlotFrequencyInCalibration (and mcmc.PlotFrequencyInCalibration)
- mbg-cnbd-k: ConditionalExpectedTransactions - why length >= 100
- transactions / sales with zero value should be filtered out
- churn analysis in big data with BTYDplus HOT 3
- pggg.mcmc.DrawParameters returns failed scheduled cores HOT 1
- Question: How can I get mu and lambda for each customer in abe model?
- Working with large datasets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from btydplus.