2017-12-30 18 views
0

R에서 BTYD BG NBD를 사용하고 개별 레벨을 추정했습니다. 데이터 준비를위한 BTYD Walkthrough모든 관측을위한 BTYD 개별 레벨 추정

코드 : :의 20 페이지의 문서를 다음과 같은 예를 들어

system.file("data/cdnowElog.csv", package = "BTYD")%>% 
dc.ReadLines(., cust.idx = 2, date.idx = 3, sales.idx = 5)%>% 
dc.MergeTransactionsOnSameDate()%>% 
mutate(date = parse_date_time(date, "%Y%m%d")) -> elog 
end.of.cal.period <- as.Date("1997-09-30") 
elog.cal <- elog[which(elog$date <= end.of.cal.period), ] 
split.data <- dc.SplitUpElogForRepeatTrans(elog.cal); 
birth.periods <- split.data$cust.data$birth.per 
last.dates <- split.data$cust.data$last.date 
clean.elog <- split.data$repeat.trans.elog; 
freq.cbt <- dc.CreateFreqCBT(clean.elog); 
tot.cbt <- dc.CreateFreqCBT(elog) 
cal.cbt <- dc.MergeCustomers(tot.cbt, freq.cbt) 
cal.cbs.dates <- data.frame(birth.periods, last.dates, end.of.cal.period) 
cal.cbs <- dc.BuildCBSFromCBTAndDates(cal.cbt, cal.cbs.dates,per="week") 
params <- pnbd.EstimateParameters(cal.cbs); 

하나는 특정 관찰 추정치를 얻을 수 있습니다. 개인 수준 평가에 대한 코드 :

cal.cbs["1516",] 
# x t.x T.cal 
# 26.00 30.86 31.00 
x <- cal.cbs["1516", "x"] 
t.x <- cal.cbs["1516", "t.x"] 
T.cal <- cal.cbs["1516", "T.cal"] 
bgnbd.ConditionalExpectedTransactions(params, T.star = 52, 
x, t.x, T.cal) 
# [1] 25.76 

내 질문은, 그것이 내가 하드와 같은 특정 ID 번호를 코딩하는 대신 각 행에 대한 기대를 포함하는 데이터 프레임을 얻을 수 있음을 반복적으로이 같은를 실행할 수 있습니다 " 이 경우에 "1516"?

감사합니다.

+0

난 당신의 게시물을 downvoted되지 않은 놀랍와 간단합니다. 다음 번 질문 할 때 일반 시청자가 이후에 데이터 세트를 가지고 놀고 싶다면 더 적절한 정보를 제공해주십시오. 최고의 소원. – InfiniteFlashChess

답변

0

제안은 (매우 이렇게 조언) : 당신이 질문을

다음에, 당신이 원하는 곳에 도착하는 데 필요한 코드를 게시하시기 바랍니다. 당신이 cal.cbs["1516",] 함께 있던 곳 바로 얻을

코드는이 아래였다

system.file("data/cdnowElog.csv", package = "BTYD")%>% 
dc.ReadLines(., cust.idx = 2, date.idx = 3, sales.idx = 5)%>% 
dc.MergeTransactionsOnSameDate()%>% 
mutate(date = parse_date_time(date, "%Y%m%d")) -> elog 
end.of.cal.period <- as.Date("1997-09-30") 
elog.cal <- elog[which(elog$date <= end.of.cal.period), ] 
split.data <- dc.SplitUpElogForRepeatTrans(elog.cal); 
birth.periods <- split.data$cust.data$birth.per 
last.dates <- split.data$cust.data$last.date 
clean.elog <- split.data$repeat.trans.elog; 
freq.cbt <- dc.CreateFreqCBT(clean.elog); 
tot.cbt <- dc.CreateFreqCBT(elog) 
cal.cbt <- dc.MergeCustomers(tot.cbt, freq.cbt) 
cal.cbs.dates <- data.frame(birth.periods, last.dates, end.of.cal.period) 
cal.cbs <- dc.BuildCBSFromCBTAndDates(cal.cbt, cal.cbs.dates,per="week") 
params <- pnbd.EstimateParameters(cal.cbs); 

그것은 나에게 제대로 OP 실행에 코드를 확인하기 위해 문서의 각 라인을 잡기 위해 다소 오랜 시간이 걸렸습니다. 다음에 질문 할 때이 발언 위의 코드를 포함하십시오! 사람들이 문서를 읽고이를 알아 내야한다는 것은 끔찍한 일입니다. 일반적으로 사람들은 작업의 명확성과 더미 데이터가 부족하여 질문에 답하지 않을 것입니다. 다음 번에 제공하십시오.

답변 :

네, dplyrmutate()

cal.cbs%>% 
data.frame()%>% 
mutate(`Conditional Expectation` = bgnbd.ConditionalExpectedTransactions(params, T.star = 52, x, t.x, T.cal)) 

    x  t.x T.cal Conditional Expectation 
1 2 30.428571 38.85714    2.3224971 
2 1 1.714286 38.85714    1.0646350 
3 0 0.000000 38.85714    0.5607707 
4 0 0.000000 38.85714    0.5607707 
5 0 0.000000 38.85714    0.5607707 
6 7 29.428571 38.85714    6.0231497