How to find correlations among feature variables in R?
MACHINE LEARNING RECIPES

How to find correlations among feature variables in R?

How to find correlations among feature variables in R?

This recipe helps you correlate the fields in a dataset to determine the relationship between them and pick the right features for modelling.

0

This recipe uses the cor (), cov (), rcorr() packages in R to establish relationships between the features. It then outputs a correlation matrix.

What is a Feature variable ?
A feature variable refers to the fields in a dataset used for analytics or machine learning. Feature selection, also known as variable selection is the process of selecting a subset of relevant features (variables) from the dataset for in model construction.

What is R ?
R is a programming language used for statistics and data science computing. R has very powerful libraries (almost 12,000) for performing data analytics including regression, classification, visualisation etc.

In [ ]:
# -------------------------------------------------
# How to find correlations among feature variables in R
# -------------------------------------------------
# load library and data
library(mlbench)
library(Hmisc)

data(mtcars)
dim(mtcars)

par(mfrow=c(1,1))

# Correlations/covariances among numeric variables 
# Use listwise deletion of missing data. 
cor(mtcars, use="complete.obs", method="kendall") 
cov(mtcars, use="complete.obs")

# Correlations with significance levels
rcorr(as.matrix(mtcars), type="pearson")

# Correlation matrix from mtcars
# with mpg, cyl, and disp as rows 
# and hp, drat, and wt as columns 
x <- mtcars[1:3]
y <- mtcars[4:6]
cor(x, y)

Relevant Projects

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

German Credit Dataset Analysis to Classify Loan Applications
In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.