# # R code to load in the vowel data set from the book ESLII and classify # two classes using the routine # # two_class_LDA_with_optimal_cut_point # # and compare this routine to normal LDA (where the cut point is not specified optimally). # # See the section entitled: # # Linear Discriminant Analysis in ESLII # # Output: # # res: list of data frames XT # # 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. # #----- library(MASS) # this has functions for lda and qda source("load_vowel_data.R") source("two_class_LDA_with_optimal_cut_point_pair_vowel.R") out = load_vowel_data( FALSE ) XTrain = out[[1]] labelsTrain = out[[2]] XTest = out[[3]] labelsTest = out[[4]] # select a pair vowels to classify: indexClassOne = 7 indexClassTwo = indexClassOne+1 two_class_LDA_with_optimal_cut_point_pair_vowel( XTrain,labelsTrain,XTest,labelsTest, indexClassOne,indexClassTwo ) num_of_experiments = 0 num_times_optimal_cut_point_wins = 0 for( ii in min(labelsTrain):(max(labelsTrain)-1) ){ for( jj in (ii+1):max(labelsTrain) ){ new_method_better = two_class_LDA_with_optimal_cut_point_pair_vowel( XTrain,labelsTrain,XTest,labelsTest, ii, jj ) num_of_experiments = num_of_experiments + 1 if( new_method_better ){ num_times_optimal_cut_point_wins = num_times_optimal_cut_point_wins + 1 } } } print( sprintf("fraction of time optimal cut point is better than the orignal LDA= %10.6f", num_times_optimal_cut_point_wins / num_of_experiments ) );