Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dane<-read.csv("F:/LAB_06/9.csv", sep=";", dec=".", header = TRUE)
- #podzial losowy
- indeksy<-sample(1:nrow(dane))
- new_data<-dane[indeksy,]
- #zbior uczacy
- uczaca<-new_data[1:3,]
- #zbior testujacy
- testujacy<-new_data[4:11,]
- #drzewo decyzyjne
- drzewo<-rpart(Zużycie~.,data = uczaca, method = "class")
- rpart.plot(drzewo)
- #wynik_klasyfikacji<-predict(drzewo, newdata = testujacy, type="class")
- #macierz<-table(testujacy$Zużycie, wynik_klasyfikacji)
- #l_wszystkie<-sum(macierz)
- #l_poprawnie<-sum(diag(macierz))
- #blednie<-l_wszystkie-l_poprawnie;
- #blad<-(blednie/l_wszystkie)*100
- k<-11
- blok<-cut(seq(1:nrow(new_data)), breaks = 11, labels = FALSE)
- blad<-0
- wszystkie<-0
- for(i in 1:k){
- testIndex<-which(blok == i)
- test<-new_data[testIndex,]
- train<-new_data[-testIndex,]
- drzewo2<-rpart(Zużycie~.,data = train, method = "class")
- #rpart.plot(drzewo2)
- wynik_klasyfikacji2<-predict(drzewo2, newdata = test, type="class")
- macierz2<-table(test$Zużycie, wynik_klasyfikacji2)
- l_wszystkie<-sum(macierz2)
- l_poprawnie<-sum(diag(macierz2))
- blednie<-l_wszystkie-l_poprawnie;
- #blad2<-(blednie/l_wszystkie)*100
- blad<-(blad+blednie)
- wszystkie<-(wszystkie+l_wszystkie)
- print(macierz2)
- }
- blad<-(blad/wszystkie)*100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement