I’m happy to announce a new package that has recently appeared on CRAN, called “TSrepr” (version 1.0.0: https://CRAN.R-project.org/package=TSrepr).
The TSrepr package contains methods of time series representations (dimensionality reduction, feature extraction or preprocessing) and several other useful helper methods and functions.
Time series representation can be defined as follows:
Let \( x \) be a time series of length \( n \), then representation of \( x \) is a model \( \hat{x} \) with reduced dimensionality \( p \) \( (p __ n) \) such that \( \hat{x} \) approximates closely \( x \) (Esling and Agon (2012)).
Time series representations are used for:
significant reduction of the time series dimensionality
emphasis on fundamental (essential) shape characteristics
implicit noise handling
reducing the dimension will reduce memory requirements and computational complexity of consequent machine learning methods.
Therefore, they are awesome!
Time series representation methods can be divided into four groups (types) (Aghabozorgi, Seyed Shirkhorshidi, and Ying Wah (2015)):
nondata adaptive
data adaptive
model-based
data dictated (clipped data).
In nondata adaptive representations, the parameters of transformation remain the same for all time series, irrespective of their nature.
In data adaptive representations, the parameters of transformation vary depending on the available data.
An approach to the model-based representation relies on the assumption that the observed time series was created based on basic model. The aim is to find the parameters of such a model as a representation. Two time series are then considered as similar if they were created by the same set of parameters of a basic model.
In data dictated approaches, the compression ratio is defined automatically based on raw time series such as clipped (Aghabozorgi, Seyed Shirkhorshidi, and Ying Wah (2015)).
Most famous (well known) methods for nondata adaptive type of representations are PAA (Piecewise Aggregate Approximation), DWT (Discrete Wavelet Transform), DFT (Discrete Fourier Transform), DCT (Discrete Cosine Transform) or PIP (Perceptually Important Points). For data adaptive type of representations, it is SAX (Symbolic Aggregate approXimation), PLA (Piecewise Linear Approximation) and SVD (Singular Value Decomposition).
For model-based representations it is ARMA, mean profiles or estimated regression coefficients from a statistical model (e.g. linear model).
The data dictated is the less known type of representation and the most famous method of this type is clipping (bit-level) representation (Bagnall et al. (2006)).
Implemented methods and functions
In the TSrepr package, these time series representation methods are implemented (the function names are in brackets):
Nondata adaptive:
PAA - Piecewise Aggregate Approximation (repr_paa)
DWT - Discrete Wavelet Transform (repr_dwt)
DFT - Discrete Fourier Transform (repr_dft)
DCT - Discrete Cosine Transform (repr_dct)
SMA - Simple Moving Average (repr_sma)
PIP - Perceptually Important Points (repr_pip)
Data adaptive:
SAX - Symbolic Aggregate Approximation (repr_sax)
PLA - Piecewise Linear Approximation (repr_pla)
Model-based:
Mean seasonal profile - Average seasonal profile, Median seasonal profile, etc. (repr_seas_profile)
Model-based seasonal representations based on linear (additive) model (LM, RLM, L1, GAM) (repr_lm, repr_gam)
Exponential smoothing seasonal coefficients (repr_exp)
Data dictated:
FeaClip - Feature extraction from clipping representation (repr_feaclip, clipping)
FeaTrend - Feature extraction from trending representation (repr_featrend, trending)
FeaClipTrend - Feature extraction from clipping and trending representation (repr_feacliptrend)
Some additional useful functions are also implemented in the TSrepr package, such as:
Windowing (repr_windowing) - applies to the above mentioned representations to every window of a time series
Matrix of representations (repr_matrix) - applies to the above mentioned representations to every row of a matrix of time series
Normalisation functions - z-score (norm_z), min-max (norm_min_max)
Normalisation functions with output also of scaling parameters - z-score (norm_z_list), min-max (norm_min_max_list)
Denormalisation functions - z-score (denorm_z), min-max (denorm_min_max)
Forecasting accuracy measures - MAE, RMSE, MdAE, MAPE, sMAPE, MASE.
Usage of the TSrepr package
The TSrepr functions can be used very easily. The input is always a numeric vector (univariate time series) and additional arguments can occur in some methods.
Let’s load the package and ggplot2 for visualizations:
# install.packages(&quot;TSrepr&quot;)library(TSrepr)library(ggplot2)Let’s load electricity consumption data (elec_load) and use first time series from the dataset. There is 672 values, so 14 days of measurements.
data(&quot;elec_load&quot;)data_ts