How to do it...

Perform the following steps to perform nonlinear dimension reduction with ISOMAP:

  1. First, install and load the RnavGraphImageData and vegan packages:
        > install.packages("RnavGraphImageData")
        > install.packages("vegan")
        > library(RnavGraphImageData)
        > library(vegan)  
  1. You can then load the dataset, digits:
        > data(digits)  
  1. Rotate and plot the image:
       > sample.digit = matrix(digits[,3000],ncol = 16, byrow=FALSE)
       > image(t(sample.digit)[,nrow(sample.digit):1])  
A sample image from the digits dataset
  1. Next, you can randomly sample 300 digits from the population:
> set.seed(2)
> digit.idx = sample(1:ncol(digits),size = 600)
> digit.select = digits[,digit.idx] 
  1. Transpose the selected digit data and then compute the dissimilarity between objects using vegdist:
        > digits.Transpose = t(digit.select)
        > digit.dist = vegdist(digits.Transpose, method="euclidean") 
  1. Next, you can use isomap to perform dimension reduction:
        > digit.isomap = isomap(digit.dist,k = 8, ndim=6, fragmentedOK
= TRUE) > plot(digit.isomap)
A two-dimension scatter plot from ISOMAP object
  1. Finally, you can overlay the scatter plot with the minimum spanning tree, marked in red:
        > digit.st = spantree(digit.dist)
        > digit.plot = plot(digit.isomap, main="isomap k=8")
        > lines(digit.st, digit.plot, col="red")  
A two-dimension scatter plot overlay with minimum spanning tree
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset