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; > y <- train$y; > > fit <- lsfit(cbind(x1,x2),y,intercept=TRUE); > b <- as.numeric(fit$coef); > > 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]; > > pred <- b[1] + b[2]*gx1 + b[3]*gx2; > dflt <- (pred > 0.5); > > edge <- ((0.49 > source("psopts.r"); > postscript(file="linr.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"); > lines(lowess(grid[edge,])); > > 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; > > pred <- b[1] + b[2]*tx1 + b[3]*tx2; > dflt <- (pred > 0.5); > > dflt <- as.numeric(dflt); > > err <- abs(dflt-ty); > print(mean(err)); [1] 0.07854 > proc.time() [1] 2.44 0.09 2.53 0.00 0.00 >