Please allow me to ask a basic question. I understand the mechanics of Naive Bayes for discrete variables, and can redo the calculations "by hand". (code of HouseVotes84 all the way per below).
However - I am struggling to see how the mechanics work for continuous variables (example code per below). How does the package calculate the conditional probabilities
[, 1] and
[, 2] in the table per below? As any individual X value is unique, does it create a range around each point, and calculate relative frequencies within these ranges (e.g. if the point is +0.311, does it evaluate the incidence of blue and orange spots in e.g. a range of 0.1 and +0.5?) This might be basic question - apologies if so.
A-priori probabilities: Y blue orange 0.5 0.5 Conditional probabilities: values Y [,1] [,2] blue 0.08703793 0.9238799 orange 1.33486433 0.9988389
blue=rep("blue",50); orange=rep("orange",50); colour=c(blue,orange); values1=rnorm(50,0,1); values2=rnorm(50,1,1); values=c(values1,values2) df=data.frame(colour,values) (model <- naiveBayes(colour ~ ., data = df)) (predict(model, df[1:10,])) (predict(model, df[1:10,], type = "raw")) (pred <- predict(model, df)) table(pred, df$colour) ## Categorical data only: library(e1071) data(HouseVotes84, package = "mlbench") HouseVotes84=HouseVotes84[,1:3] (model <- naiveBayes(Class ~ ., data = HouseVotes84)) (predict(model, HouseVotes84[1:10,])) (predict(model, HouseVotes84[1:10,], type = "raw")) (pred <- predict(model, HouseVotes84)) table(pred, HouseVotes84$Class)