# Forecasting Algorithm Adaptive Automatically to Time Series Length

Kolyo Onkov, Georgios Tegos

► To cite this version:

Kolyo Onkov, Georgios Tegos. Forecasting Algorithm Adaptive Automatically to Time Series Length. 10th IFIP International Conference on Artificial Intelligence Applications and Innovations (AIAI), Sep 2014, Rhodes, Greece. pp.537-545, 10.1007/978-3-662-44654-6_53 . hal-01391356

HAL Id: hal-01391356

https://inria.hal.science/hal-01391356

Submitted on 3 Nov 2016

**HAL** is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Forecasting algorithm adaptive automatically to time series length

Kolyo Onkov¹, Georgios Tegos²

¹Department of Mathematics, Computer Science and Physics, Agricultural University, 12 Mendeleev, 4000 Plovdiv, Bulgaria,
kolonk@au-plovdiv.bg

²Department of Information Technology, Alexander Technological Educational Institute of Thessaloniki, P.O. Box 14561, 54101, Greece,
gtegos@gen.teithe.gr

**Abstract.** The developed forecasting algorithm creates trend models based on varying length time series by eliminating its oldest member. The constructed criterion evaluates the attained models through estimating the ratio between the average of the stochastic errors for the forecasted period and the average of real values. The best model and forecasting are automatically achieved in contrast to statistical software systems SPSS, STATISTICA, etc. where this process is accomplished progressively by the user. Therefore, this forecasting algorithm is adaptive to the length of time series. Component oriented approach has been used for software implementation. Simulation experiments have been carried out to test the forecasting algorithm using the multidimensional time series database on fishery in Greece. This algorithm is more efficient in case forecasting is applied on large number of time series because it saves time and efforts.

**Keywords:** varying length time series, automatic model fitting, criterion, adaptive algorithm

## 1 INTRODUCTION

Time series forecasting refers to the process of identifying past relationships and trends in historical data for predicting future values [1]. Forecasting is important in time series analysis because it plays a central role in management since it precedes decision making [2]. There are many time series analysis techniques related to forecasting [3]. Trend modelling can be used for forecasting if it is assumed that the studied event will follow the same rules during the historical and the forecasted period. The attained forecasts are a simple consequence of the trend extrapolation. The advantages of forecasts based on trend modelling compared to other forecasting methods are: a) the preliminary evaluation of the forecast stochastic error by trend models and b) the determination of the confidence intervals. As a result, the critical limits, on which the real values of the studied event fluctuate during the forecasted period, can be evaluated.
While modeling the trend of time series for forecasting purposes, the issue concerning the length of the period, within which the trends will be studied, frequently arises. Here there are two tendencies opposing each other. The stochastic error of the forecast decreases in longer historical periods. However, by covering a longer historical period, there is a risk for the model to include the influence of factors that used to function in the past, but later disappeared.

Forecasting time series based on trend modeling is often implemented through using statistical packages such as SPSS, Statistica etc. However, for reapplying trend modeling to different length time series and achieving new forecasted values the same procedure is followed manually. In general, in case of forecasting based on large numbers of time series, automatic forecasting is more efficient [2], [4]. Two automatic forecasting time series algorithms based on state space and ARIMA models have been implemented as R packages for statistical computing [5]. Fuzzy time series models and automatic forecasting techniques are developed to improve forecasting accuracy [6], [7].

This work aims to present an adaptive to time series length algorithm in order to achieve the best models and forecasted values automatically. The idea is to reapply forecasting by decreasing time series length and testing different trend models. As a result, different forecasts are achieved giving the opportunity to choose the most proper one based on objective criterions.

## 2 MATERIALS AND METHODS

The algorithm is based on the gradual elimination of data from the start of the historical time series by applying the same trend model to each resultant time series. The confidence intervals are evaluated according to the different types of trend models on the grounds of which the forecast is achieved.

Let's denote:

$y_i$ ($i=1, 2, ..., n$) – time series with length $n$,

