# DAL ToolBox
# version 1.0.777
source("https://raw.githubusercontent.com/cefet-rj-dal/daltoolbox/main/jupyter.R")
#loading DAL
load_library("daltoolbox")
Loading required package: daltoolbox Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo Attaching package: ‘daltoolbox’ The following object is masked from ‘package:base’: transform
data(sin_data)
library(ggplot2)
plot_ts(x=sin_data$x, y=sin_data$y) + theme(text = element_text(size=16))
sw_size <- 10
ts <- ts_data(sin_data$y, sw_size)
ts_head(ts, 3)
t9 | t8 | t7 | t6 | t5 | t4 | t3 | t2 | t1 | t0 |
---|---|---|---|---|---|---|---|---|---|
0.0000000 | 0.2474040 | 0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 |
0.2474040 | 0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 | 0.5984721 |
0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 | 0.5984721 | 0.3816610 |
test_size <- 3
samp <- ts_sample(ts, test_size)
#first five rows from training data
ts_head(samp$train, 5)
t9 | t8 | t7 | t6 | t5 | t4 | t3 | t2 | t1 | t0 |
---|---|---|---|---|---|---|---|---|---|
0.0000000 | 0.2474040 | 0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 |
0.2474040 | 0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 | 0.5984721 |
0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 | 0.5984721 | 0.3816610 |
0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 | 0.5984721 | 0.3816610 | 0.1411200 |
0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 | 0.5984721 | 0.3816610 | 0.1411200 | -0.1081951 |
#last five rows from training data
ts_head(samp$train[-c(1:(nrow(samp$train)-5)),])
t9 | t8 | t7 | t6 | t5 | t4 | t3 | t2 | t1 | t0 |
---|---|---|---|---|---|---|---|---|---|
-0.27941550 | -0.03317922 | 0.2151200 | 0.4500441 | 0.6569866 | 0.8230809 | 0.9380000 | 0.9945988 | 0.9893582 | 0.9226042 |
-0.03317922 | 0.21511999 | 0.4500441 | 0.6569866 | 0.8230809 | 0.9380000 | 0.9945988 | 0.9893582 | 0.9226042 | 0.7984871 |
0.21511999 | 0.45004407 | 0.6569866 | 0.8230809 | 0.9380000 | 0.9945988 | 0.9893582 | 0.9226042 | 0.7984871 | 0.6247240 |
0.45004407 | 0.65698660 | 0.8230809 | 0.9380000 | 0.9945988 | 0.9893582 | 0.9226042 | 0.7984871 | 0.6247240 | 0.4121185 |
0.65698660 | 0.82308088 | 0.9380000 | 0.9945988 | 0.9893582 | 0.9226042 | 0.7984871 | 0.6247240 | 0.4121185 | 0.1738895 |
#testing data
ts_head(samp$test)
t9 | t8 | t7 | t6 | t5 | t4 | t3 | t2 | t1 | t0 |
---|---|---|---|---|---|---|---|---|---|
0.8230809 | 0.9380000 | 0.9945988 | 0.9893582 | 0.9226042 | 0.7984871 | 0.6247240 | 0.41211849 | 0.17388949 | -0.07515112 |
0.9380000 | 0.9945988 | 0.9893582 | 0.9226042 | 0.7984871 | 0.6247240 | 0.4121185 | 0.17388949 | -0.07515112 | -0.31951919 |
0.9945988 | 0.9893582 | 0.9226042 | 0.7984871 | 0.6247240 | 0.4121185 | 0.1738895 | -0.07515112 | -0.31951919 | -0.54402111 |