### Simulate the data:
cols <- 10 ; rows <- 100
M <- matrix(sample(0:5, rows * cols, TRUE), nrow = rows, ncol = cols)
y <- factor(sample(paste0("class", LETTERS[1:2]), rows, TRUE, prob = c(0.3,0.7)))
colnames(M) <- paste0("V", seq_len(ncol(M)))
laplace <- 1
### Train the Multinomial Naive Bayes
mnb <- multinomial_naive_bayes(x = M, y = y, laplace = laplace)
# Classification
head(predict(mnb, newdata = M, type = "class"))
head(mnb %class% M)
# Posterior probabilities
head(predict(mnb, newdata = M, type = "prob"))
head(mnb %prob% M)
Run the code above in your browser using DataLab