7406_solution3

# 7406_solution3 - ISyE 7406, Spring-2007 Instructor:...

This preview shows pages 1–3. Sign up to view the full content.

ISyE 7406, Spring-2007 Instructor: Kwok-Leung Tsui Assignment # 3 (Solution) Question 1: v:number of folds m:max number of neighbors cv knn=function(v,x,y,m) { n < -length(y) n1 < -Foor(n/v) n2 < -n-n1*v n3 < -v-n2 ind < -rep(c(n1,n1+1),c(n3,n2)) ind < -di±nv(ind) cv.error < -matrix(0,v,m) samp¡-sample(1:n,n,replace=²ALSE) for(i in 1:v) { temp.test < -samp[(ind[i]+1):ind[i+1]] for(j in 1:m) { temp.pred < -knn(x[-temp.test,],x[temp.test,],y[-temp.test],k=j) temp.table < -table(temp.pred,y[temp.test]) cv.error[i,j] < -1-sum(diag(temp.table))/length(temp.test) }} avg.error < -apply(cv.error,2,mean) sd.error < -apply(cv.error,2,sd)/sqrt(n1) limit < -min(avg.error)+sd.error[which.min(avg.error)] # 1 sd criterion cv knn < -max(which(avg.error < limit)) print(c(cv knn,avg.error[cv knn])) } Question 2: best k: 15; min error k: 9 0.08900598 0.08835239 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Question 3: Logistic Regression Train Validation Test [1,] 0.06588389 0.06779661 0.07822686 [2,] 0.07175473 0.07692308 0.07431551 [3,] 0.06523157 0.07692308
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/13/2010 for the course ISE 680 taught by Professor Santanu during the Spring '10 term at Purdue University Calumet.

### Page1 / 3

7406_solution3 - ISyE 7406, Spring-2007 Instructor:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online