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
| #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) |
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
| 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) |
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
| 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 |
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
| set.seed(998) | |
| cl <- makePSOCKcluster(4) | |
| registerDoParallel(cl) | |
| ## Create Model Data | |
| arcmodel<-arc%>%dplyr::select(slaughtermonth, | |
| slaughteryear, | |
| weightclasshalv, | |
| length, | |
| rochefant, | |
| `nir-ala`, |
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
| 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() |
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
| 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)) |
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
| 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 |
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
| 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)) |
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
| 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() |
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
| 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) |