library(MASS); library(nnet) X=as.matrix(crabs[,4:8]); y=c(rep(1,50),rep(2,50),rep(3,50),rep(4,50)) pe1=sample(50); pe2=sample(50)+50; pe3=sample(50)+100; pe4=sample(50)+150 ppp.qda=rep(NA,5); ppp.nnet=rep(NA,5) for(i in 1:5){ ind=((i-1)*10+1):(i*10) te1=pe1[ind]; te2=pe2[ind]; te3=pe3[ind]; te4=pe4[ind] te=c(te1,te2,te3,te4); tr=(1:200)[-te] K=qda(X[tr,],y[tr]) pred=predict(K,X[te,])$class ppp.qda[i] = mean( y[te] == pred ) S=nnet(X[tr,],class.ind(y[tr]),maxit=200, trace=F,size=16,softmax=T) pred2=apply(predict(S,X[te,]),1,which.max) ppp.nnet[i] = mean( y[te] == pred2 ) } cat("\nP-stwo poprawnej predykcji qda:\n",round(ppp.qda,2),"\n") cat("P-stwo poprawnej predykcji nnet:\n",round(ppp.nnet,2),"\n")