Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(MASS)
- painters
- painters_sg<-painters[, 1:4]
- print("Skladowe glowne: ")
- sklad_glowne=prcomp(painters_sg)
- sklad_glowne
- plot(sklad_glowne)
- summary(sklad_glowne)
- biplot(sklad_glowne)
- print("Wartosci srednie: ")
- print("Composition: ")
- mean(painters[,1])
- print("Drawings: ")
- mean(painters[,2])
- print("Colors: ")
- mean(painters[,3])
- print("Expressions: ")
- mean(painters[,4])
- print("Odchylenia standardowe: ")
- print("Composition: ")
- sd(painters[,1])
- print("Drawings: ")
- sd(painters[,2])
- print("Color: ")
- sd(painters[,3])
- print("Expression: ")
- sd(painters[,4])
- print("Histogram: ")
- summary(painters)
- print("Composition: ")
- hist_comp<-subset(painters, painters$Composition<20)
- summary(hist_comp$Composition)
- attach(hist_comp)
- summary(Composition)
- bin_comp=seq(min(Composition),max(Composition)+2,2)
- hist(Composition, main="Histogram composition", ylab="Czestotl composition", xlab="Composition", col="grey", breaks=54)
- print("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 drawing", ylab="Czestotl 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="Czestotl color", xlab="Colour", 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 of 'Expression'", ylab="Czestotl expression", xlab="Expression", col="yellow", breaks=54)
- print("Macierz korelacji: ")
- pairs(painters[,1:4])
- cor(painters[,1:4])
- 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_forw=stepclass(School~., data=painters, method="lda", direction="forward", improvement=0.0001)
- painters.step_back=stepclass(School~., data=painters, method="lda", direction="backward", improvement=0.0001)
- print("Metoda Bayesa")
- painters.bayes<-NaiveBayes(School~., data=painters, userkernel=TRUE)
- painters.bayes_pred<-predict(painters.bayes, painters)
- print(table_bayes<-table(painters$School, painters.bayes_pred$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)) ) }
- paintersNorm<-as.data.frame(lapply(painters[,c(1,2,3,4)], normalizacja))
- str(paintersNorm)
- summary(paintersNorm)
- paintersTrn<-paintersNorm[1:33,]
- painters_test<-paintersNorm[34:54,]
- paintersTrn_cel<-painters[1:33,5]
- painters_test_cel<-painters[34:54,5]
- require(class)
- model1<-knn(train=paintersTrn, test=painters_test, cl=paintersTrn_cel, k=8)
- model1
- knnTable=table(painters_test_cel, model1)
- knnTable
- print(procent<-100*sum(diag(knnTable))/sum(knnTable))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement