Abstract

Rainfall is one of the climatic factors that influence various human activities and affect decision making in daily life activities. High intensity of rainfall can turn into a threat and cause serious problems such as causing various natural disasters. Therefore, it is essential to conduct rainfall forecasting to anticipate and enable preventive actions and can be used as a decision consideration in increasing the productivity and mobility of human activities. The aim of this study is to compare rainfall accuracy between the Gregorian and the lunar calendars using the bidirectional long short-term memory (Bi-LSTM) machine learning model through the grid search approach. This method was used because it can capture patterns arising from the simultaneous effects of two asynchronous calendars, Gregorian and lunar, which were used in this study by finding the right parameters. Monthly rainfall data from Bogor City, Indonesia, were used from the period of 2001 to 2022. The results show that the MAPE of the lunar calendar is relatively smaller at 14.82% which indicates the better forecasting ability than the Gregorian calendar which is 35.12%.

1. Introduction

Most rainfall forecasting is based on the Gregorian calendar [1, 2], but many rainfall phenomena are closely linked to the lunar calendar [3]. Earth’s climate including variations in rainfall and tides is influenced by the phases of the moon, which are the cornerstone of making the lunar calendar (see [4]). Conversely, rainfall forecasting has generated significant research attention in recent times owing to its complexity and ongoing applications. Hence, methods employing machine learning algorithms in conjunction with time series data are being investigated as viable alternatives to address these limitations (see [5, 6]).

In recent years, machine learning algorithms have been widely employed for time series data predictions, yielding highly accurate results. Machine learning enables the resolution of prediction problems in time series data with a wide range of values. Numerous studies have been conducted on rainfall forecasting using machine learning algorithms, including the support vector machine (SVM) method (see [7, 8]), the deep neural network (DNN) method (see [9, 10]), and the long short-term memory (LSTM) method (see [1113]).

Bidirectional long short-term memory (Bi-LSTM) is a machine learning method suitable for time series data prediction. It is an extension of LSTM with the capability of retaining dat information from both forward and backward directions. This capability enhances the learning process by offering additional neural networks, leading to more comprehensive results. To obtain the best forecasting model using the Bi-LSTM method, it is essential to determine the optimal parameters for the learning algorithm. Parameter setting and tuning play a significant role in improving forecasting accuracy. One effective approach to determining the optimal parameter setting and tuning is to utilize the grid search algorithm. The grid search algorithm works by systematically combining various parameters used in the model creation process. This method divides the parameter range into a grid and explores different combinations of parameter settings to identify the best parameters for the model. According to [14, 15], the grid search technique improved the model performance.

This study covered three aspects of analysis: (1) rainfall data conversion from the Gregorian-based calendar to the lunar-based calendar, (2) rainfall data modeling and forecasting based on the lunar calendar, and (3) comparison of rainfall forecasting accuracy which is based on the Gregorian calendar and the lunar calendar. The purpose of this study is to forecast the rainfall using the bidirectional long short-term memory (Bi-LSTM) model by the grid search approach. This research is expected to yield an efficient calendar conversion algorithm and can be used as the basis for further research for making an automatization of calendar conversion. Some previous works on the calendar conversion were conducted by [1621].

2. Materials and Methods

2.1. Bidirectional Long Short-Term Memory (Bi-LSTM)

LSTM was specifically designed to address the problem of vanishing gradient. LSTM units consist of forget gates, input gates, and output gates, which are used to control the storage or disposal of information. This method has been used in various cases such as sentiment analysis [22], COVID-19 vaccination responses [23], and smartphone data sensors [24]. LSTM usually uses quite complex calculations and high computation in its application. Therefore, this study examines a method with a simpler level of computation but with comparable performance, Bi-LSTM.

Bi-LSTM was proposed by Graves and Schmidhuber to solve a flaw in the recurrent neural network (RNN) and the LSTM model. In both models, information can only be propagated forward, meaning that the time state t depends only on the information before time t [25]. On the other hand, Bi-LSTM involves two LSTM networks: processing the sequence of data input in the forward direction and processing the sequence of data in the reverse direction (backward). This method can store time series information in two directions and can provide additional training processes. Additional training processes and two-way feature extraction make Bi-LSTM have better performance [26]. In addition, the outputs of the forward and backward LSTM networks are combined on each time sequence.

The Bi-LSTM model can learn past and future information for each input sequence. In addition, Bi-LSTM has two layers of data input that are opposite to each other which enable the model does not forget a long sequence of data information during the training process [27]. Therefore, theoretical prediction performance with Bi-LSTM is better than that with LSTM [28]. The architecture of Bi-LSTM [29] is provided in Figure 1.

Figure 1 shows that the order of the forward layer is the same as in a regular LSTM network that calculates the sequence of , , and then . However, for the backward layer, the hidden layer and output iterated from , t, to . and are the forward and backward layers, respectively. According to [30], the process of forward LSTM and backward LSTM can be written as follows:

It is described in Figure 1 that the hidden layers on each forward and backward are connected and form an output value. The calculation of the output value is shown in the following equation [31]:with as the final output value and and as the weight values for the output gate on and , respectively.

Several studies using the Bi-LSTM method have been conducted by authors in [32] on the case of wastewater flow rate prediction, by authors in [33] on tropical cyclone prediction, by authors in [34] on groundwater content prediction and soil, and by authors in [35] on water content and river water flow prediction.

2.2. The Grid Search Method

The grid search is a method used for finding appropriate parameters to improve model performance by trying all combinations of parameters. In its applications, the grid search algorithm is usually combined with cross-validation to form a model evaluation index. The index evaluates model performance by considering data sharing.

In this paper, the grid search algorithm is evaluated by a cross-validation (CV) test. A common form of cross-validation is k-fold, which is used to estimate prediction errors in evaluating model performance. It divides datasets into k groups of equal size. One of the k-fold groups was used as test data while the rest of the groups were used as training data. The parameter pair obtained from the cross-validation test with the smallest error average is the best parameter. This parameter is used in the formation of the model for later testing and evaluation.

2.3. Calendar Conversion

This study utilizes algorithm to convert daily data into monthly data based on the lunar calendar. The month’s names and the number of days are referenced from the islamicfinder.com website. The conversion of daily data from the Gregorian calendar to the lunar calendar requires data division into three segments, as illustrated in Figure 2. The conversion process using the “TS” package in R software [36] is done through the following steps:(1)Determine the initial and end dates of the lunar calendar(2)Partition the time interval into three calendar parts(3)Convert boundary points from the Gregorian calendar to the lunar calendar(4)Make these three segments into vector shapes of the dates of the Gregorian and lunar calendars as seen in Figure 2(5)Include calendar attributes, i.e., lunar number and date, e.g., Attr < - c (no, dates)(6)Create a data frame which consists of the combination of the three vectors(7)Input the daily rainfall data based on the Gregorian calendar in a separate column/vector(8)Merge the column vector of daily data with lunar number and dates into the data frame in Step 6(9)Shift the daily data according to the calendar converter and change the name of Gregorian months to the corresponding lunar months

2.4. Preprocessing Data

The data preprocessing stage is carried out to improve performance in data processing and prevent errors in the data so that the data used for the prediction process have a high quality. The first stage in the data preprocessing process is data cleaning in which data are adjusted in the presence of missing values. Handling of missing values in data can be done using the mean imputation method, in which missing values are filled up with the average of all known values in a variable.

The second stage is data sharing or data splitting, i.e., data are divided into training and testing data. Training data are used in training models, while testing data are used in evaluation of the selection of model architectures with the best parameters. The total data used in this study were 286 lunar calendar data and 273 Gregorian calendar data. These data were divided into several forecasting lengths: 3, 6, 12, 18, and 24 months.

