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 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.