Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- painters
- skladowe_painters<-painters[, 1:4]
- print("skladowe glowne")
- skladowe_glowne=prcomp(skladowe_painters)
- skladowe_glowne
- plot(skladowe_glowne)
- summary(skladowe_glowne)
- biplot(skladowe_glowne)
- print("wartosci srednia")
- print("composition: ")
- mean(painters[,1])
- print("drawing: ")
- mean(painters[,2])
- print("color: ")
- mean(painters[,3])
- print("expression ")
- mean(painters[,4])
- print("odchylenie standardowe composition")
- sd(painters[,1])
- print("odchylenie standardowe drawing")
- sd(painters[,2])
- print("odchylenie standardowe color")
- sd(painters[,3])
- print("odchylenie standardowe expression")
- sd(painters[,4])
- print("histogram:")
- summary(painters)
- print("composition: ")
- histogram_composition<-subset(painters, painters$Composition<20)
- summary(histogram_composition$Composition)
- attach(histogram_composition)
- summary(Composition)
- bin_comp=seq(min(Composition),max(Composition)+2,2)
- hist(Composition, main="Histogram composition", ylab="Czestotliwosc Composition", xlab="Composition", col="grey", breaks=54)
- print("DLA 'DRAWING'")
- hist_draw<-subset(painters, painters$Drawing<20)
- summary(hist_draw$Drawing)
- attach(hist_draw)
- summary(Drawing)
- bin_draw=seq(min(Drawing),max(Drawing)+2,2)
- hist(Drawing, main="Histogram of 'Drawing'", ylab="Czestotliwosc Drawing'", xlab="Drawing", col="blue", breaks=54)
- print("color: ")
- hist_col<-subset(painters, painters$Colour<20)
- summary(hist_col$Colour)
- attach(hist_col)
- summary(Colour)
- bin_col=seq(min(Colour),max(Colour)+2,2)
- hist(Colour, main="Histogram color", ylab="Czestotliwosc color", xlab="color", col="red", breaks=54)
- print("expression: ")
- hist_exp<-subset(painters, painters$Expression<20)
- summary(hist_exp$Expression)
- attach(hist_exp)
- summary(Expression)
- bin_exp=seq(min(Expression),max(Expression)+2,2)
- hist(Expression, main="Histogram expression", ylab="Czestotliwosc expression", xlab="expression", col="yellow", breaks=54)
- print("macierz korelacji")
- pairs(painters[,1:4])
- cor(painters[,1:4]) #Pearson
- cor(painters[,1:4], method="spearman")
- cor(painters[,1:4], method="kendall")
- print("klasyfikator LDA")
- painters.lda=lda(School~., data=painters)
- painters.pred=predict(painters.lda, newdata=painters)
- print(table_lda<-table(painters$School, painters.pred$class))
- print(procent<-100*sum(diag(table_lda))/sum(table_lda))
- print("klasyfikator QDA")
- painters.qda1=qda(School~Composition+Drawing, data=painters)
- painters.pred_qda1=predict(painters.qda1, newdata=painters)
- print(table_qda1<-table(painters$School, painters.pred_qda1$class))
- print(procent<-100*sum(diag(table_qda1))/sum(table_qda1))
- painters.qda2=qda(School~Colour+Expression, data=painters)
- painters.pred_qda2=predict(painters.qda2, newdata=painters)
- print(table_qda2<-table(painters$School, painters.pred_qda2$class))
- print(procent<-100*sum(diag(table_qda2))/sum(table_qda2))
- print("metoda krokowa")
- set.seed(4578)
- painters.step_forward=stepclass(School~., data=painters, method="lda", direction="forward", improvement=0.0001)
- painters.step_backward=stepclass(School~., data=painters, method="lda", direction="backward", improvement=0.0001)
- print("metoda bayesa")
- painters.bayes<-NaiveBayes(School~., data=painters, userkernel=TRUE)
- painters.bayes_predicted<-predict(painters.bayes, painters)
- print(table_bayes<-table(painters$School, painters.bayes_predicted$class))
- print(procent<-100.0*sum(diag(table_bayes))/sum(table_bayes))
- print("metoda najblizszych sasiadow")
- data(painters)
- str(painters)
- table(painters$School)
- head(painters)
- set.seed(9850)
- painters.grp<-runif(nrow(painters))
- painters<-painters[order(painters.grp),]
- str(painters)
- summary(painters[,c(1,2,3,4)])
- normalizacja<-function(x){ return( (x-min(x))/(max(x)-min(x)) ) }
- painters_norm<-as.data.frame(lapply(painters[,c(1,2,3,4)], normalizacja))
- str(painters_norm)
- summary(painters_norm)
- painters_trening<-painters_norm[1:33,]
- painters_test<-painters_norm[34:54,]
- painters_trening_cel<-painters[1:33,5]
- painters_test_cel<-painters[34:54,5]
- require(class)
- model1<-knn(train=painters_trening, test=painters_test, cl=painters_trening_cel, k=8)
- model1
- table_knn=table(painters_test_cel, model1)
- table_knn
- print(procent<-100*sum(diag(table_knn))/sum(table_knn))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement