Exercise

Out-of-sample testing

Your goal is to make purchase predictions for new stores based on your estimated model. You check if this goal is viable by using the function predict(). The predict() function retrieves the parameter estimates of train.model to make predictions about the response variable in test.data. To obtain predicted values on the scale of the response variable (the predicted purchase probabilities) you have to set the additional type argument to "response".

Finally, the hold-out predictions are classified into purchases and no-purchases by using the function ifelse() and compared to the observed purchases by using the function table(). Finally, you use the function prop.table() to convert the numbers in the table into relative numbers.

Instructions

100 XP
  • Predict the responses for test.data by using the function predict() on train.model. Set the type argument to "response" and name the result probability.
  • Classify the model predictions into 1 if the probability exceeds 0.5 and 0 otherwise. Assign the result to an object predicted.
  • Obtain the observed purchases for HOPPINESS from test.data. Assign them to an object observed.
  • Cross-tabulate the observed and predicted data vectors by using the functions table() and prop.table().