Created
January 12, 2016 13:01
-
-
Save szilard/8e56e784119da270bbb1 to your computer and use it in GitHub Desktop.
outliers impact on neural net classifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(nnet) | |
| library(h2o) | |
| h2o.init() | |
| set.seed(123) | |
| n <- 1000 | |
| x1 <- runif(n) | |
| x2 <- runif(n) | |
| z <- 30*(x2 - x1) | |
| p <- 1/(1+exp(-z)) | |
| y <- rbinom(n,1,p) | |
| x1t <- seq(0,1,1/20) | |
| x2t <- seq(0,1,1/20) | |
| dt <- expand.grid(x1=x1t,x2=x2t) | |
| dxt <- as.h2o(dt) | |
| par(pty="s") | |
| plot(x2 ~ x1, col = ifelse(y==0,"blue","red")) | |
| d <- data.frame(x1,x2,y) | |
| ## outliers ON/OFF: | |
| d <- rbind(d, data.frame(x1=1000,x2=0,y=1)) | |
| dx <- as.h2o(d) | |
| ## choose model glm/nnet/h2o.DL: | |
| #md <- glm(y~., d, family=binomial) | |
| #md <- nnet(y~., d, size = 10, decay = 0.1, maxit = 1000) | |
| md <- h2o.deeplearning(x=1:2, y=3, training_frame=dx, | |
| hidden = 10, activation = "Rectifier", epochs = 10) | |
| ## try with tanh, try with CV (auto early stopping) | |
| ## choose d/dx for R/h2o | |
| #yt <- matrix(predict(md, dt),21,21) | |
| yt <- matrix(h2o.predict(md, dxt),21,21) | |
| contour(x=x1t, y=x2t, z=yt, levels=0.5, add=TRUE, lwd=3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment