## 4 Platform Design
### ToU Ranges Using GRU Model Predictions and K-Mean Clustering
#### 4.1.1 Energy Consumption Time Series Forecasting Using GRU  
Our forecasting model is using an open-source dataset from PJM, in Megawatts [62], The data consist of hourly records of electricity consumption in the USA for a period of time ranging from 31 December 2004 to 1 February 2018. They are structured into double columns of 121,274 values with no empty values. The energy consumption histogram provided in Figure 3 shows a normal distribution and hence, normalization of the dataset is not required.  
The model is trained by utilizing the GRU network. Numerous research works including [63,64] have successfully applied the GRU network for predicting electricity consumption. The aforementioned studies have investigated the performance of several machine learning predictive models to forecast electricity consumption. Results have shown that the GRU-based method achieves more accurate predictions, making it the reason behind our choice. The implementation of the standard GRU prediction model is conducted  
Figure 3: Distribution of the observations in the dataset.  
Figure 2: The proposed model defining TOU peak and off-peak ranges.  
under the Keras framework with Tensorflow2 as the back end, using Python language. The prediction of the electricity consumption in the next defined time steps should only use the historical electricity consumption data and the date-time as predicting features. Despite the availability of other datasets containing other metrics such as consumers' household temperature and humidity, we stick only to date and time as extracted features for prediction. The reason behind it is that the prediction is meant to be performed by the electricity provider who is not supposed to have access to such private data of his clients. The predictions should solely be based on the electricity consumption data uploaded to the blockchain by the respective clients. During each new trading round, the GRU model adds the previously collected electricity consumption data to its training set. The model is evaluated by its accuracy. As a consequence, the more rounds go by, the more data available to train the model and thus the more precise the prediction should be. To assess that, we defined the trading round to be 100 days, i.e., we would be using 2400 rows to forecast the next 2400 rows. Then the number of rows \(R(n)\) that is used to predict the upcoming 2400 rows in the \(n\)-th round is defined according to the expression in Equation (1):  
\[R(n)=2400\cdot n,n>0 \tag{1}\]  
The performance of the model is assessed in terms of the Mean Average Percentage Error (\(MAPE\)) given in Equation (2), and the results are depicted in Figure 4.  
\[MAPE=\frac{100}{n}\sum_{i=1}^{n}\left|\frac{(Y_{i}-P_{i})}{Y_{i}}\right| \tag{2}\]  
where \(Y_{i}\) is the \(i\)-th real electricity consumption reading and \(P_{i}\) is the \(i\)-th reading of the predicted electricity consumption, in a test set of size n. Figure 5 also provides the real energy consumption with respect to predicted energy consumption for the 50 th trading round. As shown in Figure 4, there are two jumps in the performance of the model. The first one occurs after nine trading rounds, which is equivalent to 9000 days and 90,000 observations, and the \(MAPE\) drops from 3% to 2.42%. Then, after the 16 th round, the \(MAPE\) drops from 2% to less than 1%. Past the 20 th round, there is no more steady decrease in the \(MAPE\), however, it fluctuates approximately in the range [0.39%, 0.61%]. The advantage of this kind of prediction is that it uses on-chain data to perform the prediction. Since each node has a copy of the ledger containing the dataset that is used to train the model, this ensures the transparency of the prediction that can be verified by any node in the network.  
Figure 4: GRU prediction model performance evolution as the trading rounds go by.