# # Epage 126 # Epage 134 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- source("load_vowel_data.R") source("reduced_rank_LDA.R") out = load_vowel_data( FALSE, FALSE ) XTrain = out[[1]] yTrain = out[[2]] XTest = out[[3]] yTest = out[[4]] out = reduced_rank_LDA( XTrain, yTrain, XTest, yTest ) K = length(unique(yTrain)) # the number of classes (expect the classes to be labeled 1, 2, 3, ..., K-1, K p = dim( XTrain )[2] # the number of features TrainClassification = out[[4]] TestClassification = out[[5]] #postscript("../../WriteUp/Graphics/Chapter4/dup_fig_4_10.eps", onefile=FALSE, horizontal=FALSE) train_error_rate = matrix( data=0, nrow=1, ncol=p ) test_error_rate = matrix( data=0, nrow=1, ncol=p ) NTrain = dim(XTrain)[1] NTest = dim(XTest)[1] for( pi in 1:p ){ train_error_rate[pi] = sum( TrainClassification[,pi] != yTrain )/NTrain test_error_rate[pi] = sum( TestClassification[,pi] != yTest )/NTest } plot( 1:p, train_error_rate, col="red", ylim=c( 0.3, 0.7 ), type="b", xlab="Dimension", ylab="Misclassification rate" ) # range( c(train_error_rate,test_error_rate) ) lines( 1:p, test_error_rate, col="blue", type="b" ) #dev.off()