A simple Naive Bayes location model
The previous exercises showed that the probability that Brett is at work or at home at 9am is highly dependent on whether it is the weekend or a weekday.
To see this finding in action, use the where9am
data frame to build a Naive Bayes model on the same data.
You can then use this model to predict the future: where does the model think that Brett will be at 9am on Thursday and at 9am on Saturday?
The data frame where9am
is available in your workspace. This dataset contains information about Brett's location at 9am on different days.
This exercise is part of the course
Supervised Learning in R: Classification
Exercise instructions
- Load the
naivebayes
package. - Use
naive_bayes()
with a formula likey ~ x
to build a model oflocation
as a function ofdaytype
. - Forecast the Thursday 9am location using
predict()
with thethursday9am
object as thenewdata
argument. - Do the same for predicting the
saturday9am
location.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load the naivebayes package
# Build the location prediction model
locmodel <- naive_bayes(___, data = ___)
# Predict Thursday's 9am location
predict(___, ___)
# Predict Saturdays's 9am location