$\hat{y}_{n+j}$ – forecasted values, $j = 1, 2, ..., L$, L – length of the forecasted period

$$S_y = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2}$$ – standard error, I

$\hat{y}_i$ ($i=1, 2, ..., n$) – smoothed values by the model

The linear $y = A_0 + A_1 t$ and the polynomial second degree $y = A_0 + A_1 t + A_2 t^2$ trend models are applied to varying length time series. The stochastic error of the forecasted value $\hat{y}_{n+j}$ for linear (equation II) and for polynomial second degree (equation III) model is [8]:
$$e^{\hat{y}_{n+j}} = \frac{S_y}{\sqrt{n-1}} \cdot \sqrt{1 + \frac{1}{n} + \frac{3(n+2j-1)^2}{n(n^2-1)}} \qquad \text{II}$$

$$e^{\hat{y}_{n+j}} = \frac{S_y}{\sqrt{n-1}} \cdot \sqrt{1 + \frac{1}{\sum_{p=1}^{j} t_p^2} \cdot t_{n+j}^2 + \frac{\sum_{p=1}^{j} t_p^4 - (2\sum_{p=1}^{j} t_p^2)t_{n+j}^2 + n \cdot t_{n+j}^4}{n \sum_{p=1}^{j} t_p^4 - (\sum_{p=1}^{j} t_p^2)^2}} \qquad \text{III}$$

where $S_y$ is the standard error by equation I.

The confidence interval for the linear and polynomial second degree models is evaluated as follows:

$$\hat{y}_{n+j} - t_{[1-\alpha]} e^{\hat{y}_{n+j}} \le \tilde{y}_{n+j} \le \hat{y}_{n+j} + t_{[1-\alpha]} e^{\hat{y}_{n+j}} \qquad \text{IV}$$

$\tilde{y}_{n+j}$ – the attained value of y for the jth year of the forecasted period;

$t_{[1-\alpha]}$ – Student's test at a level of significance $\alpha$ and n-2 degrees of freedom.

From equations II and III it is noticed that the value of the stochastic error depends directly on the length of time series n to which the trend model is applied and on the length of the forecasted period j. When n increases the value of stochastic error decreases while when j increases the stochastic error also does. Stated in other words, the greater the historical period is, the smaller the stochastic error becomes and on the other hand, the longer the forecasted period is, the greater the stochastic error becomes.

A criterion is created in order to evaluate the forecasts attained from time series with different length. The criterion is related to the stochastic error (equation II and III). During the elimination of data of time series by decreasing each time the value of n by 1, the ratio between the average of the stochastic errors for the forecasted period and the average of real values are computed according to the next equation:

$$C_1(d) = \left( \frac{1}{L} \sum_{j=1}^{L} e^{\hat{y}_{d+j}} \right) / \left( \frac{1}{n} \sum_{i=1}^{n} y_i \right), \quad d=n, n-1, \dots, m \qquad \text{V}$$

m is the minimal value of time series length, ($m < n$). The best trend model and forecasting are achieved for the minimal value of $C_1(d)$ criterion when varying the length time series.

The created forecasting algorithm, based on trend models applied to varying length time series, is presented here for one time series by the following steps:
1. Implement steps 2-6 for both trend models;

2. Procedure for trend modeling;

3. Procedure for trend model adequacy by F-test. If the model is adequate then go to step 4 else go to step 6;

4. Computation of smoothed values Ŷᵢ, i=1, 2, ...n and Standard error Sᵢ;

5. Procedure for estimation and storing of:

• Forecasted values ŷₙ₁, ŷₙ₂, ..., ŷₙₐ;

• Stochastic errors eᵢₙ₁, eᵢₙ₂, ..., eᵢₙₐ;

• Confidence intervals by equation IV applying Student's test;

• C₁(n) value.

6. Next operation;

7. n=n-1;

8. If n < m then go to step 10 else go to step 9;

9. Elimination of the most distant year from time series and go to step 1;

