-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdvertisingPredictor.R
58 lines (49 loc) · 1.41 KB
/
AdvertisingPredictor.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Chris Arnold
# Advertising Success Predictor
# Bayesian Network originally generated by naiveBayes machine
# learning algorithm from R library "e1071".
advertisingPredictor <- function(advProdTemp, advProdHealth){
# Probability of boughtAdv given adProdTemp and advProdHealth
# predicted using Bayes theorem with assumption of independent
# inputs for simplification
# P( boughtAdv | advProdTemp, advProdHealth) =
# aPriori-P(boughtAdv) * P(advTemp | boughtAdv) * P(advHealth | boughtAdv)
# / ( P(advTemp) * P(advHealth) )
# aPriori-P(boughtAdv) 0.3153816
return((0.3153816
*advProdTempCPT(advProdTemp)
*advProdHealthCPT(advProdHealth))
/(advProdTempTable(advProdTemp)*advProdHealthTable(advProdHealth)))
}
# P ( advTemp | boughtAdv)
advProdTempCPT <- function(advProdTemp){
if(advProdTemp == "Cold"){
return(0.3627914)
}else{
return(0.6372086)
}
}
# P ( advHealth | boughtAdv)
advProdHealthCPT <- function(advProdHealth){
if(advProdHealth == "Healthy"){
return(0.5745117)
}else{
return(0.4254883)
}
}
# P ( advTemp )
advProdTempTable <- funtion(advProdTemp){
if(advProdTemp == "Cold"){
return(0.3981161)
}else{
return(0.6018838)
}
}
# P ( advHealth )
advProdHealthTable <- function(advProdHealth){
if(advProdHealt == "Healthy"){
return(0.5738643)
}else{
return(0.4261356)
}
}