Considering a dataset with $p$ numerical attributes.
The goal of the autoencoder is to reduce the dimension of $p$ to $k$, such that these $k$ attributes are enough to recompose the original $p$ attributes.
# 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)
sw_size <- 5
ts <- ts_data(sin_data$y, sw_size)
ts_head(ts)
t4 | t3 | t2 | t1 | t0 |
---|---|---|---|---|
0.0000000 | 0.2474040 | 0.4794255 | 0.6816388 | 0.8414710 |
0.2474040 | 0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 |
0.4794255 | 0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 |
0.6816388 | 0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 |
0.8414710 | 0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 |
0.9489846 | 0.9974950 | 0.9839859 | 0.9092974 | 0.7780732 |
preproc <- ts_norm_gminmax()
preproc <- fit(preproc, ts)
ts <- transform(preproc, ts)
ts_head(ts)
t4 | t3 | t2 | t1 | t0 |
---|---|---|---|---|
0.5004502 | 0.6243512 | 0.7405486 | 0.8418178 | 0.9218625 |
0.6243512 | 0.7405486 | 0.8418178 | 0.9218625 | 0.9757058 |
0.7405486 | 0.8418178 | 0.9218625 | 0.9757058 | 1.0000000 |
0.8418178 | 0.9218625 | 0.9757058 | 1.0000000 | 0.9932346 |
0.9218625 | 0.9757058 | 1.0000000 | 0.9932346 | 0.9558303 |
0.9757058 | 1.0000000 | 0.9932346 | 0.9558303 | 0.8901126 |
samp <- ts_sample(ts, test_size = 10)
train <- as.data.frame(samp$train)
test <- as.data.frame(samp$test)
Reduce from 5 to 3 dimensions
auto <- autoenc_encode(5, 3)
auto <- fit(auto, train)
presenting the original test set and display encoding
print(head(test))
result <- transform(auto, test)
print(head(result))
t4 t3 t2 t1 t0 1 0.7258342 0.8294719 0.9126527 0.9702046 0.9985496 2 0.8294719 0.9126527 0.9702046 0.9985496 0.9959251 3 0.9126527 0.9702046 0.9985496 0.9959251 0.9624944 4 0.9702046 0.9985496 0.9959251 0.9624944 0.9003360 5 0.9985496 0.9959251 0.9624944 0.9003360 0.8133146 6 0.9959251 0.9624944 0.9003360 0.8133146 0.7068409 [,1] [,2] [,3] [1,] -1.659231 -0.5514435 0.47297540 [2,] -1.752244 -0.5687587 0.41909412 [3,] -1.797444 -0.5653516 0.34581864 [4,] -1.792005 -0.5414488 0.25749445 [5,] -1.736488 -0.4983090 0.16273342 [6,] -1.634345 -0.4386145 0.06742734