Advertisement
encoree1996

Untitled

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