45
45
# ' @export calc.model
46
46
# '
47
47
# ' @examples
48
- # ' \dontrun {
48
+ # ' \donttest {
49
49
# ' # Create 48 different models (12 months x 4 classifiers) for every month in 2017
50
50
# ' calc.model(method = "monthly",
51
51
# ' timespan = c(2017),
@@ -98,7 +98,7 @@ calc.model <- function(
98
98
# Optional: activate for faster computing
99
99
if (doParallel == TRUE ){
100
100
# talk to the user
101
- print (" Starting parallelization." )
101
+ message (" Starting parallelization." )
102
102
103
103
cr <- parallel :: detectCores()
104
104
cl <- parallel :: makeCluster(cr * 0.75 )
@@ -122,14 +122,14 @@ calc.model <- function(
122
122
months <- unique(data_y $ month )
123
123
124
124
# talk to the user
125
- print (paste0(" Training models for " , y , " . Year-Nr.: " , which(timespan == y ), " /" , length(timespan )))
125
+ message (paste0(" Training models for " , y , " . Year-Nr.: " , which(timespan == y ), " /" , length(timespan )))
126
126
127
127
# Loop for monthly models ----------------------------------------- Month --- #
128
128
for (m in months ) try ({
129
129
data_m <- data_y [c(which(data_y $ month == m )), ]
130
130
131
131
# talk to the user
132
- print (paste0(" Training monthly models for " , y ," . Month-Nr.: " , m ))
132
+ message (paste0(" Training monthly models for " , y ," . Month-Nr.: " , m ))
133
133
134
134
# Loop for the climate sensors --------------------------------- Climresp --- #
135
135
for (s in climresp ) try({
@@ -146,7 +146,7 @@ calc.model <- function(
146
146
147
147
if (autocorrelation == " TRUE" ){
148
148
# talk to the user
149
- print (" Use autocorellation data for filtering.." )
149
+ message (" Use autocorellation data for filtering.." )
150
150
data <- data_m [stats :: complete.cases(data_m ), ]
151
151
delect <-
152
152
utils :: read.csv(
@@ -188,7 +188,7 @@ calc.model <- function(
188
188
spacevar = " plot"
189
189
)
190
190
# talk to the user
191
- print (
191
+ message (
192
192
paste0(
193
193
" Run with spatial folds for cross validation. Fold-Nr.: " ,
194
194
which(f == dofolds ), " /" , length(dofolds )
@@ -201,7 +201,7 @@ calc.model <- function(
201
201
timevar = " datetime"
202
202
)
203
203
# talk to the user
204
- print (
204
+ message (
205
205
paste0(
206
206
" Run with temporal folds for cross validation. Fold-Nr.: " ,
207
207
which(f == dofolds ), " /" , length(dofolds )
@@ -215,7 +215,7 @@ calc.model <- function(
215
215
spacevar = " plot"
216
216
)
217
217
# talk to the user
218
- print (
218
+ message (
219
219
paste0(
220
220
" Run with spatio-temporal folds for cross validation. Fold-Nr.: " ,
221
221
which(f == dofolds ), " /" , length(dofolds )
@@ -240,7 +240,7 @@ calc.model <- function(
240
240
resps <- trainingDat [ ,s ]
241
241
242
242
# talk to the user
243
- print (
243
+ message (
244
244
paste0(
245
245
" Calculate models for sensor: " ,
246
246
sensor_names [which(s == climresp )])
@@ -295,27 +295,27 @@ calc.model <- function(
295
295
savePredictions = TRUE )
296
296
modclass <- " gbm"
297
297
# talk to the user
298
- print (paste0(" Next model: Stochastic Gradient Boosting. " , i , " /" , length(classifier )))
298
+ message (paste0(" Next model: Stochastic Gradient Boosting. " , i , " /" , length(classifier )))
299
299
}
300
300
if (method == " lm" ){
301
301
tuneLength <- 10
302
302
modclass <- " lim"
303
303
# talk to the user
304
- print (paste0(" Next model: Linear Regression. " , i , " /" , length(classifier )))
304
+ message (paste0(" Next model: Linear Regression. " , i , " /" , length(classifier )))
305
305
}
306
306
if (method == " rf" ){
307
307
tuneLength <- 1
308
308
tuneGrid <- expand.grid(mtry = 2 )
309
309
modclass <- " raf"
310
310
# talk to the user
311
- print (paste0(" Next model: Random Forest. " , i , " /" , length(classifier )))
311
+ message (paste0(" Next model: Random Forest. " , i , " /" , length(classifier )))
312
312
}
313
313
if (method == " pls" ){
314
314
# preds <- data.frame(scale(preds))
315
315
tuneLength <- 10
316
316
modclass <- " pls"
317
317
# talk to the user
318
- print (paste0(" Next model: Partial-Least-Squares. " , i , " /" , length(classifier )))
318
+ message (paste0(" Next model: Partial-Least-Squares. " , i , " /" , length(classifier )))
319
319
}
320
320
if (method == " nnet" ){
321
321
tuneLength <- 1
@@ -324,11 +324,11 @@ calc.model <- function(
324
324
)
325
325
modclass <- " nnt"
326
326
# talk to the user
327
- print (paste0(" Next model: Neural Networks. " , i , " /" , length(classifier )))
327
+ message (paste0(" Next model: Neural Networks. " , i , " /" , length(classifier )))
328
328
}
329
329
330
330
# talk to the user
331
- print (" Computing model..." )
331
+ message (" Computing model..." )
332
332
333
333
# calculate model
334
334
ffsmodel <- CAST :: ffs(
@@ -405,7 +405,7 @@ calc.model <- function(
405
405
}) # end timespan loop [y]
406
406
407
407
# talk to the user
408
- print (" Done! Saving evaluation data frame." )
408
+ message (" Done! Saving evaluation data frame." )
409
409
410
410
# save total loop analytics for eval
411
411
saveRDS(df_total , file.path(envrmt $ path_statistics , paste0(mnote , " _mod_eval_df.rds" )));
@@ -414,7 +414,7 @@ calc.model <- function(
414
414
# stop paralellization, if it was activated
415
415
if (doParallel == TRUE ){
416
416
# talk to the user
417
- print (" Ending parallelization." )
417
+ message (" Ending parallelization." )
418
418
parallel :: stopCluster(cl )
419
419
}
420
420
0 commit comments