The third stage is called a scaling or mapping technique which is used to normalize data. The normalization process involves the min-max method. The data normalization process will result in values ranging from 0 to 1. According to [28], the equation used in data normalization is as follows:and the denormalization [37] of the data iswhere is a normalised value, is the maximum value of the entire data, and is the threshold of the entire data.

2.5. Bi-LSTM-Grid Search Modeling

In building models using the machine learning model such as Bi-LSTM, it is important to select optimal parameters. Parameter determination or tuning parameters are used to control the model so that it can produce better model performance [38]. This study proposed the use of the Bi-LSTM-grid search model (see Figure 3).

Bi-LSTM modeling with grid search consists of input layer, Bi-LSTM layer, dropout layer, dense layer, and the addition of the grid search algorithm to determine the best parameters in the Bi-LSTM learning process and output layer. The input layer is the layer that receives input data, while the Bi-LSTM is a layer in the learning process. Dropout layers are used to prevent overfitting of the model during the learning process. The dense layer is a neural network layer that has functions to convert the output of the previous layer into predicted values. The output layer is a layer that produces outputs or final values in the learning process. The addition of a grid search algorithm is used to determine the best parameters, dividing the range of parameters used into grids and at all points in order to obtain optimal parameters in the learning process of the Bi-LSTM model.

Some of the parameters used in this study consist of one hidden layer, hidden neurons, batch, and epoch. In addition, dropout regulation techniques are also used to avoid overfitting in the model. Adam’s optimization or optimizer function is added to determine the optimal weight and reduce errors in the model formation process of maximizing model accuracy. The parameter values set to build the prediction model are given in Table 1.

The determination of neuron numbers in the hidden layer is carried out to obtain the optimal number of hidden neurons. Epoch is a condition where all data have gone through the training process on the network that is formed until it returns to the beginning in one round. Each epoch can be partitioned into batches. Batch is a parameter that determines the sample size used in the process before updating architectural parameters.

The best parameter value from each combination of parameters can be determined using a grid search with the help of cross-validation. It allows for an evaluation of each model with various combinations of predefined parameter limit values. A common form of cross-validation is k-fold cross-validation. In this study, the grid search algorithm used 5-fold validation.

3. Results and Discussion

3.1. Calendar Conversion Results

The data used in this research are daily rainfall data from 1st April 2000 to 31rd December 2022 in Bogor City obtained from the Meteorological, Climatological and Geophysical Agency. The daily rainfall data in the Gregorian calendar were shifted into Gregorian monthly data. The result of the observations of 22 years revealed that the Gregorian calendar has 273 months as seen in Table 2. The results of rainfall data conversion from the Gregorian calendar to the lunar-based calendar can be seen in Table 3 which has 286 months.

3.2. Bi-LSTM Prediction Results, Grid Search

The data used in Bi-LSTM modeling were those that passed in the data preprocessing stage, and parameter tuning was conducted using the grid search algorithm. Based on predetermined parameters, 375 models were obtained from a combination of parameters. Of the 375 models, the most optimal combination of parameters was obtained based on the minimum MSE (mean squared error) value for each forecasting length in the Gregorian and the lunar calendars which was continued to the testing process. See Table 4 for the complete results.

Based on the results in Table 4, the smallest MSE was 0.01882 for a 12-month forecasting length with an optimal combination of parameters based on tuning parameters using the grid search such as the number of neurons 20, batch 4, epoch 200, and dropout 0.2. The model with the best combination of parameters obtained from the training data using the grid search was then applied to the testing data. The optimal combination of parameters for rainfall data based on the lunar calendar is shown in Table 5.

According to Table 5, the smallest MSE was 0.01891 with a forecasting length of 3 months, the number of neurons 20, batch 4, epoch 200, and dropout 0.1. Similar to the model in the Gregorian rainfall data, the model with the best combination of parameters obtained from the training data was then applied to the testing data.

The Bi-LSTM model was formed using testing data based on the selection of the best parameters. The forecasting length was evaluated using MAPE based on the lunar and Gregorian calendars which is provided in Table 6.

