Finding highly correlated features with the caret package

When performing regression or classification, some models perform better if highly correlated attributes are removed. The caret package provides the findCorrelation function, which can be used to find attributes that are highly correlated to each other. In this recipe, we will demonstrate how to find highly correlated features using the caret package.

Getting ready

In this recipe, we will continue to use the telecom churn dataset as the input data source to find highly correlated features.

How to do it...

Perform the following steps to find highly correlated attributes:

  1. Remove the features that are not coded in numeric characters:
    > new_train = trainset[,! names(churnTrain) %in% c("churn", "international_plan", ...

Get R: Recipes for Analysis, Visualization and Machine Learning 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.