R : Copyright 2004, The R Foundation for Statistical Computing Version 2.0.0 (2004-10-04), ISBN 3-900051-07-0 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 and 'citation()' on how to cite R or R packages in publications. 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)) > source("mlp.r") > > trnx = as.matrix(read.table("a2trnx",head=F)) > tstx = as.matrix(read.table("a2tstx",head=F)) > > trny = scan("a2trny") Read 1708 items > tsty = scan("a2tsty") Read 2562 items > > # Try logistic regression. > > m = glm (trny ~ trnx, family = "binomial") > > print(summary(m)) Call: glm(formula = trny ~ trnx, family = "binomial") Deviance Residuals: Min 1Q Median 3Q Max -2.9128 -0.4880 0.2613 0.5866 2.9459 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) -3.05071 1.26836 -2.405 0.016161 * trnxV1 -0.97554 0.19350 -5.042 4.62e-07 *** trnxV2 -1.28711 0.23445 -5.490 4.02e-08 *** trnxV3 -0.01075 0.09407 -0.114 0.909025 trnxV4 0.42009 0.23313 1.802 0.071549 . trnxV5 0.26227 0.16644 1.576 0.115090 trnxV6 -0.04156 0.02763 -1.504 0.132585 trnxV7 0.57519 0.18703 3.075 0.002103 ** trnxV8 -3.54666 0.27940 -12.694 < 2e-16 *** trnxV9 0.06427 0.18545 0.347 0.728912 trnxV10 -0.19697 0.11305 -1.742 0.081440 . trnxV11 0.10247 0.09171 1.117 0.263825 trnxV12 0.07966 0.15494 0.514 0.607143 trnxV13 -0.20463 0.13087 -1.564 0.117907 trnxV14 -1.19928 0.27087 -4.427 9.53e-06 *** trnxV15 0.74670 0.20644 3.617 0.000298 *** trnxV16 5.60564 0.46877 11.958 < 2e-16 *** trnxV17 -0.31754 0.24613 -1.290 0.197010 trnxV18 -0.07661 0.28577 -0.268 0.788643 trnxV19 2.47395 0.29163 8.483 < 2e-16 *** trnxV20 -3.22532 0.30526 -10.566 < 2e-16 *** trnxV21 0.96260 0.36075 2.668 0.007623 ** trnxV22 0.86491 0.33945 2.548 0.010835 * trnxV23 1.75445 0.34105 5.144 2.69e-07 *** --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 2285.2 on 1707 degrees of freedom Residual deviance: 1320.6 on 1684 degrees of freedom AIC: 1368.6 Number of Fisher Scoring iterations: 5 > > p1.logistic = 1 / (1 + exp(-(coef(m)[1] + tstx %*% coef(m)[2:(ncol(tstx)+1)]))) > > cat("Error rate with logistic regression:\n"); Error rate with logistic regression: > print(mean(tsty != (p1.logistic>0.5))) [1] 0.1791569 > > val.set = 1:427 > est.set = 428:1708 > > postscript("ass2-plts.ps",horiz=T) > par(mfrow=c(2,4)) > > # Try MLP with varous learning rates. > > iters = + c ( 60000, 30000, 20000, 15000, 10000, 60000, 60000, 60000) > eta1 = + c (0.000012, 0.000025, 0.00005, 0.0001, 0.0002, 0.000012, 0.000012, 0.000020) > eta2 = + c (0.000012, 0.000025, 0.00005, 0.0001, 0.0002, 0.000020, 0.000030, 0.000012) > > for (i in 1:length(iters)) + { + set.seed(123) + + params = mlp.cv (trny, trnx, eta1[i], eta2[i], val.set, iters=iters[i], q=15, + cv.plot=T) + title(paste("eta1 =",eta1[i]," eta2 =",eta2[i])) + p1.mlp = mlp.predict(tstx,params) + cat("Error rate with mlp using eta1 =",eta1[i],"and eta2 =",eta2[i],":\n") + print(mean(tsty != (p1.mlp>0.5))) + } Error rate with mlp using eta1 = 1.2e-05 and eta2 = 1.2e-05 : [1] 0.1436378 Error rate with mlp using eta1 = 2.5e-05 and eta2 = 2.5e-05 : [1] 0.1436378 Error rate with mlp using eta1 = 5e-05 and eta2 = 5e-05 : [1] 0.1444184 Error rate with mlp using eta1 = 1e-04 and eta2 = 1e-04 : [1] 0.1506635 Error rate with mlp using eta1 = 2e-04 and eta2 = 2e-04 : [1] 0.1807182 Error rate with mlp using eta1 = 1.2e-05 and eta2 = 2e-05 : [1] 0.1405152 Error rate with mlp using eta1 = 1.2e-05 and eta2 = 3e-05 : [1] 0.1412959 Error rate with mlp using eta1 = 2e-05 and eta2 = 1.2e-05 : [1] 0.1451991 > proc.time() [1] 8309.61 29.31 9546.92 0.01 0.00 >