Database Reference
In-Depth Information
desireCounts
Desire
Enrolls Excellent Fair
No 0.6000000 0.4000000
Yes 0.3333333 0.6666667
According to Equation 7.7 , probability is determined by the product of
times the where and . The larger value of and
determines the predicted result of the output variable. Given the test data,
use the following code to predict the Enrolls .
prob_yes <-
ageCounts["Yes",testdata[,c("Age")]]*
incomeCounts["Yes",testdata[,c("Income")]]*
jsCounts["Yes",testdata[,c("JobSatisfaction")]]*
desireCounts["Yes",testdata[,c("Desire")]]*
tprior["Yes"]
prob_no <-
ageCounts["No",testdata[,c("Age")]]*
incomeCounts["No",testdata[,c("Income")]]*
jsCounts["No",testdata[,c("JobSatisfaction")]]*
desireCounts["No",testdata[,c("Desire")]]*
tprior["No"]
max(prob_yes,prob_no)
As shown below, the predicted result of the test set is Enrolls =Yes .
prob_yes
Yes
0.02821869
prob_no
No
0.006857143
max(prob_yes, prob_no)
[1] 0.02821869
The e1071 package in R has a built-in naiveBayes function that can compute
the conditional probabilities of a categorical class variable given independent
Search WWH ::




Custom Search