10. Application of the criterion for the best forecasting – MIN (C₁(n), C₁(n-1), ..., C₁(m)) for both trend models;

11. Evaluation and printing the best forecasting results based on both trend models.

The algorithm is adaptive to time series length and as a result it gives the ability to
achieve automatically forecasts based on trend modelling. The perspective of this
algorithm is to apply different weights on the time series members used for trend
modeling. The study of this approach will reveal abilities for attaining more precise
forecasting values.

3 RESULTS AND DISCUSSION

3.1 Software and simulation experiment

Component oriented approach and VB programming language have been used for
software implementation according to the algorithm. The procedures are placed in
two modules:

* The first of them is consisted of procedures for estimating the descriptive statistics (mean value, standard deviation, standard error etc) as well as for evaluating the F-test and Student test;

* The second one contains the procedures for trend modelling, managing the length of time series, stochastic error, confidence intervals, application of the criterion and presentation of the results.

Generally, the procedures in the second module, “call” the procedures from the
first one. VB programming code is also created for managing Excel-sheets which are
proper for storing tables containing automatically accessed theoretical values of F-test
and Student test by the trend modelling and forecasting and forecasting results as well.

A simulation experiment has been carried out to test the forecasting software using multidimensional time series database on sea fishery in Greece. Data in database concerns quantities and values of fish catch by areas, fish species, fishing tools and category as well as months, kinds of fishery and employment for the period 1990-2011 [9], [10]. Each time series extracted from FTS database consists of 22 members. For the purpose of forecasting it is divided into two parts: the first twenty members are used as historical time series and the last two (2010, 2011) are compared with the obtained forecasted values for the same years (proportion 20:2).

## 3.2 Forecasting results

The forecasting results presented here are oriented to time series on catch quantity of 71 sea fish species statistically registered in Greece. Table1 presents the part of the obtained results concerning only 10 fish species. Generally, for forecasting purposes the optimal time series length on the particular fish species is different. Besides the type of trend model used for the forecasts is also different. From 71 fish species there are 6 without adequate trend because of big random factor and as a result no forecasts are proposed by the algorithm. Almost all these cases concern fish species with small amount of catches – mean value for the studied period of time do not exceed 200 metric tons (Sprat, Skipjack etc).

<table><caption>Table1. Trend model and optimal length time series</caption><thead><tr><td>Fish code</td><td>Fish name</td><td>Trend model</td><td>Optimal length time series</td></tr></thead><tbody><tr><td>15</td><td>Bogue</td><td>Linear</td><td>12</td></tr><tr><td>23</td><td>Goatfish</td><td>Polynomial 2 degree</td><td>17</td></tr><tr><td>25</td><td>Red bream</td><td>Polynomial 2 degree</td><td>10</td></tr><tr><td>31</td><td>Red mullet</td><td>Linear</td><td>12</td></tr><tr><td>35</td><td>Bonito</td><td>Polynomial 2 degree</td><td>15</td></tr><tr><td>36</td><td>Sprat</td><td>No adequate model</td><td>-</td></tr><tr><td>41</td><td>Skipjack</td><td>No adequate model</td><td>-</td></tr><tr><td>43</td><td>Goldline</td><td>Linear</td><td>13</td></tr><tr><td>55</td><td>Tune fish</td><td>Linear</td><td>16</td></tr><tr><td>68</td><td>Cuttle fish</td><td>Polynomial 2 degree</td><td>18</td></tr></tbody></table>

Table 2 presents more detailed results of the forecasting algorithm applied on quantity of catch for fish species “Bogue”, based on linear trend modeling. For each varying length historical time series (n = 15, 14, 13, 12, 11) the forecasted values for the years 2010 and 2011 as well as the confidence interval (equation IV) and the C1 criterion (equation V) are also presented. The relative error shows the percentage
deviation between real and forecasted values. The best forecast is obtained for time series length 12 when C1 criterion has the minimum value (Figure1). The obtained relative error values are considered satisfactory – 10.87% and 2.47% for the years 2010 and 2011 respectively.

