R : Copyright 2003, The R Development Core Team Version 1.6.2 (2003-01-10) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type `license()' or `licence()' for distribution details. R is a collaborative project with many contributors. Type `contributors()' for more information. Type `demo()' for some demos, `help()' for on-line help, or `help.start()' for a HTML browser interface to help. Type `q()' to quit R. > invisible(options(echo = TRUE)) > train <- read.table("loans.dat",header=F,col.names=c("x1","x2","y")); > > x1 <- train$x1; > x2 <- train$x2; > > one <- mat.or.vec(length(x1),1) + 1.0; > X <- cbind(one,x1,x2,x1*x2,x1^2,x2^2); > y <- train$y; > > fit <- lsfit(X,y,intercept=FALSE); > b <- as.numeric(fit$coef); > > y <- train$y; > y <- (y==1); > > size <- 100; > grid <- mat.or.vec((size+1)*(size+1),2); > for (i in 0:size) { + for (j in 0:size) { + grid[(size+1)*j+i+1,1] <- i; + grid[(size+1)*j+i+1,2] <- j; + } + } > grid <- grid/(size+1); > > gx1 <- grid[,1]; > gx2 <- grid[,2]; > > one <- mat.or.vec(length(gx1),1) + 1.0; > X <- cbind(one,gx1,gx2,gx1*gx2,gx1^2,gx2^2); > > pred <- X%*%b; > dflt <- (pred > 0.5); > > edge <- ((0.489 > source("psopts.r"); > postscript(file="quad.eps"); > > plot(x=x1,y=x2,type='n',xlab="FICO Score",ylab="P-Index"); > points(x=x1[y],y=x2[y],pch='o',col="red"); > points(x=x1[!y],y=x2[!y],pch='o',col="green"); > points(grid[dflt,],pch='.',col="red"); > points(grid[!dflt,],pch='.',col="green"); > points(grid[edge,],pch="+",cex=0.4); > > dev.off(); null device 1 > > test <- read.table("eval.dat",header=F,col.names=c("x1","x2","y")); > > tx1 <- test$x1; > tx2 <- test$x2; > ty <- test$y; > > one <- mat.or.vec(length(tx1),1) + 1.0; > X <- cbind(one,tx1,tx2,tx1*tx2,tx1^2,tx2^2); > > pred <- X%*%b; > dflt <- (pred > 0.5); > > dflt <- as.numeric(dflt); > > err <- abs(dflt-ty); > print(mean(err)); [1] 0.07807 > proc.time() [1] 2.68 0.11 2.78 0.00 0.00 >