5) Create a Naive Bayesian Network with a Laplace Estimator.

This Blog entry is from the Naive Bayesian section in Learn R.

To create a Bayesian model with a nominal Laplace estimator of 1, which will mean that in the event that there is nothing it is switch to at least one occurrence in the observation, simply change the parameter value in the training:

SafeBayesianModel <- naiveBayes(CreditRisk,CreditRisk$Dependent,laplace=1)
1.png

Run the line of script to console:

2.png

A Bayesian model has been created as SafeBaysianModel.  Recall the model:

ClassPredictions <- predict(SafeBayesianModel,CreditRisk,type = "class")
3.png

Run the line of script to console:

4.png

The de-facto method to appraise the performance of the model would be to create a confusion matrix:

library(gmodels)
CrossTable(CreditRisk$Dependent, ClassPredictions)
5.png

Run the block of script to console:

6.png

It can be seen that this naive Bayesian model appears to be startlingly accurate, which stands to reason as the same data is being used to test as was trained.  It follows that this would benefit from an element of cross validation, which was introduced in Gradient Boosting Machines.