<table><caption>**Table2.** Forecasting results for fish species Bogue by automatic application of linear trend model to varying length time series</caption><thead><tr><th>Time series length</th><th>Year</th><th>Forecasted values</th><th colspan="2">Confidence interval</th><th>Real values</th><th>C<sub>1</sub></th><th>Relative error %</th></tr></thead><tbody><tr><td rowspan="2">15</td><td>2010</td><td>2882.92</td><td>2464.92</td><td>3300.92</td><td>3201.69</td><td>14.50</td><td>9.96</td></tr><tr><td>2011</td><td>2683.34</td><td>2255.65</td><td>3111.03</td><td>3405.40</td><td>15.94</td><td>21.20</td></tr><tr><td rowspan="2">14</td><td>2010</td><td>3052.99</td><td>2645.02</td><td>3460.96</td><td>3201.69</td><td>13.36</td><td>4.64</td></tr><tr><td>2011</td><td>2885.30</td><td>2466.59</td><td>3304.00</td><td>3405.40</td><td>14.51</td><td>15.27</td></tr><tr><td rowspan="2">13</td><td>2010</td><td>3311.15</td><td>2993.61</td><td>3628.69</td><td>3201.69</td><td>9.59</td><td>3.42</td></tr><tr><td>2011</td><td>3095.09</td><td>2867.97</td><td>3522.21</td><td>3405.40</td><td>10.24</td><td>9.12</td></tr><tr><td rowspan="2">12</td><td><strong>2010</strong></td><td><strong>3549.77</strong></td><td><strong>3363.76</strong></td><td><strong>3735.78</strong></td><td><strong>3201.69</strong></td><td><strong>5.24</strong></td><td><strong>10.87</strong></td></tr><tr><td><strong>2011</strong></td><td><strong>3484.84</strong></td><td><strong>3292.34</strong></td><td><strong>3677.34</strong></td><td><strong>3405.40</strong></td><td><strong>5.52</strong></td><td><strong>2.33</strong></td></tr><tr><td rowspan="2">11</td><td>2010</td><td>3579.59</td><td>3373.36</td><td>3785.82</td><td>3201.69</td><td>5.76</td><td>11.80</td></tr><tr><td>2011</td><td>3521.54</td><td>3306.89</td><td>3736.19</td><td>3405.40</td><td>6.10</td><td>3.41</td></tr></tbody></table>

<figure><img src="image_2.png" /><figcaption>**Figure1.** Values of C₁ criterion between 15-11 length time series for fish species “Bogue” in Greek fishery</figcaption></figure>
Table 3 presents the results of the forecasting subroutine application, based on polynomial second degree trend model, on the “total fish quantity” time series. It is evident that the best forecasting result is achieved for time series length 9, because the value of criterion C₁ is the smallest – 2.96 and 3.75, for years 2010 and 2011, respectively.

<table><caption>**Table3.** Forecasting results for total quantity of fish catches in Greece</caption><thead><tr><th>Time series length</th><th>Year</th><th>Forecasted values</th><th colspan="2">Confidence interval</th><th>Real values</th><th>C<sub>1</sub></th><th>Relative error %</th></tr></thead><tbody><tr><td rowspan="2">20</td><td>2010</td><td>61479.50</td><td>50465.45</td><td>72493.55</td><td>70122.20</td><td>17.91</td><td>12.33</td></tr><tr><td>2011</td><td>55345.39</td><td>43955.74</td><td>66735.04</td><td>62871.50</td><td>20.58</td><td>11.97</td></tr><tr><td rowspan="2">19</td><td>2010</td><td>69345.30</td><td>59130.43</td><td>79560.17</td><td>70122.20</td><td>14.73</td><td>1.11</td></tr><tr><td>2011</td><td>66207.68</td><td>55611.86</td><td>76803.50</td><td>62871.50</td><td>16.00</td><td>5.31</td></tr><tr><td rowspan="2">18</td><td>2010</td><td>78486.68</td><td>69918.60</td><td>87054.77</td><td>70122.20</td><td>10.92</td><td>11.93</td></tr><tr><td>2011</td><td>79005.61</td><td>70086.60</td><td>87924.63</td><td>62871.50</td><td>11.29</td><td>25.66</td></tr><tr><td rowspan="2">17</td><td>2010</td><td>86653.35</td><td>79761.13</td><td>93545.58</td><td>70122.20</td><td>7.95</td><td>23.57</td></tr><tr><td>2011</td><td>90610.88</td><td>83407.19</td><td>97814.57</td><td>62871.50</td><td>7.95</td><td>44.12</td></tr><tr><td rowspan="2">16</td><td>2010</td><td>92217.97</td><td>86049.52</td><td>98386.42</td><td>70122.20</td><td>6.69</td><td>31.51</td></tr><tr><td>2011</td><td>98648.66</td><td>92171.04</td><td>105126.28</td><td>62871.50</td><td>6.57</td><td>56.91</td></tr><tr><td rowspan="2">15</td><td>2010</td><td>89754.04</td><td>83290.40</td><td>96217.68</td><td>70122.20</td><td>7.20</td><td>28.00</td></tr><tr><td>2011</td><td>95025.24</td><td>88200.23</td><td>101850.25</td><td>62871.50</td><td>7.18</td><td>51.14</td></tr><tr><td rowspan="2">14</td><td>2010</td><td>91224.82</td><td>84201.31</td><td>98248.32</td><td>70122.20</td><td>7.70</td><td>30.09</td></tr><tr><td>2011</td><td>97231.40</td><td>89767.06</td><td>104695.74</td><td>62871.50</td><td>7.68</td><td>54.65</td></tr><tr><td rowspan="2">13</td><td>2010</td><td>89050.90</td><td>81438.80</td><td>96663.00</td><td>70122.20</td><td>8.55</td><td>26.99</td></tr><tr><td>2011</td><td>93898.06</td><td>85745.68</td><td>102050.44</td><td>62871.50</td><td>8.68</td><td>49.35</td></tr><tr><td rowspan="2">12</td><td>2010</td><td>80442.93</td><td>75340.46</td><td>85545.40</td><td>70122.20</td><td>6.34</td><td>14.72</td></tr><tr><td>2011</td><td>80371.25</td><td>74855.87</td><td>85886.62</td><td>62871.50</td><td>6.86</td><td>27.83</td></tr><tr><td rowspan="2">11</td><td>2010</td><td>79141.56</td><td>73427.51</td><td>84855.61</td><td>70122.20</td><td>7.22</td><td>12.86</td></tr><tr><td>2011</td><td>78269.03</td><td>72022.79</td><td>84515.28</td><td>62871.50</td><td>7.98</td><td>24.49</td></tr><tr><td rowspan="2">10</td><td>2010</td><td>71699.59</td><td>69295.85</td><td>74103.32</td><td>70122.20</td><td>3.35</td><td>2.25</td></tr><tr><td>2011</td><td>65865.75</td><td>63201.50</td><td>68529.99</td><td>62871.50</td><td>4.04</td><td>4.76</td></tr><tr><td rowspan="2">9</td><td><strong>2010</strong></td><td><strong>69385.92</strong></td><td><strong>67329.52</strong></td><td><strong>71442.32</strong></td><td><strong>70122.20</strong></td><td><strong>2.96</strong></td><td><strong>1.05</strong></td></tr><tr><td><strong>2011</strong></td><td><strong>61869.42</strong></td><td><strong>59550.33</strong></td><td><strong>64188.50</strong></td><td><strong>62871.50</strong></td><td><strong>3.75</strong></td><td><strong>1.59</strong></td></tr><tr><td rowspan="2">8</td><td>2010</td><td>68904.13</td><td>66429.77</td><td>71378.50</td><td>70122.20</td><td>3.59</td><td>1.74</td></tr><tr><td>2011</td><td>61002.20</td><td>58149.52</td><td>63854.88</td><td>62871.50</td><td>4.68</td><td>2.97</td></tr><tr><td rowspan="2">7</td><td>2010</td><td>66870.92</td><td>64342.34</td><td>69399.50</td><td>70122.20</td><td>3.78</td><td>4.64</td></tr><tr><td>2011</td><td>57161.69</td><td>54161.67</td><td>60161.71</td><td>62871.50</td><td>5.25</td><td>9.08</td></tr></tbody></table>

