# DAL ToolBox # version 1.0.777 source("https://raw.githubusercontent.com/cefet-rj-dal/daltoolbox/main/jupyter.R") #loading DAL Toolbox load_library("daltoolbox") #load required library library(ggplot2) i <- seq(0, 25, 0.25) x <- cos(i) plot_ts(x=i, y=x) + theme(text = element_text(size=16)) sw_size <- 10 ts <- ts_data(x, sw_size) ts_head(ts, 3) test_size <- 1 samp <- ts_sample(ts, test_size) ts_head(samp$train, 3) ts_head(samp$test) # Setup for tunning using ELM tune <- ts_tune(input_size=c(3:5), base_model = ts_elm(ts_norm_gminmax())) ranges <- list(nhid = 1:5, actfun=c('sig', 'radbas', 'tribas', 'relu', 'purelin')) # tune <- ts_tune(input_size=c(3:5), base_model = ts_lstm(ts_norm_gminmax())) # ranges <- list(input_size = 1:10, epochs=10000) io_train <- ts_projection(samp$train) # Generic model tunning model <- fit(tune, x=io_train$input, y=io_train$output, ranges) adjust <- predict(model, io_train$input) ev_adjust <- evaluate(model, io_train$output, adjust) print(head(ev_adjust$metrics)) steps_ahead <- 1 io_test <- ts_projection(samp$test) prediction <- predict(model, x=io_test$input, steps_ahead=steps_ahead) prediction <- as.vector(prediction) output <- as.vector(io_test$output) if (steps_ahead > 1) output <- output[1:steps_ahead] print(sprintf("%.2f, %.2f", output, prediction)) ev_test <- evaluate(model, output, prediction) print(head(ev_test$metrics)) print(sprintf("smape: %.2f", 100*ev_test$metrics$smape)) yvalues <- c(io_train$output, io_test$output) plot_ts_pred(y=yvalues, yadj=adjust, ypre=prediction) + theme(text = element_text(size=16)) ### Ranges for ELM ranges_elm <- list(nhid = 1:20, actfun=c('sig', 'radbas', 'tribas', 'relu', 'purelin')) ### Ranges for MLP ranges_mlp <- list(size = 1:10, decay = seq(0, 1, 1/9), maxit=10000) ### Ranges for RF ranges_rf <- list(nodesize=1:10, ntree=1:10) ### Ranges for SVM ranges_svm <- list(kernel=c("radial", "poly", "linear", "sigmoid"), epsilon=seq(0, 1, 0.1), cost=seq(20, 100, 20)) ### Ranges for LSTM ranges_lstm <- list(input_size = 1:10, epochs=10000) ### Ranges for CNN ranges_cnn <- list(input_size = 1:10, epochs=10000)