How to do it...

Perform the following steps to perform dimension reduction using SVD:

  1. First, you can perform svd on the swiss dataset:
        > swiss.svd = svd(swiss)  
  1. You can then plot the percentage of variance explained and the cumulative variance explained in accordance with the SVD column:
        > plot(swiss.svd$d^2/sum(swiss.svd$d^2), type="l", xlab=" Singular        vector", ylab = "Variance explained")
The percent of variance explained
       > plot(cumsum(swiss.svd$d^2/sum(swiss.svd$d^2)), type="l",        xlab="Singular vector", ylab = "Cumulative percent of variance        explained")  
Cumulative percent of variance explained
  1. Next, you can reconstruct the data ...

Get Machine Learning with R Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.