Evaluating a classification model

Earlier in this chapter, we discussed five different ways to look at the performance of a classification model. In this section, we are going to learn how we can compute and visualize the metrics for evaluating a classification model in R using the random forest model we have just built.

The first three metrics that we are going to look at are accuracy, precision, and recall. Before we go ahead and evaluate the model performance, we will need the model prediction results. In order to have the random forest model we have built in the previous section make predictions on a dataset, we can simply use the predict function. Take a look at the following code:

inSamplePreds <- as.double(predict(rfModel, trainX)) ...

Get Hands-On Data Science for Marketing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.