Skip to content

Instantly share code, notes, and snippets.

View MJacobs1985's full-sized avatar

Marc Jacobs MJacobs1985

View GitHub Profile
#Bayesian Regularization for Feed-Forward Neural Networks
training_comp<-training%>%na.omit()
neurons=2
p=length(names(training_comp))-1
n=dim(training_comp)[1]
npar=neurons*(1+1+p)+1
brnngrid<-initnw(neurons,p,n,npar)
brnn1 <- train(rochefant~. - consumer, data = training_comp,
method = "brnn",
trControl = tr)
training_comp<-training%>%na.omit()
enetgrid<-expand.grid(.lambda=c(0,0.01,.1),
.fraction = seq(0.5, 1 , length=20))
enet1 <- train(rochefant~.-customer, data = training_comp,
preProcess = c("center", "scale"),
method = "enet",
tuneGrid=enetgrid,
trControl = tr)
enet1;summary(enet1);plot(enet1)
enet1pred<-predict(enet1, testing)
stopCluster(cl)
registerDoSEQ()
cl <- makeCluster(8)
registerDoParallel(cl)
pm1 <- train(rochefant~. -customer, data = training,
preProcess = c("center", "scale"),
method = "glmnet",
trControl = tr,
na.action = na.omit)
arrange(pm1$results, RMSE) %>% head
set.seed(998)
cl <- makePSOCKcluster(4)
registerDoParallel(cl)
## Create Model Data
arcmodel<-arc%>%dplyr::select(slaughtermonth,
slaughteryear,
weightclasshalv,
length,
rochefant,
`nir-ala`,
ts.stl <- stl(arc_ts[, 'rochef'],"periodic")
ts.sa <- seasadj(ts.stl)
seasonplot(ts.sa, 12, col=rainbow(12))
# Look at stationairy
nsdiffs(arc_ts[, 'rochef']) # no differencing needed
plot(arc_ts[, 'rochef'])
arc_ts%>%feasts::autoplot()
par(mfrow = c(1, 2))
arc_ts[, c("rochef")] %>%
acf(lag.max = 24,
main = "Autocorrelation Plot - R")
arc_ts[, c("rochef")] %>%
pacf(lag.max = 24,
main = "Partial Autocorrelation Plot - R")
ts_lags(arc_ts,
lags = c(2, 5, 8, 10, 12, 24))
arc_ts <- ts(data = arc_month[, c("rochef", "nirastax", "nirfat", "nirtotpig")],
start = c(2005, 09), # start date
end = c(2017, 11), # end date
frequency = 12)
ts_plot(arc_ts) # nirtotpig and nirastax are the same
arc_ts <- ts(data = arc_month[, c("rochef", "weightwhole", "weightslaughter" )],
start = c(2005, 09), # start date
end = c(2017, 11), # end date
frequency = 12)
ts_plot(arc_ts) # Weight whole and weight slaughter are almost the same
plot(ts_seas(arc_ts))
plot(ts_prcomp(arc_ts))
arc_ts <- ts(data = arc_month[, c("rochef", "length", "weightslaughter" )],
start = c(2005, 09), # start date
end = c(2017, 11), # end date
frequency = 12)
ts_info(arc_ts)
ts_plot(arc_ts)
forecast::autoplot(arc_ts)+theme_bw()
rochef_ts <- ts(data = arc_month[, c("rochef")],
start = c(2005, 09), # start date
end = c(2017, 11), # end date
frequency = 12)
ts_heatmap(rochef_ts)
ts_cor(rochef_ts)
ts_lags(rochef_ts)
plot(ts_ma(rochef_ts))
ts_decompose(rochef_ts, type="both")
ts_surface(rochef_ts)