Created
April 8, 2020 10:54
-
-
Save timcdlucas/acc7df24da656d8401f1c47882eb09d0 to your computer and use it in GitHub Desktop.
Does having a weird seed mess up neural networks
This file contains 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(dplyr) | |
set.seed(20200408) | |
diamonds <- diamonds %>% | |
select(carat, price, depth, table, x, y, z) %>% | |
scale | |
# Kinda dumb. I want reaosnable size datasets with no overlap | |
train_ii <- sample(nrow(diamonds), 1000) | |
test_ii <- sample(nrow(diamonds), 3000) | |
test_ii <- test_ii[!(test_ii %in% train_ii)] | |
train <- diamonds[train_ii, ] | |
test <- diamonds[test_ii, ] | |
test_y <- diamonds[, 'price'][test_ii] | |
mae <- rep(NA, 200) | |
for(i in 1:200){ | |
m <- nnet(price ~ depth + table + carat + x + y + z, data = train, size = 100, linout = TRUE) | |
preds <- predict(m, newdata = test) | |
mae[i] <- mean(abs(preds - test_y)) | |
} | |
set.seed(2631) | |
m <- nnet(price ~ depth + table + carat + x + y + z, data = train, size = 100, linout = TRUE) | |
preds <- predict(m, newdata = test) | |
mae_odd <- mean(abs(preds - test_y)) | |
hist(mae) | |
abline(v = mae_odd) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment