Get startedGet started for free

Examining "raw" probabilities

The naivebayes package offers several ways to peek inside a Naive Bayes model.

Typing the name of the model object provides the a priori (overall) and conditional probabilities of each of the model's predictors. If one were so inclined, you might use these for calculating posterior (predicted) probabilities by hand.

Alternatively, R will compute the posterior probabilities for you if the type = "prob" parameter is supplied to the predict() function.

Using these methods, examine how the model's predicted 9am location probability varies from day-to-day. The model locmodel that you fit in the previous exercise is available for you to use, and the naivebayes package has been pre-loaded.

This exercise is part of the course

Supervised Learning in R: Classification

View Course

Exercise instructions

  • Print the locmodel object to the console to view the computed a priori and conditional probabilities.
  • Use the predict() function similarly to the previous exercise, but with type = "prob" to see the predicted probabilities for Thursday at 9am.
  • Compare these to the predicted probabilities for Saturday at 9am.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Examine the location prediction model


# Obtain the predicted probabilities for Thursday at 9am
predict(___, ___ , type = ___)

# Obtain the predicted probabilities for Saturday at 9am
Edit and Run Code