Table 6 shows the results of model evaluation using MAPE on rainfall data with various forecasting lengths. MAPEs are computed based on the best combination of parameters. The lowest MAPE is the lunar calendar-based rainfall data with a forecasting length of 3 months. The results in Table 6 conclude that the longer the forecasting, the smaller the MAPE. The comparison of actual data and forecasting results of rainfall data based on the Gregorian and lunar calendars using a model with the best parameters for each forecasting length is reported in Figures 4(a) and 4(b).

According to Figures 4(a) and 4(b), the Bi-LSTM model that was formed using the best parameter selected using the grid search algorithm on rainfall data based on the lunar calendar produces predictions that are quite similar to the test data pattern. The MAPE value obtained from rainfall data based on the lunar calendar was relatively lower than the one from the Gregorian. The lowest MAPE was obtained from the lunar calendar-based rainfall data at 14.82% with the best parameter values optimized using the grid search algorithm: the number of neurons 20, batch 4, epoch 200, and dropout 0.1. The criteria of the MAPE value could confirm the accuracy of the model. In conclusion, the best model obtained from the Bi-LSTM grid search was able to provide better results in modeling rainfall data based on the lunar calendar instead of the Gregorian calendar.

4. Discussion

Converting the Gregorian-based rainfall data to the lunar calendar gives an advantage in time series analysis. The conversion of daily data to monthly data based on the lunar calendar increases the length of the data series, which provides more information and gives a better forecast. The addition in time series length is an effect of different number of days in a year. In particular, the Gregorian calendar has 365 days, while the lunar calendar has 355 days. In general, the longer the forecasting horizon, the bigger the mean absolute percentage error (MAPE) for both Gregorian and lunar calendars.

The use of lunar calendar-based forecasting for rainfall is because the moon’s gravity affects the earth’s climate. Furthermore, the moon exerts a more significant influence on earth than the sun due to its closer distance. The moon’s position not only affects its phases but also has a gravitational impact on earth’s weather. The effect of the moon’s gravitational force on earth’s rainfall needs further study involving collaboration with astronomers.

Lunar calendars are commonly used in countries with Muslim populations as the majority, such as Indonesia, Saudi Arabia, and the Middle East. The Islamic calendar, known as the Hijri calendar, is derived from the lunar calendar. Religious holidays often affect significant movements of residents who want to visit places of worship or their hometown for family reunions, visit their parents and relatives, and so on. As a result, the lunar calendar has a notable impact on transportation and economy, particularly in countries with large Muslim communities.

The grid search algorithm proposed in this paper remains time-consuming. Each parameter combination takes approximately two hours to complete, which is less efficient. Hence, it is advisable to explore alternative algorithms, such as the genetic algorithm.

5. Conclusions

In this paper, we employed the machine learning time series method with the Bi-LSTM model and the grid search approach. The accuracy of forecasting results of rainfall data based on the lunar calendar was evaluated using the mean absolute percentage error (MAPE). We also compare the MAPE of the Gregorian calendar-based rainfall data model and the lunar calendar-based rainfall data model.

The lowest MAPE for the Gregorian calendar-based model was 35.12%, while the lowest MAPE for the lunar calendar-based model was 14.82%, with a forecasting length of 3 months. The smaller MAPE for the lunar calendar-based model suggests a superior forecasting ability compared to the Gregorian calendar-based model. According to the MAPE criteria, the forecasting model based on the lunar calendar can be considered highly accurate. The optimal combination of parameters for rainfall data based on the lunar calendar, as determined through the grid search algorithm, comprises 20 neurons, 200 epochs, a batch size of 4, and a dropout value of 0.1.

Data Availability

The data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest

The authors declare that there are no conflicts of interest.

Acknowledgments

The authors would like to acknowledge Universitas Padjadjaran for funding this research. This research was funded by the Acceleration to Senior Lecturer Grant number 1549/UN6.3.1/PT.00/2023, Universitas Padjadjaran.