Perform the following steps to perform nonlinear dimension reduction with ISOMAP:
- First, install and load the RnavGraphImageData and vegan packages:
> install.packages("RnavGraphImageData") > install.packages("vegan") > library(RnavGraphImageData) > library(vegan)
- You can then load the dataset, digits:
> data(digits)
- 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
- 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]
- 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")
- 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
- 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