Advertisement
encoree1996

Untitled

Jun 6th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. painters
  2. skladowe_painters<-painters[, 1:4]
  3.  
  4. print("skladowe glowne")
  5. skladowe_glowne=prcomp(skladowe_painters)
  6. skladowe_glowne
  7. plot(skladowe_glowne)
  8. summary(skladowe_glowne)
  9. biplot(skladowe_glowne)
  10.  
  11. print("wartosci srednie: ")
  12. print("composition: ")
  13. mean(painters[,1])
  14. print("drawing: ")
  15. mean(painters[,2])
  16. print("color: ")
  17. mean(painters[,3])
  18. print("expression ")
  19. mean(painters[,4])
  20.  
  21. print("odchylenie standardowe composition")
  22. sd(painters[,1])
  23. print("odchylenie standardowe drawing")
  24. sd(painters[,2])
  25. print("odchylenie standardowe color")
  26. sd(painters[,3])
  27. print("odchylenie standardowe expression")
  28. sd(painters[,4])
  29.  
  30. print("histogram:")
  31. summary(painters)
  32. print("composition: ")
  33. histogram_composition<-subset(painters, painters$Composition<20)
  34. summary(histogram_composition$Composition)
  35. attach(histogram_composition)
  36. summary(Composition)
  37. bin_comp=seq(min(Composition),max(Composition)+2,2)
  38. hist(Composition, main="Histogram composition", ylab="Czestotliwosc Composition", xlab="Composition", col="grey", breaks=54)
  39. print("drawing: ")
  40. hist_draw<-subset(painters, painters$Drawing<20)
  41. summary(hist_draw$Drawing)
  42. attach(hist_draw)
  43. summary(Drawing)
  44. bin_draw=seq(min(Drawing),max(Drawing)+2,2)
  45. hist(Drawing, main="Histogram of 'Drawing'", ylab="Czestotliwosc Drawing'", xlab="Drawing", col="blue", breaks=54)
  46. print("color: ")
  47. hist_col<-subset(painters, painters$Colour<20)
  48. summary(hist_col$Colour)
  49. attach(hist_col)
  50. summary(Colour)
  51. bin_col=seq(min(Colour),max(Colour)+2,2)
  52. hist(Colour, main="Histogram color", ylab="Czestotliwosc color", xlab="color", col="red", breaks=54)
  53. print("expression: ")
  54. hist_exp<-subset(painters, painters$Expression<20)
  55. summary(hist_exp$Expression)
  56. attach(hist_exp)
  57. summary(Expression)
  58. bin_exp=seq(min(Expression),max(Expression)+2,2)
  59. hist(Expression, main="Histogram expression", ylab="Czestotliwosc expression", xlab="expression", col="yellow", breaks=54)
  60.  
  61. print("macierz korelacji")
  62. pairs(painters[,1:4])
  63. cor(painters[,1:4])
  64. cor(painters[,1:4], method="spearman")
  65. cor(painters[,1:4], method="kendall")
  66.  
  67. print("klasyfikator LDA")
  68. painters.lda=lda(School~., data=painters)
  69. painters.pred=predict(painters.lda, newdata=painters)
  70. print(table_lda<-table(painters$School, painters.pred$class))
  71. print(procent<-100*sum(diag(table_lda))/sum(table_lda))
  72. print("klasyfikator QDA")
  73. painters.qda1=qda(School~Composition+Drawing, data=painters)
  74. painters.pred_qda1=predict(painters.qda1, newdata=painters)
  75. print(table_qda1<-table(painters$School, painters.pred_qda1$class))
  76. print(procent<-100*sum(diag(table_qda1))/sum(table_qda1))
  77. painters.qda2=qda(School~Colour+Expression, data=painters)
  78. painters.pred_qda2=predict(painters.qda2, newdata=painters)
  79. print(table_qda2<-table(painters$School, painters.pred_qda2$class))
  80. print(procent<-100*sum(diag(table_qda2))/sum(table_qda2))
  81.  
  82. print("metoda krokowa")
  83. set.seed(4578)
  84. painters.step_forward=stepclass(School~., data=painters, method="lda", direction="forward", improvement=0.0001)
  85. painters.step_backward=stepclass(School~., data=painters, method="lda", direction="backward", improvement=0.0001)
  86.  
  87. print("metoda bayesa")
  88. painters.bayes<-NaiveBayes(School~., data=painters, userkernel=TRUE)
  89. painters.bayes_predicted<-predict(painters.bayes, painters)
  90. print(table_bayes<-table(painters$School, painters.bayes_predicted$class))
  91. print(procent<-100.0*sum(diag(table_bayes))/sum(table_bayes))
  92.  
  93. print("metoda najblizszych sasiadow")
  94. data(painters)
  95. str(painters)
  96. table(painters$School)
  97. head(painters)
  98. set.seed(9850)
  99. painters.grp<-runif(nrow(painters))
  100. painters<-painters[order(painters.grp),]
  101. str(painters)
  102. summary(painters[,c(1,2,3,4)])
  103. normalizacja<-function(x){ return( (x-min(x))/(max(x)-min(x)) ) }
  104. painters_norm<-as.data.frame(lapply(painters[,c(1,2,3,4)], normalizacja))
  105. str(painters_norm)
  106. summary(painters_norm)
  107. painters_trening<-painters_norm[1:33,]
  108. painters_test<-painters_norm[34:54,]
  109. painters_trening_cel<-painters[1:33,5]
  110. painters_test_cel<-painters[34:54,5]
  111. require(class)
  112. model1<-knn(train=painters_trening, test=painters_test, cl=painters_trening_cel, k=8)
  113. model1
  114. table_knn=table(painters_test_cel, model1)
  115. table_knn
  116. print(procent<-100*sum(diag(table_knn))/sum(table_knn))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement