Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. > dim(train)
  2. [1] 33 102
  3. > unique(train[,1])
  4. [1] Crete Peloponese Other
  5. Levels: Crete Other Peloponese
  6.  
  7. > train.pca <- prcomp(train[,-1],center = TRUE,scale. = TRUE)
  8. > summary(train.pca)
  9. Importance of components:
  10. PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10 PC11
  11. Standard deviation 6.2499 5.5934 4.3538 2.5857 1.53128 1.1457 0.88391 0.5223 0.37085 0.27148 0.20914
  12. Proportion of Variance 0.3867 0.3098 0.1877 0.0662 0.02322 0.0130 0.00774 0.0027 0.00136 0.00073 0.00043
  13. Cumulative Proportion 0.3867 0.6965 0.8842 0.9504 0.97360 0.9866 0.99433 0.9970 0.99840 0.99912 0.99956
  14. PC12 PC13 PC14 PC15 PC16 PC17 PC18 PC19 PC20 PC21
  15. Standard deviation 0.10622 0.09947 0.07317 0.06188 0.05741 0.04700 0.04026 0.03675 0.03154 0.03029
  16. Proportion of Variance 0.00011 0.00010 0.00005 0.00004 0.00003 0.00002 0.00002 0.00001 0.00001 0.00001
  17. Cumulative Proportion 0.99967 0.99977 0.99982 0.99986 0.99989 0.99991 0.99993 0.99994 0.99995 0.99996
  18. PC22 PC23 PC24 PC25 PC26 PC27 PC28 PC29 PC30 PC31
  19. Standard deviation 0.02676 0.02422 0.02301 0.01986 0.01969 0.01836 0.01757 0.01506 0.01304 0.01241
  20. Proportion of Variance 0.00001 0.00001 0.00001 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
  21. Cumulative Proportion 0.99997 0.99997 0.99998 0.99998 0.99999 0.99999 0.99999 1.00000 1.00000 1.00000
  22. PC32 PC33
  23. Standard deviation 0.01016 3.344e-13
  24. Proportion of Variance 0.00000 0.000e+00
  25. Cumulative Proportion 1.00000 1.000e+00
  26.  
  27. validation.pca <- predict(train.pca,newdata = validation[,-1])
  28.  
  29. > set.seed(1234)
  30. > #tune k using transformed data
  31. > ccr.tnx <-numeric(25)
  32. > for(j in 1:25)
  33. + {
  34. + pred.class.tnx<-knn(train.pca$x[,1:4],
  35. + validation.pca[,1:4],
  36. + train[,1],
  37. + k=j)
  38. + ccr.tnx[j]<-sum((pred.class.tnx==validation[,1]))/length(pred.class.tnx)
  39. + print(ccr.tnx[j])
  40. + }
  41. [1] 0.8823529
  42. [1] 0.8823529
  43. [1] 0.7058824
  44. [1] 0.8235294
  45. [1] 0.8235294
  46. [1] 0.8235294
  47. [1] 0.6470588
  48. [1] 0.7647059
  49. [1] 0.7058824
  50. [1] 0.6470588
  51. [1] 0.8235294
  52. [1] 0.7647059
  53. [1] 0.7647059
  54. [1] 0.7058824
  55. [1] 0.7647059
  56. [1] 0.6470588
  57. [1] 0.6470588
  58. [1] 0.7647059
  59. [1] 0.7647059
  60. [1] 0.7058824
  61. [1] 0.6470588
  62. [1] 0.5882353
  63. [1] 0.5294118
  64. [1] 0.7058824
  65. [1] 0.7058824
  66.  
  67. > ccr.tnx[2]
  68. [1] 0.8823529
  69.  
  70. > set.seed(1234)
  71. > pred.class.tnx.2<-knn(train.pca$x[,1:4],
  72. + validation.pca[,1:4],
  73. + train[,1],
  74. + k=2)
  75. > sum((pred.class.tnx.2==validation[,1]))/length(pred.class.tnx.2)
  76. [1] 0.6470588
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement