Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. dane<-read.csv("F:/LAB_06/9.csv", sep=";", dec=".", header = TRUE)
  2.  
  3. #podzial losowy
  4. indeksy<-sample(1:nrow(dane))
  5. new_data<-dane[indeksy,]
  6.  
  7. #zbior uczacy
  8. uczaca<-new_data[1:3,]
  9.  
  10. #zbior testujacy
  11. testujacy<-new_data[4:11,]
  12.  
  13. #drzewo decyzyjne
  14. drzewo<-rpart(Zużycie~.,data = uczaca, method = "class")
  15. rpart.plot(drzewo)
  16.  
  17. #wynik_klasyfikacji<-predict(drzewo, newdata = testujacy, type="class")
  18. #macierz<-table(testujacy$Zużycie, wynik_klasyfikacji)
  19. #l_wszystkie<-sum(macierz)
  20. #l_poprawnie<-sum(diag(macierz))
  21. #blednie<-l_wszystkie-l_poprawnie;
  22. #blad<-(blednie/l_wszystkie)*100
  23.  
  24. k<-11
  25. blok<-cut(seq(1:nrow(new_data)), breaks = 11, labels = FALSE)
  26. blad<-0
  27. wszystkie<-0
  28. for(i in 1:k){
  29. testIndex<-which(blok == i)
  30. test<-new_data[testIndex,]
  31. train<-new_data[-testIndex,]
  32.  
  33. drzewo2<-rpart(Zużycie~.,data = train, method = "class")
  34. #rpart.plot(drzewo2)
  35.  
  36. wynik_klasyfikacji2<-predict(drzewo2, newdata = test, type="class")
  37. macierz2<-table(test$Zużycie, wynik_klasyfikacji2)
  38.  
  39. l_wszystkie<-sum(macierz2)
  40. l_poprawnie<-sum(diag(macierz2))
  41. blednie<-l_wszystkie-l_poprawnie;
  42. #blad2<-(blednie/l_wszystkie)*100
  43. blad<-(blad+blednie)
  44. wszystkie<-(wszystkie+l_wszystkie)
  45. print(macierz2)
  46.  
  47. }
  48.  
  49. blad<-(blad/wszystkie)*100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement