Full text
Information Fusion 95 (2023) 163–173 Available online 20 February 2023 1566-2535/© 2023 The Authors. Published by Elsevier B.V. This is an open access article under the CC BY-NC license (http://creativecommons.org/licenses/bync/4.0/). Contents lists available at ScienceDirect Information Fusion journal homepage: www.elsevier.com/locate/inffus Full length article A novel distributed forecasting method based on information fusion and incremental learning for streaming time series Laura Melgar-Garcíaa, David Gutiérrez-Avilésb, Cristina Rubio-Escuderob, Alicia Troncosoa,∗ aData Science & Big Data Lab, Universidad Pablo de Olavide, ES-41013, Seville, Spain bDepartment of Computer Science, University of Seville, Avda. Reina Mercedes s/n, Seville, 41012, Spain ARTICLE INFO Dataset link:https://www.omie.es Keywords: Real-time forecasting Incremental learning Streaming time series Electricity demand ABSTRACT Real-time algorithms have to adapt and adjust to new incoming patterns to provide timely and accurate responses. This paper presents a new distributed forecasting algorithm for streaming time series called StreamWNN. StreamWNN starts with an offline stage in which a forecasting model based on tuples of information fusion is created with historical data. In particular, this model consists of the fusion of patterns composed of past values of the time series with the future values of their k-nearest neighbors. Afterwards, streaming data starts to arrive. The model is incrementally updated in the online stage using a buffer with streaming data that more accurately matches the current model patterns. The model can be updated daily, monthly, quarterly or based on error thresholds. The methodology has been applied to Spanish electricity demand time series providing more accurate results when the model is updated incrementally. The best error results are obtained with the daily update of the model, resulting in an error between 2% and 3.5% depending on the prediction horizon. The model provides better error results than other algorithms. 1. Introduction Nowadays, researchers and companies are paying more and more attention to time series forecasting, due to the large number of existing applications based on time-indexed data. Moreover, as this data is mostly from electronic devices, the time series are usually very long and are measured in minutes or even seconds, resulting in big data time series. These characteristics open up a huge field of study in the big data paradigm with the aim of obtaining more accurate and efficient predictive models. Big data streaming is becoming one of the most widely used big data trends in recent years. Of the three ‘‘Vs’’ that define big data, namely variety, volume and velocity, the most important characteristic in this type of algorithm is velocity. Velocity refers to large continuous flows of data, called streams. Streams need to be processed and modeled in a special way considering specific requirements [1]. The real-time decision making process contributes to the challenge of developing safe and efficient smart cities with timely responses [2]. In addition to the condition of providing fast results when working in streaming mode, it is important to develop a model that must be always ready to give responses. However, streaming flows usually variate and suffer transformations which could lead to a non-accurate response if the model does not adapt to them [3]. For this reason, some streaming models include the option to update themselves taking into ∗Corresponding author. E-mail address: [email protected] (A. Troncoso). account the data arriving online in order to fit as best as possible to their new behavior. It is worth mentioning that even if the streaming model updates, it has to provide, as well, timely results. In this research, a new forecasting algorithm for time series in streaming named StreamWNN is proposed. The algorithm is made up of two phases: a batch phase and an online phase. In the batch phase, a model from historical data is created, and in the online phase the forecasts are made and the model is updated in real time. Therefore, the online phase fits the model to current streaming data. Both phases are based on the fusion of relevant information for the time series such as patterns and the classes of their k-nearest neighbors. The main innovation of StreamWNN compared to models in the literature is the use of a data structure that merges information of different nature. This information fusion from historical data allows both the real-time prediction and the online incremental learning to adapt the model to new incoming patterns in the streaming data. StreamWNN is applied to electrical energy consumption data in Spain from 2007 to 2016. The results show that the fusion of information related to patterns and their nearest neighbors is adequate to be able to incrementally update the model as well as to make predictions in a computationally efficient way. The rest of the article is structured as follows. Section 2presents a review of streaming time series forecasting algorithms. In Section 3 the whole methodology of the StreamWNN is introduced, including https://doi.org/10.1016/j.inffus.2023.02.023 Received 30 December 2022; Received in revised form 30 January 2023; Accepted 15 February 2023
Information Fusion 95 (2023) 163–173 164 L. Melgar-García et al. the incremental updating of the prediction model based on nearest neighbors. Section 4defines the time series used and includes the discussion of the forecasting and execution time results. The paper finishes with some final conclusions and ideas for future approaches in Section 5. 2. Related work Currently, all the topics related to streaming data are being widely investigated. The concept of streaming data is part of the big data environment and therefore, the challenges related to distributed computation, fault-tolerant computing paradigms, and architectures are still open. These technologies allow researchers to develop streaming data processing and analysis techniques to obtain accurate knowledge [4]. Concretely, understanding streaming events and their behavior is a critical task to accomplish [5]. Time series forecasting is crucial for streaming data analytics due to the large amount of existing massive time series data from different sources and its multiple applications. A wide variety of proposals for forecasting of data streams can be found in the literature. In [6], an Apache Spark framework based on the Lambda big data architecture was proposed. The authors implemented a vector auto-regression algorithm using that architecture to achieve better adaptability and efficiency of the model. The authors in [7] proposed a new method for time series forecasting based on a dynamic ensemble selection framework. This framework consisted of a set of baseline regressors trained offline and a set of meta learners that predicted the errors of the first ones. The proposal in [8] described a hybrid model that combined statistical learning methods such as ARIMA with machine learning models as the gradient descent optimization algorithm, obtaining promising results. The authors stated that the statistical and machine learning techniques, correctly combined, provide better error results than separately, since the hybrid system will have the adaptability characteristic of machine learning models and the accuracy of the statistical ones. The authors in [9] presented a methodology for time series data modeling and prediction. They proposed a double sliding window as a data-driven model and a combination of gene expression programming and a colony climbing metaheuristic. The benchmark results obtained better error results than the hierarchical temporal memory algorithm [10] used as a baseline. Time series forecasting has also various real-life applications, as in [11] where the authors presented an Android-based mobile application that predicts the physical activity of the user based on the steps taken and calorie consumption. Fusion of the data from variables of different sources or the fusion of different methods to improve the prediction is also a state-of-the- art strategy [12]. The authors in [13] presented a hybrid algorithm to predict both univariate and multivariate time series based on a fusion of clustering, classification models and a regressor that makes the final prediction. In [14] fusion methods are proposed for the aggregation of emergent patterns obtained by an evolutionary fuzzy system applied on each data stream. In [15] a Hoeffding adaptive tree is combined with an ensemble of C4.5 decision trees from massive data streams without increasing the time to obtain the model. In this context, statistical methods are also widely used. A comparative study of several well-known statistical methods such as Vector Autoregressive (VAR), Vector Moving Average (VMA), Vector Autoregressive Moving Average (VARMA), and Theta are compared with recurrent neural network models in [16]. Explainable models are trendy in the machine learning research field. Focusing on time series forecasting, a proposal of a linear regression-based forecasting method that explains the predictions through regression trees can be found in [17]. Pattern recognition is also a relevant topic in the streaming environment for a direct application such as anomaly and novelty detection and it is also the core of a comprehensive collection of streaming time series forecasting algorithms. In [18] the authors presented an online triclustering algorithm to detect three-dimensional behavior patterns from streams. The particularity of this proposal was the high dimensionality of the streams as they were formed by several variables indexed over time. This approach has been successfully applied to real problems such as precision agriculture [19], and the online analysis of cellular high-content screening images [20]. In addition, streaming data can variate and change its behavior patterns as time passes. It is crucial to have a streaming model that adapts to the new data flows. A wavelet-neural network with an error-updating scheme was proposed for meteorological predictions in streaming in [21]. The need for systematically updating the errors of data streams was shown. In order to reduce the computational cost of the optimization algorithm used in transductive support vector machine to deal with big data classification an incremental learning is proposed in [22]. Authors in [23] proposed an incremental update method based on Support Vector Machines (SVM) and Gated Recurrent Unit (GRU), considering concept drift for forecasting in real-time. Training models were updated based on the error between batch test results and real values. [24] proposed a novel incremental learning approach to identify individuals of interest from streaming face data. This approach fed with stream data, simultaneously predict and update classifiers, combining a deep features encoder with ensembles of SVM. Concept drift is also addressed through adaptive decision forest in [25]. The authors used three parallel forests to keep historical knowledge and the classification is made with the forest which achieves the best classification accuracy. In [26] an algorithm to enable incremental class learning in hierarchical classification was presented. In particular, a structure that grows horizontally and vertically in an online way when online data arrives is proposed, showing a better performance when comparing with other algorithms trained using offline data. In [27], the authors developed an incremental online multi-label classification method. This method is based on a weighted clustering model and the weights of the samples decrease to adapt to the change of data. Many literature approaches for model updating in the streaming environment are based on external algorithms such as the Kalman filters. Authors in [28] presented a coupled methodology of the k-nearest neighbor algorithm with a Kalman filter for real-time flood forecasting. The state transition matrix of the Kalman filter was recalculated using the forecasting method to improve the performance of the model and obtain accurate results. Another ensemble Kalman filter was used in [29]. The ensemble was used as a data assimilation algorithm to update water temperature forecasting considering sensor instances. The proposed algorithm is applied to electrical energy forecasting. This application field has been studied mainly in the batch or traditional time series forecasting mode. Several proposals have adapted nearest neighbor proposals to the big data paradigm using the Apache Spark distributed computation framework [30] for electricity demand forecasting. In the real-time environment, in [31] a new algorithm to predict energy demand time series in streaming was introduced. It used three different algorithms in streaming: k-means, nearest neighbors and naive Bayes. Deep learning models variants have been applied to the electric field, even in a real-time scenario [32]. In [33], the authors developed an innovative deep learning architecture for realtime forecasting of highly volatile and high-frequency electricity price time series. Furthermore, in [33] the authors proposed a multi-scale convolutional and long-short term hybrid neural network for shortterm electricity price prediction. In [34] a recurrent neural model to predict the electricity demand in Cambodia was presented. A postprocessing consisting of searching for correlated climate variables was carried out to improve the predictions. Finally, in [35] the authors developed a new streaming k-nearest neighbor algorithm for electricity demand in streaming. The algorithm was successfully tested using Spanish electricity demand data. A complete and updated review of the machine learning applications to electrical load forecasting was presented in [36].
Information Fusion 95 (2023) 163–173 165 L. Melgar-García et al. 3. Material and methods The StreamWNN methodology is based on a data structure fusing information related to the k-nearest neighbors, which is based on the idea that nearest data share similar properties or characteristics. The goal of this time series forecasting problem is to predict the next values considering past ones. The time series used are in 𝑁instances where the 𝑖th instance consists of 𝑥𝑖representing its 𝑤past features and 𝑦𝑖representing its ℎnext classes, i.e., next ℎvalues to predict: 𝑋𝑡= {(𝑥1, 𝑦1),…,(𝑥𝑁, 𝑦𝑁)} 𝑥𝑖∈R𝑤𝑦𝑖∈Rℎ(1) The dataset is divided into three chronologically ordered sets: 𝑠𝑒𝑡𝑛, 𝑠𝑒𝑡𝑝and 𝑠𝑒𝑡𝑠𝑡 referring to the set of the neighbors, set of the patterns and set of streaming data respectively. This division is as follows: The dataset is divided into 70/30, with 𝑠𝑒𝑡𝑠𝑡 being the 30%. In turn, 70% is subdivided into 70/30 generating the subsets 𝑠𝑒𝑡𝑛and 𝑠𝑒𝑡𝑝. The StreamWNN algorithm uses the offline–online learning approach to model data streams. The 𝑠𝑒𝑡𝑛and 𝑠𝑒𝑡𝑝sets are used to generate an initial model in the offline stage, and the 𝑠𝑒𝑡𝑠𝑡 set is used to simulate the arrival of data in real time in the online stage. In the first phase, the requirements for streaming models must not be met. However, in order to consider the StreamWNN as an algorithm that can work in real-time, all requirements for such algorithms must be fulfilled in the streaming or online phase. These requisites are described in [37]: only a limited set of past data can be stored; the model has to adapt to concept drift quickly and has to be always ready to make predictions; the model has to work in distributed computational environments so that its computation is fast. In this research work, an incremental learning approach during the online phase is presented. In this way, the algorithm is always up to date. The proposed algorithm is built on Apache Spark 2.3.4 and uses HDFS file system on Hadoop 2.7.7 and the Kappa Architecture on Apache Kafka 2.11 as streaming platform, i.e., a single pipeline is specifically designed for the job. Fig. 1 presents a scheme of the StreamWNN algorithm. First, the model 𝑀is initially generated from 𝑠𝑒𝑡𝑛and 𝑠𝑒𝑡𝑝historical data. Once the model 𝑀has been obtained, forecasts and errors can be computed as the 𝑥𝑠𝑡 streaming data arrive in real time. This prediction is based on the nearest neighbors of the 𝑥𝑚𝑖𝑛, where 𝑥𝑚𝑖𝑛 is the nearest neighbor to the 𝑥𝑠𝑡 streaming. If the stream 𝑥𝑠𝑡 is a closer neighbor to 𝑥𝑚𝑖𝑛 than the nearest neighbors of 𝑥𝑚𝑖𝑛 stored in the model 𝑀, the stream is stored in a buffer 𝐵in order to update the model 𝑀later using the neighbors from the buffer. The online phase of the StreamWNN finishes when there is no more incoming streaming data. The complete methodology of this algorithm is described in the following sections. Section 3.1 describes the offline phase, Section 3.2 the online phase and how forecasting is made in real time and the incremental learning of the algorithm is presented in Section 3.3. 3.1. Offline learning model The first task of the algorithm is to create an offline learning model in distributed batch processing. This model is the basis for the online phase where streaming data starts to arrive. The offline historical data is divided chronologically into 𝑠𝑒𝑡𝑛and 𝑠𝑒𝑡𝑝with around 70% and 30% of the data respectively. The batch model consists of the fusion of each feature instance of the 𝑠𝑒𝑡𝑝with its 𝐾closest instances of the 𝑠𝑒𝑡𝑛. Thus, the offline model 𝑀is represented by tuples of information as follows: 𝑀=⟨𝑥𝑖,⟨𝑦(𝑛1(𝑥𝑖)),…, 𝑦(𝑛𝐾(𝑥𝑖))⟩⟩ (2) where 𝑥𝑖are the features of the 𝑖th instance of the 𝑠𝑒𝑡𝑝and 𝑦(𝑛𝑗(𝑥𝑖)) are the classes of the instance of the 𝑠𝑒𝑡𝑛selected as the 𝑗th closest neighbor of 𝑥𝑖. The distance used to measure the nearness between the attributes in order to generate the model is the euclidean distance. This distance is represented as 𝑑(𝑥𝑖, 𝑥𝑗)where 𝑥𝑖refers to the features of the 𝑖th instance of the 𝑠𝑒𝑡𝑝and 𝑥𝑗to the features of the 𝑗th instance of the 𝑠𝑒𝑡𝑛. After the creation of the offline model, the next ℎare predicted. In the offline phase, predictions for each value 𝑙in the prediction horizon of length ℎare computed by: 𝑦𝑙=1 ∑𝐾 𝑗=1 𝛼𝑗 𝐾 ∑ 𝑗=1 𝛼𝑗𝑦(𝑛𝑗(𝑥𝑖))𝑙1≤𝑙≤ℎ(3) where 𝑦(𝑛𝑗(𝑥𝑖))𝑙is the class associated to the 𝑗th neighbor of the instance 𝑥𝑖for the 𝑙prediction horizon and 𝛼𝑗is the distance of 𝑑(𝑥𝑖, 𝑥𝑗) defined as: 𝛼𝑗=1 𝑑(𝑥𝑖, 𝑥𝑗)2(4) The error between predictions and actual data is computed to evaluate the performance of the offline model. In this research, the selected error metrics are the 𝑀𝐴𝑃 𝐸 Mean Absolute Percentage Error and the 𝑀𝐴𝐸 Mean Absolute Error. Errors 𝑀𝐴𝑃 𝐸𝑖and 𝑀𝐴𝐸𝑖are calculated for each 𝑖th instance predicted of the set of patterns. Finally, the offline phase gets 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 and 𝑀𝐴𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 that are the mean value of each error. These error metrics are defined as: 𝑀𝐴𝑃 𝐸𝑖=1 ℎ ℎ ∑ 𝑙=1 ||||| 𝑦𝑙−𝑦𝑙 𝑦𝑙||||| × 100 1 ≤𝑙≤ℎ(5) 𝑀𝐴𝐸𝑖=1 ℎ ℎ ∑ 𝑙=1 |𝑦𝑙−𝑦𝑙|1≤𝑙≤ℎ(6) where 𝑦𝑙is the 𝑙class of the 𝑖th instance and 𝑦𝑙corresponds to the offline prediction defined by Eq. (3). In brief, the offline model is generated from the Algorithm 1. Algorithm 1: Offline phase Result: Offline model 𝑀,𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒,𝑀𝐴𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 𝑤←Window of past features ℎ←Prediction horizon or next values to predict 𝐾←Number of neighbors to select distances ←[ ] M←[ ] for each 𝑥𝑖in 𝑠𝑒𝑡𝑝do for each 𝑥𝑗in 𝑠𝑒𝑡𝑛do distances ←add(distances, d(𝑥𝑖,𝑥𝑗)); end {𝑛1(𝑥𝑖), ..., 𝑛𝐾(𝑥𝑖)} ←K_smallest(distances, 𝐾) 𝑀←add(𝑀,< 𝑥𝑖,𝑦(𝑛𝑗(𝑥𝑖)) >) 𝑦𝑙←predict(𝑀,𝑥𝑖) 𝑀𝐴𝑃 𝐸𝑖←MAPE(𝑦𝑙,𝑦𝑙) 𝑀𝐴𝐸𝑖←MAE(𝑦𝑙,𝑦𝑙) end 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 ←𝑚𝑒𝑎𝑛(𝑀𝐴𝑃 𝐸𝑖) 𝑀𝐴𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 ←𝑚𝑒𝑎𝑛(𝑀𝐴𝐸𝑖) 3.2. Real-time forecasting The second phase of the StreamWNN algorithm is the online phase. This phase starts once the offline model from Eq. (2) is computed. This model is the base of the online phase. Streaming or online data is received in real-time and collected in groups of features (of length 𝑤), this data can be called 𝑥𝑠𝑡. For each 𝑥𝑠𝑡, the euclidean distances between it and all 𝑥𝑖features of the model 𝑀are calculated. The one with the minimum distance 𝑑𝑚𝑖𝑛 is selected as the nearest 𝑥𝑖, called 𝑥𝑚𝑖𝑛 from now on. Real-time forecasts are calculated when 𝑥𝑠𝑡 is associated with its nearest 𝑥𝑚𝑖𝑛. In this case, online predictions take into account not only
Information Fusion 95 (2023) 163–173 166 L. Melgar-García et al. Fig. 1. Flowchart of the StreamWNN methodology. the K nearest neighbors of 𝑥𝑚𝑖𝑛 but also 𝑥𝑚𝑖𝑛 itself as a neighbor for each value 𝑙to forecast in the prediction horizon of length ℎ: 𝑦𝑙=1 (∑𝐾 𝑗=1 𝛼𝑗) + 𝛼𝑚𝑖𝑛 ((𝐾 ∑ 𝑗=1 𝛼𝑗𝑦(𝑛𝑗(𝑥𝑚𝑖𝑛))𝑙)+𝛼𝑚𝑖𝑛𝑦(𝑥𝑚𝑖𝑛)𝑙)(7) where 𝛼𝑚𝑖𝑛 is represented as: 𝛼𝑚𝑖𝑛 =1 𝑑(𝑥𝑚𝑖𝑛, 𝑥𝑠𝑡)2(8) Thus, the prediction is made up of two clearly differentiated parts. Since the prediction must be obtained in real time, instead of calculating the neighbors of 𝑥𝑠𝑡, the neighbors of 𝑥𝑚𝑖𝑛 are used and Eq. (3) is applied leading to the first part of Eq. (7). The second part is due to the consideration of 𝑥𝑚𝑖𝑛 as a close neighbor of 𝑥𝑠𝑡 as well. Subsequently, the actual class of the online data 𝑥𝑠𝑡 arrives and the metric errors are calculated. This metrics use Eqs. (5) and (6) to obtain the 𝑀𝐴𝑃 𝐸𝑠𝑡 and 𝑀𝐴𝐸𝑠𝑡 for each 𝑖th instance of the set of streaming. Therefore, at the end of the online stage, the final 𝑀𝐴𝑃 𝐸𝑜𝑛𝑙𝑖𝑛𝑒 and 𝑀𝐴𝐸𝑜𝑛𝑙𝑖𝑛𝑒 errors can be calculated. These errors are the average of all 𝑀𝐴𝑃 𝐸𝑠𝑡 and 𝑀𝐴𝐸𝑠𝑡, respectively. Up to this stage, the offline or historical data of the model 𝑀is the only data that the real-time forecasting takes into account [35]. Section 3.3 presents the incremental learning approach of the StreamWNN. This innovative methodology focuses on obtaining more accurate predictions in real-time by updating the model with new streaming patterns. 3.3. Incremental learning The goal of online incremental learning is to keep the model up to date to prevent the model from aging and becoming unsuitable for realtime predictions. This step is very important as new streaming patterns may appear and need to be added to the model. The incremental learning is performed by updating the neighbors of 𝑥𝑚𝑖𝑛, i.e., 𝑛𝑗(𝑥𝑚𝑖𝑛)with 𝑗= 1,…, 𝐾. This is the reason why the model is said to be internally updated. The dimensions of the 𝑀model are conserved, however, the components are updated in real-time taking into account new incoming patterns. The update of neighbors uses a possible update buffer 𝐵. Let 𝑑𝑚𝑖𝑛 be the distance between 𝑥𝑠𝑡 and its nearest pattern 𝑥𝑚𝑖𝑛, and let 𝑑𝐾be the distance between 𝑥𝑚𝑖𝑛 and its farthest neighbor in the model 𝑛𝐾(𝑥𝑚𝑖𝑛). That is, 𝑑𝑚𝑖𝑛 =𝑑(𝑥𝑚𝑖𝑛, 𝑥𝑠𝑡)(9) 𝑑𝐾=𝑑(𝑥𝑚𝑖𝑛, 𝑛𝐾(𝑥𝑚𝑖𝑛)) (10) Real-time prediction is performed and 𝑑𝑚𝑖𝑛 and 𝑑𝐾are compared. In the case where 𝑑𝑚𝑖𝑛 is less than 𝑑𝐾, the actual 𝑥𝑠𝑡 is considered to be
Information Fusion 95 (2023) 163–173 167 L. Melgar-García et al. Fig. 2. Graphic representation of the neighbor updating process. a more accurate neighbor of the 𝑥𝑚𝑖𝑛 than its current neighbors in the model 𝑀. If it happens, 𝑥𝑠𝑡 is added to the possible update buffer with its corresponding 𝑥𝑚𝑖𝑛 as follows: 𝐵= {(𝑥𝑚𝑖𝑛, 𝑥𝑠𝑡, 𝑑𝑚𝑖𝑛)} (11) The buffer is filled as many times as necessary by adding instances meeting the condition 𝑑𝑚𝑖𝑛 < 𝑑𝐾for each instance 𝑥𝑠𝑡 in the 𝑠𝑒𝑡𝑠𝑡. To perform the model update there are five options to choose from: three based on time and two based on exceeding an error threshold. The update for the time-based options can be conducted on a daily, monthly or very three months basis. The threshold-base options can be performed when the error of the actual forecast is higher than a defined threshold. In this research, the 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 obtained when the offline model is computed is the first threshold-based incremental learning option. The second one is the 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 plus its standard deviation. When the so-called specific moment occurs, the 𝐾nearest instances of 𝑥𝑚𝑖𝑛 in the current model 𝑀are selected along with all the 𝑥𝑠𝑡 associated to 𝑥𝑚𝑖𝑛 in the buffer. Then, all neighbors both from the current model and from the buffer are sorted by distance and the 𝐾 smallest ones are kept. All neighbors selected are the updated neighbors of the 𝑥𝑚𝑖𝑛 in the model 𝑀. It is possible that all 𝐾neighbors of a 𝑥𝑚𝑖𝑛 are updated in the model with data streaming instances. The new equation presents an example of updating of the model when the parameter 𝐾, used to refer to the number of neighbors, is 𝐾 =3: 𝑀=⟨𝑥𝑚𝑖𝑛,⟨𝑦(𝑥𝑠𝑡1), 𝑦(𝑛1(𝑥𝑚𝑖𝑛)), 𝑦(𝑥𝑠𝑡2)⟩⟩ (12) In this example the nearest and farthest neighbors are updated with two streaming instances of the set of the streaming. The neighbor one of the offline model is still considered a good neighbor. Fig. 2 illustrates a graphical representation of the incremental learning approach of the StreamWNN, where 𝑛𝑗is the abbreviation of 𝑛𝑗(𝑥𝑖) and 𝑥𝑠𝑖is the abbreviation of 𝑥𝑠𝑡𝑖. The general online phase is represented in Algorithm 2including the neighbors updating described in Algorithm 3. Algorithm 2: Online phase including neighbor updating Result: updated M model, forecasts 𝑦𝑠𝑡 and 𝑀𝐴𝑃 𝐸𝑜𝑛𝑙𝑖𝑛𝑒 and 𝑀𝐴𝐸𝑜𝑛𝑙𝑖𝑛𝑒 errors of the 𝑠𝑒𝑡𝑠𝑡 𝑀←Offline model from Algorithm 1 distances ←[ ] for each 𝑥𝑠𝑡 that arrives do for each 𝑥𝑖in M do distances ←add(distances, d(𝑥𝑖,𝑥𝑠𝑡)) end 𝑥𝑚𝑖𝑛 ←K_smallest (distances, 1) 𝑑𝑚𝑖𝑛 ←d(𝑥𝑚𝑖𝑛,𝑥𝑠𝑡) 𝑦𝑠𝑡 ←predict (𝑀,𝑥𝑠𝑡) 𝑀𝐴𝑃 𝐸𝑠𝑡 ←MAPE(𝑦𝑠𝑡,𝑦𝑠𝑡) 𝑀𝐴𝐸𝑠𝑡 ←MAE(𝑦𝑠𝑡,𝑦𝑠𝑡) 𝑀←Update neighbors from Algorithm 3 end 𝑀𝐴𝑃 𝐸𝑜𝑛𝑙𝑖𝑛𝑒 ←mean(𝑀𝐴𝑃 𝐸𝑠𝑡) 𝑀𝐴𝐸𝑜𝑛𝑙𝑖𝑛𝑒 ←mean(𝑀𝐴𝐸𝑠𝑡) 4. Results and discussion The dataset used in this research work is a time series of the electrical energy consumption in megawatt (MW) in Spain. The time series has 497,832 samples measured every 10 min and preprocessed following the considerations in [35]. The time series starts in January 1st 2007 and ends in June 21st 2016. The first 70% of the dataset is used for the offline phase as historical data. The rest of the dataset is used for the online or streaming phase. The parameters values used in this experimentation are the optimal ones in [35] with the idea of comparing the results of the streaming
Information Fusion 95 (2023) 163–173 168 L. Melgar-García et al. Algorithm 3: Neighbor Updating Result: updated 𝑀model 𝑢𝑝𝑑𝑎𝑡𝑒𝑚𝑜𝑚𝑒𝑛𝑡 ←select(day, month, three-months, 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒, 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 +𝜎𝑀𝐴𝑃 𝐸𝑜𝑓 𝑓𝑙𝑖𝑛𝑒 ) 𝐵←[ ] distances𝑀∪𝐵←[ ] if 𝑑𝑚𝑖𝑛 <d(𝑥𝑚𝑖𝑛,𝑛𝐾(𝑥𝑚𝑖𝑛))then 𝐵←add(𝐵,< 𝑥𝑚𝑖𝑛,𝑥𝑠𝑡,𝑑𝑚𝑖𝑛)> if 𝑢𝑝𝑑𝑎𝑡𝑒𝑚𝑜𝑚𝑒𝑛𝑡 𝑎𝑛𝑑 𝐵 not empty then n(𝑥𝑚𝑖𝑛)←{𝑛1(𝑥𝑚𝑖𝑛), ..., 𝑛𝐾(𝑥𝑚𝑖𝑛)) 𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒𝑠𝑀∪𝐵←add(distances𝑀∪𝐵,d(𝑥𝑚𝑖𝑛,n(𝑥𝑚𝑖𝑛)) distances𝑀∪𝐵←add(distances𝑀∪𝐵,𝑑𝑚𝑖𝑛) new_n(𝑥𝑚𝑖𝑛)←K_smallest(distances𝑀∪𝐵,𝐾) n(𝑥𝑚𝑖𝑛)←new_n(𝑥𝑚𝑖𝑛) 𝑀←update(𝑀,< 𝑥𝑚𝑖𝑛, n(𝑥𝑚𝑖𝑛)>) end end model without updates and the results obtained from the incremental learning updates developed in this research: •For prediction horizon of 4 h (ℎ=24): 𝑤=144 and 𝐾=4. •For prediction horizon of 8 h (ℎ=48): 𝑤=288 and 𝐾=2. •For prediction horizon of 12 h (ℎ=72): 𝑤=576 and 𝐾=4. •For prediction horizon of 24 h (ℎ=144): 𝑤=864 and 𝐾=4. The experimentation is performed on the cluster of the Data Science and Big Data Laboratory in Pablo de Olavide University which is made up of 1 master node and 3 slaves. It has 4 Processor Intel(R) Core(TM) i7-5820K CPU with 48 cores and 120 GB of RAM memory. 4.1. Discussion of results Table 1 presents the errors for each prediction horizon after forecasting the streaming set for each type of update. The errors are reported with the following metrics: MAPE in percent, standard deviation of the MAPE in the column Std. dev. MAPE and the MAE in MW. The time-dependent update types are the daily, monthly and quarterly updates. The threshold-based updates are performed when the forecast error is larger than the MAPE obtained in the offline phase (𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒) and when the forecast error is larger than the offline MAPE plus its the standard deviation (𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 +𝜎𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 ). Considering the results in Table 1, the lowest MAPE and MAE errors are reached for the daily update at all the prediction horizons. The update using the 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 threshold also achieves very good results. Forecast errors when the model is not updated are larger than those obtained when any type of incremental learning update is performed on the model. The streaming forecasts become more accurate as more updates are performed on the online model. For example, the monthly update provides better MAPE results than the quarterly update, since the first one updates the model more and, therefore, the model adjusts more to the new incoming data. Similarly, results are more accurate for the 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 threshold than the 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 +𝜎𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 threshold, as the latter threshold is more difficult to reach and thus the model is updated fewer times. The worst forecasts do not improve when the model is updated. For each prediction horizon, the worst forecasts coincide in date and time and provide the same MAPE value regardless of whether the model is updated or not, except for ℎ=144. The worst prediction for ℎ=24 is August 16th 2015 from 8:00 AM to 11:50 AM with a MAPE of 33.00%. For ℎ=48 it is August 16th 2014 from 8:00 AM to 15:50 PM with a MAPE of 31.27%. For ℎ=72 it is December 25th 2013 from 00:00 AM to 11:50 AM with a MAPE of 24.39%. The worst predicted day with ℎ =144 with no update is the whole December 25th 2014 with 29.33% Table 1 Error metrics for each update and prediction horizon. Update type MAPE (%) Std. dev. MAPE MAE (MW) No update 2.43 2.07 670.13 Daily 2.19 2.01 605.71 Monthly 2.25 2.03 620.54 Quarterly 2.27 2.03 626.02 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 2.20 2.01 606.14 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 +𝜎𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 2.21 2.01 607.89 (a) Errors for ℎ=24 Update type MAPE (%) Std. dev. MAPE MAE (MW) No update 2.76 2.08 766.86 Daily 2.55 2.09 706.01 Monthly 2.59 2.09 719.23 Quarterly 2.61 2.10 724.44 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 2.55 2.09 706.92 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 +𝜎𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 2.57 2.09 710.85 (b) Errors for ℎ=48 Update type MAPE (%) Std. dev. MAPE MAE (MW) No update 3.35 2.82 933.99 Daily 3.13 2.81 872.13 Monthly 3.18 2.83 883.64 Quarterly 3.19 2.83 887.83 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 3.14 2.80 872.32 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 +𝜎𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 3.15 2.80 876.37 (c) Errors for ℎ=72 Update type MAPE (%) Std. dev. MAPE MAE (MW) No update 3.85 3.61 1072.83 Daily 3.57 3.53 998.06 Monthly 3.63 3.57 1011.77 Quarterly 3.65 3.56 1018.87 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 3.59 3.53 1001.66 𝑀𝐴𝑃 𝐸𝑜𝑓𝑓 𝑙𝑖𝑛𝑒 +𝜎𝑀𝐴𝑃 𝐸𝑜𝑓𝑓𝑙𝑖𝑛𝑒 3.62 3.52 1011.91 (d) Errors for ℎ=144 as MAPE and the December 25th 2013 with a MAPE of 27.02% for all different streaming updates. The daily MAPE when the model is updated every day for each prediction horizon is shown in Fig. 3. The smallest error is achieved when the prediction horizon is 24 (Fig. 3(a)). In this case, the maximum MAPE is 10.16% and occurs on August 16th 2015, i.e. the day when the worst prediction is obtained for the next 4 h. For the rest of the prediction horizons, the highest MAPE is also reached on the day with the worst forecast for the next 4 h. The MAPE value of the best forecasts decreases when any type of update is performed on the model. The error MAPE metrics for the best predictions of the model without update are 0.25%, 0.41%, 0.60% and 0.65% for ℎ=24, ℎ=48, ℎ=72 and ℎ=144, respectively. The best predictions achieved for each prediction horizon are represented in Fig. 4. For ℎ=24 the best prediction is obtained with the daily update providing a MAPE of 0.22%. This evolution throughout the day is in Fig. 4(a). For ℎ=48 the best MAPE is reached for the daily, monthly and the two threshold-dependent types of update. The MAPE is 0.32% and it is illustrated in Fig. 4(b). For ℎ=72, the best prediction has a MAPE of 0.45% and is achieved for the daily and for both of the two threshold updates. It is depicted in Fig. 4(c). The best forecast for ℎ= 144 is in Fig. 4(d). It is obtained only with the daily update and has a MAPE of 0.63%. The incremental learning approach implemented in the StreamWNN offers the possibility to add new patterns from streaming data to the model. This innovative k-nearest neighbor based technique improves online predictions. Fig. 5 illustrates the evolution of the average euclidean distance between model neighbors as iterations pass for ℎ= 144. The representations of the mean distance between neighbors and the number of iterations follow the same distribution for the remaining prediction horizons. When this incremental learning technique is not
Information Fusion 95 (2023) 163–173 169 L. Melgar-García et al. Fig. 3. Daily MAPE for each ℎprediction horizon. Fig. 4. Days with the best forecasts for each ℎprediction horizon.
Information Fusion 95 (2023) 163–173 170 L. Melgar-García et al. Fig. 5. Evolution of mean euclidean distance between neighbors in the model for ℎ=144. performed, i.e., no model update is conducted, this distance remains the same for all the iterations. However, when the incremental learning update is performed this distance decreases. The evolution of temporal updating methods is illustrated in Fig. 5(a) showing a reduction of this average distance in a stepwise fashion. The evolution of update methods based on error thresholds is depicted in Fig. 5(b). The two update methods that achieve the lowest average distances and the lowest MAPE errors are the daily and the MAPE update, represented in Fig. 5(c). Streaming algorithms must always be ready to make predictions. These predictions have to be computed as fast as possible in order to provide near real-time results during the online phase. Fig. 6 illustrates the evolution of the execution time needed to predict the whole streaming set using the daily update. This evolution is presented for
Information Fusion 95 (2023) 163–173 171 L. Melgar-García et al. Fig. 6. Execution time versus number of iterations for daily neighbor updating in the online phase. each prediction horizon. The number of iterations each horizon has to perform to predict the online set is different since the values of 𝑤and ℎare different for each of them. The execution time increases linearly with iterations for all prediction horizons, demonstrating the scalability of the algorithm. The shorter the prediction horizon, the higher the scalability, i.e., the represented line has a smaller slope. The evolution of the execution time versus iterations is similar for the rest of the update types. More specifically, the average time to compute the online prediction of h values for the daily update method is approximately: 8.37 s for ℎ=144, 5.46 s for ℎ=72, 3.25 s for ℎ=48 and 2.72 s for ℎ=24. Therefore, one value of the prediction horizon ℎ=48 takes approximately 0.06 s to be predicted. Furthermore, although in the offline phase there are no execution time restrictions, the computation times to generate the offline model for each prediction horizon, that is, the computation of the nearest neighbors mainly, are the following: 122.50 s for ℎ=144, 153.47 s for ℎ=72, 167.16 s for ℎ=48 and 222.09 s for ℎ=24. 4.2. Comparison with other methods In this Section, the best error result obtained by the proposed algorithm is compared with other studies that used the same dataset [13, 31,38]. The works in [13,38] are not data streaming algorithms, but traditional machine learning algorithms. However, they are used in order to obtain a comparison of the accuracy of the forecasts obtained by the proposed method. All these benchmark algorithms were trained using the data that the streaming method proposed in this work used in the offline stage. The algorithms were evaluated using the streaming set of this work as the test set. In [13], the authors presented a hybrid model for time series forecasting based on a combination of clustering, classification and forecasting techniques. The k-means algorithm with the optimal number of clusters (k =7) and different prediction and classification methods were used. In particular, classifiers such as a basic classifier based on the distance to the nearest centroid, SVM and Naive Bayes were tested, and the prediction methods evaluated were different ARIMA models, different Holt–Winter models and a deep Long Short-Term Memory (LSTM) recurrent neural network. Table 2 presents the MAPE obtained for each prediction and classification method used in the hybrid model published in [13] and for the StreamWNN proposed algorithm updating the model on a daily basis when predicting the streaming set for the 24-value forecast horizon, i.e., 4-hour forecast (ℎ= 4). It can be observed that the StreamWNN algorithm obtains a much more accurate error than that of the other methods. Table 2 MAPE obtained by the proposed method using daily updating and the methods published in [13]. Algorithm MAPE (%) Classifier Update Basic Naive Bayes SVM Random Daily ARIMA(3,0,1) 4.60 4.60 4.50 5.90 – ARIMA(5,0,1) 4.30 4.10 4.00 5.80 – ARIMA(7,0,1) 4.70 4.80 4.75 5.80 – ARIMA combinations 4.10 4.20 4.00 6.00 – LSTM 3.00 3.00 3.20 4.50 – StreamWNN – – – – 2.19 Table 3 MAPE obtained by the proposed method using daily updating and the methods published in [38]. Algorithm MAPE (%) NDL 1.51 FFNN 2.32 DT 8.86 GMB 4.49 StreamWNN +daily updating 2.19 In summary, our StreamWNN method provides better MAPE error results comparing with traditional machine learning algorithms. Although it works with additional requirements as forecasts must be made as soon as new data arrives and in the shortest possible time. None of the cited articles included information on execution time. The benchmark study introduced in [38] included different prediction methods applied to the same time series dataset as this work. In particular, NDL, FFNN, DT and GBM methods were evaluated. The NDL is a deep learning neural network which used a genetic algorithm to find the sub-optimal hyper-parameters of the network, FFNN is a feedforward neural network, DT a decision tree algorithm and GBM an algorithm based on gradient boosting. Table 3 presents the MAPE obtained by the NDL, FFNN, DT, GBM methods and the StreamWNN proposed forecasting method to predict next 4 h from the previous 24 h, i.e. 144 values (𝑤= 144). It can be seen that the StreamWNN method is more accurate in terms of MAPE error compared to most of the approaches. However, it is not better than the NDL model. Authors state that the computational time required is high while the aim of StreamWNN is to forecast in real-time. A forecasting algorithm for streaming time series, named StreamNSP was presented and compared with benchmark forecasting algorithms for data streams such as the FIMTDD, AdaGrad and AMRulesReg in [31]. StreamNSP combines clustering with a classifier and the nearest neighbor algorithm. The FIMTDD algorithm, which stands for Fast Incremental Model Trees with Drift Detection, models data streams using regression tree. The algorithm detects drift changes in incoming data and adapts the model incrementally. The AdaGrad performs an online gradient-based learning. The model adapts dynamically by adding geometry information from the previous data. The AMRules, i.e., Adaptive Model Rules, is an incremental model for learning rules in streaming for regression problems. Each rule contains a linear model and is trained with incremental gradient descent. The update is performed using a delta rule. It detects online changes using a Page–Hinkley test. Table 4 shows the MAPE obtained by the FIMTDD, AdaGrad, AM- RulesReg, StreamNSP and the StreamWNN when predicting the streaming set for a prediction horizon of 24 values. It is important to consider that MAPE errors are the average of the results for a prediction horizon of 1 value up to a prediction horizon of 24 values. The result for the StreamNSP is the one corresponding to the 24-value prediction horizon. Authors do not mention execution times even though it is a real-time algorithm.