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.
Este ejercicio forma parte del curso
Building Response Models in R
Instrucciones del ejercicio
- Predict the responses for
test.databy using the functionpredict()ontrain.model. Set thetypeargument to"response"and name the resultprobability. - Classify the model predictions into
1if theprobabilityexceeds0.5and0otherwise. Assign the result to an objectpredicted. - Obtain the observed purchases for
HOPPINESSfromtest.data. Assign them to an objectobserved. - Cross-tabulate the
observedandpredicteddata vectors by using the functionstable()andprop.table().
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Predict the purchase probabilities for test.data
probability <- ___(___, ___, type = "response")
# Classify the predictions
predicted <- ___(probability >= ___, ___, ___)
# Obtain the observed purchases from test.data
observed <- test.data$HOPPINESS
# Cross-tabulate observed vs. predicted purchases
___(___(predicted, observed))