Computing probabilities
The where9am data frame contains 91 days (thirteen weeks) worth of data in which Brett recorded his location at 9am each day as well as whether the daytype was a weekend or weekday.
Using the conditional probability formula below, you can compute the probability that Brett is working in the office, given that it is a weekday.
$$ P(A|B) = \frac{P(A \text{ and } B)}{P(B)} $$
Calculations like these are the basis of the Naive Bayes destination prediction model you'll develop in later exercises.
Latihan ini adalah bagian dari kursus
Supervised Learning in R: Classification
Petunjuk latihan
- Find P(office) using
nrow()andsubset()to count rows in the dataset and save the result asp_A. - Find P(weekday), using
nrow()andsubset()again, and save the result asp_B. - Use
nrow()andsubset()a final time to find P(office and weekday). Save the result asp_AB. - Compute P(office | weekday) and save the result as
p_A_given_B. - Print the value of
p_A_given_B.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Compute P(A)
p_A <- ___
# Compute P(B)
p_B <- ___
# Compute the observed P(A and B)
p_AB <- ___
# Compute P(A | B) and print its value
p_A_given_B <- ___
___