# NOT RUN {
# Use the pewee dataset and look at the last 8 elements:
substring(pewee, nchar(pewee)-7, nchar(pewee))
# [1] "10001001"
# Predict last 8 elements using the prediction function
pred <- prediction(pewee, 10, nchar(pewee)-8)[["Prediction"]]
# Taking only the "Prediction" vector:
pred
# [1] "1" "0" "0" "1" "1" "0" "0" "1"
# To transform the result of the prediction function into a "character" object:
paste(pred, collapse = "")
# [1] "10011001"
# As observed, there is only 1 error (the sixth predicted element is 1 instead of a 0).
# Thus, up to the 4th place, the averaged error is 0
# and the sixth averaged error is expected to be 1/4.
# Indeed, the zero_one_loss function yields the expected answer:
zero_one_loss(pewee, 10, nchar(pewee)-8)
# [1] 0.0000000 0.0000000 0.0000000 0.2500000 0.2000000 0.1666667 0.1428571 0.1250000
# }
Run the code above in your browser using DataLab