Figure2 presents the real values for total fish catch quantity for time period 1999-2011 and the forecasted values based on time series length n=11, 9 and 7 (polynomial second degree trend model). The results have the following characteristics:
* Forecast of length 11 is optimistic because trend model uses much bigger values of catch quantity at the beginning of the period 1999–2009 than at the end. For the opposite reason forecast of length 7 spanning the period 2003–2009 is pessimistic.

* The most important result consists of the fact that the algorithm automatically finds the optimal time series length 9 and the polynomial second degree model for achieving the best forecast.

<figure><img src="image_3.png" /><figcaption>**Figure2.** Forecasting results for varying time series length *n*</figcaption></figure>

The obtained results show that the algorithm is adaptive to the dynamic of the fish catch quantity process and automatically achieves forecasting results.

# 4 CONCLUSION

This work presents an algorithm applied on time series, capable to achieving optimum trend models and forecasting with minimum human intervention. The most significant characteristic of the developed algorithm is the varying length time series used for automatic model fitting. A criterion related to the stochastic error of the forecasted values is constructed for the estimation of the best forecast. When analyzing the set of time series the algorithm behaviour is adaptive to time series length and trend model. As a result, the forecasts are achieved automatically.

A component oriented approach has been used for the implementation of the software. The forecasting algorithm has been tested on time series sets concerning sea fishery in Greece and acceptable forecasting results are attained. The same algorithm can be applied in appropriate time series of other branches giving equivalent results as well. More efficient results are achieved in case forecasting is applied on large numbers of time series because it saves time and efforts.
REFERENCES

1. Singh, S.: Pattern Modelling in Time-Series Forecasting, An International Journal of Cybernetics and Systems, 31 (1), pp. 49-66 (2000)

2. Makridakis, S., Wheelwright, S., McGee, V.: "Forecasting: Methods and Applications", pp. 926. Wiley, New York (1983)

3. Leonard, M.: "Large-Scale Automatic Forecasting: Millions of Forecasts", SAS Institute, http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.9518&rep=rep1&type=pdf

4. Marahaj, E. A., Inder, B.: Forecasting Time Series from Clusters, Working Paper 9/99, Monash University, Australia, http://ideas.repec.org/p/msh/ebswps/1999-9.html

5. Hyndman, R.J., Khandakar, Y.: Automatic Time Series Forecasting: The forecast Package for R, Journal of Statistical Software, 27 (3), pp. 1-22 (2008)

6. Wong, W.K., Bai, E., Chu, A.W.: Adaptive Time-Variant Models for Fuzzy-Time-Series Forecasting, IEEE Transactions on Systems, Man, and Cybernetics, Part B: Cybernetics, 40 (6), pp. 1531–1542 (2010)

7. Chen, S. M., Tanuwijaya, K.: Multivariate fuzzy forecasting based on fuzzy time series and automatic clustering techniques, Journal of Expert Systems with Applications, 38 (8), pp. 10594–10605 (2011)

8. Velickova, N.: Statistical methods for study and forecasting the development of socio-economic processes, Publishing house "Science & Art", Sofia (1981)

9. Tegos, G.: PC-Information System concerning sea fishery time series in Greece, PhD thesis, Computer science department, Agricultural University, Plovdiv (2005)

10. Onkov, K., Tegos, G.: Management solutions for fish resources in Greece based on analysis of multi-dimensional database, Proceedings of the International Conference "Sustainable landscape planning and safe environment", pp. 95-103 (2012)