Chapter 7. Model Evaluation

In the previous chapter, we've seen how to create supervised learning methods. We divided our datasets into three subsets—training, validation, and testing. We also used the training dataset to train our models, and in this chapter, we'll use the validation dataset to measure the model performance and to compare different models.

In this chapter, we'll explore different methods for measuring the predictive power of a model.

As we've seen before, there are two kinds of predictive models: regression and classification. In a regression model, the output variable is a numeric variable; in a classification model, the output variable is a categorical variable. We'll start this chapter with cross-validation. After this, we'll measure the performance in regression methods, and then, we'll move on to classification performance.

Cross-validation

Cross-validation is a very useful technique to evaluate the performance of a supervised method. We will randomly split our dataset into k sub-datasets called folds (usually, 5 to 10). We will choose a fold for testing and keep the rest for training. We will train the model using the other k-1 folds and test it with a fold. We will repeat this process of training and testing k times, each time keeping a different folder for testing.

In each iteration, we will create a model and obtain a performance measure such as accuracy. When we've finished, we have k measures of performance, and we can obtain the performance of the modeling technique by calculating the average.

Using Rattle, we can split the original dataset into training, validation, and testing. Some R packages implement cross-validation when creating the model. If the model we are creating, uses cross-validation, we can skip the creation of the validation dataset and only create the training and testing datasets.

When we build a tree, such as in the previous chapter, Rattle uses the RPART package. This package implements cross-validation. For this reason, after building the model, the last information that Rattle gives us is the complexity table, which is shown here:

Cross-validation

In the complexity table, we can see the Complexity Parameter (CP) that we've discussed in the previous chapter, the number of splits (nsplit), the error in the training set (error), and the cross-validated error (xerror). Notice that by incrementing the number of splits, we will reduce the error on the training dataset very fast, but we're not interested in that because a low error in the training dataset doesn't assure a low error with the new observation. We want to reduce the cross-validated error. We can see that on row 3 with 6 folds, we've the lowest cross-validated error; after row 3, the error increases. For this reason, Rattle stops splitting the dataset.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset