O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To reduce dimensionality with PCA, follow these steps:

  1. Read the data:
> bh <- read.csv("BostonHousing.csv")
  1. View the correlation matrix to check whether some variables are highly correlated and whether PCA has the potential to yield some dimensionality reduction. As we are interested in reducing the dimensionality of the predictor variables, we leave out the outcome variable, MEDV:
> corr <- cor(bh[,-14]) > corrplot(corr, method="color")

Positive correlations are displayed in blue and negative correlations in red. Color intensity and the size of the circle are proportional to the correlation coefficients. Ignoring the main ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required