1. Introduction
One of the most important challenges the world faces in the twenty-first century is climate change, which is having a profound effect on the environment and the socio-economic well-being of the world’s population. Human activities, such as burning fossil fuels, deforestation, and land use, have affected the energy balance of Earth’s atmosphere, leading to global warming and climate change [
1,
2]. This, in turn, has led to extreme temperatures and irregular precipitation patterns, with a profound impact on the environment’s sustainability [
3].
Although global and regional climate assessments are imperative for giving us a glimpse of the climate, there are instances in which the local climate is not considered. This is particularly true for local climate behaviour, especially when the local population is affected by climate change. To illustrate, the local climate is imperative in regions where the local population is affected by climate change, especially in the implementation of agricultural and water resource activities. The impacts of climate change, in this case, are usually seen through increases in temperature and decreases in rainfall [
4].
The South African region is highly susceptible to climate variability due to its diverse climatic conditions and socio-economic disparities. Although research has been conducted at different levels of analysis, various insights have emerged regarding general trends in climate variability. However, little emphasis has been placed on local-scale changes and short-term variability, which have important impacts on smaller towns/local areas [
5]. Such variability may influence agricultural productivity, water availability, and the resilience of local infrastructure and livelihoods, particularly in areas that depend heavily on climate-sensitive resources. Thohoyandou is a local community situated in the Limpopo Province in South Africa. In the past few decades, this region has experienced changes in temperature and precipitation patterns, affecting local activities such as agriculture, water availability, and biodiversity [
4]. In addition, various socio-economic changes, such as infrastructure development and water availability, have negatively impacted the adaptive potential of various communities in South Africa [
6]. Despite its economic importance in this region of South Africa, local-scale investigations of temperature and precipitation patterns have not been well addressed in Thohoyandou.
Accurate prediction of local weather patterns poses substantial methodological problems. In fact, widely used statistical methods for time series prediction, like Autoregressive Integrated Moving Average (ARIMA), Seasonal ARIMA (SARIMA), and Generalised Autoregressive Conditional Heteroscedasticity (GARCH), are commonly used for weather forecasting because they are computationally efficient and easy to understand and interpret [
7]. General Circulation Models (GCMs) are commonly employed in large-scale climate projections. However, the spatial resolution of GCMs is generally poor and does not allow for accurate representation of local-scale climates. This means that small-scale areas, such as towns/municipalities, can end up with climatic characteristics that differ entirely from those of the rest of the region [
8,
9].
However, these challenges have spurred growing interest in applying machine learning (ML) methods to climate-related forecasting problems. ML algorithms can learn nonlinear relationships and temporal dependencies from data without prior knowledge of the underlying problem dynamics, making them well-suited for short-term forecasting. In Africa, ML methods such as Random Forests, Support Vector Regression, and gradient boosting models have been applied to rainfall and temperature forecasting in several studies [
10]. In East and West Africa, recurrent neural network models, such as Long Short-Term Memory (LSTM) networks, have been successfully used for daily and hourly climate forecasting, indicating their effectiveness in modelling temporal dependencies and nonlinear relationships in time-series data [
11].
The power of Artificial Neural Networks (ANNs) and LSTM networks can be leveraged for short-term time series forecasting. Furthermore, the vanishing gradient problem is addressed in LSTM networks through memory gates, which help learn long-term temporal dependencies and autocorrelation patterns in time series data [
12]. Also, the success of deep learning techniques in handling nonstationary time series data indicates that such data can be used for training the model. That relevant features can be learned internally without the need for manual detrending [
13]. In fact, results from large-scale forecasting competitions, such as the M4 competition, also show the potential of neural network-based forecasting methods for handling level and seasonal patterns in data while retaining high forecast accuracy [
14]. In fact, comparative studies of different forecasting methods also show the potential of deep learning-based methods in handling nonstationary time series data [
15,
16]. From the perspective of representation learning in time series data, higher layers of the network learn higher-level features, making it useful for short-term forecasting tasks [
17].
Recent literature has also highlighted the importance of incorporating transparent statistical baselines in the evaluation of machine learning models. Generalised Additive Models (GAMs) offer a flexible yet transparent approach for modelling nonlinear relationships between variables by fitting smooth functions of the covariates. GAMs have been successfully employed in various climate-related studies, including temperature interpolation and drought index modelling in a nonstationary climate [
18]. GAMs have been successfully employed in South Africa to model drought-related variables, such as the Standardised Precipitation Evaporation Index, at different timescales. This indicates the capability of GAMs in modelling hydrological extremes in semi-arid regions of South Africa. Incorporating a GAM baseline into the study will improve its methodological rigour and provide a transparent approach to interpreting results relative to more advanced machine learning models [
19].
In Africa as a whole, deep learning techniques such as LSTM networks have been successfully employed for monthly and seasonal rainfall forecasting in various regions, including Ghana. Machine learning techniques have been employed for rainfall prediction in arid and semi-arid regions of South Africa [
20].
The effects of climate change in Thohoyandou have been further complicated by strain on the country’s infrastructure, water, and food security, with the most vulnerable populations affected [
6]. The rising temperatures have been attributed to increased heat stress and irrigation needs, with irregular rainfall patterns negatively affecting agricultural activities and water management [
21,
22]. Although GCMs successfully capture large-scale climate patterns, they are less effective at representing local-scale variability [
2,
9]. Machine learning combined with decomposition techniques, including the Bayesian Estimator of Abrupt change, Seasonal change, and Trend (BEAST), has been found useful for forecasting fine-scale climatic patterns, including changes in expected climatic patterns and long-term climatic trends.
This research will focus on the forecasting of short-term temperature and precipitation anomalies in Thohoyandou, South Africa. Hourly data collected for many decades will be used. Anomalies will indicate deviations from expected seasonal patterns. Long-term climatic trends and structural changes will also be analysed separately using the BEAST decomposition technique. For forecasting, Artificial Neural Networks and Long Short-Term Memory will be used. A Generalised Additive Model will be used as the statistical model.
The remainder of this paper is structured as follows.
Section 2 introduces the models,
Section 3 presents the empirical results, and
Section 4 provides a detailed discussion of these findings. Finally,
Section 5 offers concluding remarks.
2. Materials and Methods
2.1. Study Area
The specific area of interest is Thohoyandou, located in Thulamela Local Municipality, Limpopo Province, South Africa (see
Figure 1). Thohoyandou is situated at 30.4663° E, 22.9749° S, with an altitude of 596 m above sea level. Thohoyandou covers 42 km
2, or 4200 hectares, thus defining the physical boundaries of the specific area of interest. Thohoyandou has a subtropical climate with hot, humid summers and dry, warm winters, with large seasonal changes in temperature and rainfall [
23].
Study area: The area was chosen due to its complex local weather patterns and its significance to climate variability in Northern South Africa. Thohoyandou is also a data-scarce area, making it an ideal place to test ML forecasting methods. Thohoyandou can also represent various small and medium-sized towns in the north of South Africa that experience subtropical climatic conditions and rainfall variability. Similar climatic conditions have been observed in various areas of Limpopo and southern Africa [
24]. Although it is essential to note that the analysis was conducted at a single location, it is believed to offer valuable insights for towns with similar climatic and environmental conditions. Caution is required in using it for areas with significantly different climatic conditions and urban structures.
2.2. Data Source
The historical weather data used in this study, which include hourly temperature (2 m) and precipitation (snow and rain) records over 35 years (1 January 1990 to 16 March 2025), were obtained from the Open-Meteo Historical Weather API, available at
https://open-meteo.com/en/docs/historical-weather-api (accessed on 5 February 2025). By default, the API provides data derived from the ERA5 reanalysis produced by ECMWF. ERA5 provides hourly data at approximately 0.25° (25 km) spatial resolution and covers the full study period, making it suitable for multi-decadal analysis. Using ERA5 ensures temporal consistency over the entire 35-year period and avoids bias in long-term climate trend analysis.
This dataset was selected because there are no freely available long-term and continuous weather station data for Thohoyandou. ERA5 is well-validated and has been widely used in climate studies. The dataset is suitable for local climate change studies, trend analysis, and the development of machine learning models due to its length, quality, and hourly resolution [
25]. The dataset’s high resolution and uniformity also enable accurate analysis of temperature and precipitation anomalies in a data-poor environment such as Thohoyandou.
The dataset has 308,616 hourly records from 1 January 1990 to 16 March 2025. The dataset has 35 years of continuous data for Thohoyandou. After feature engineering, the dataset has 308,448 values; temperature and precipitation are the main variables in this research. In addition to the original variables, several feature engineering variables were created to enhance forecasting accuracy, including lagged temperature anomalies (1, 2, 3, and 168 h), lagged precipitation anomalies (1, 2, 3, and 24 h), calendar variables (Day, Month, Hour), and meteorological covariates such as humidity, dew point, cloud cover, wind speed, wind direction, and atmospheric pressure.
During the data preprocessing, accuracy and validity were ensured for all variables. The most difficult part of preprocessing was handling the large number of zeros in the precipitation data. The zeros represent dry days, which are common in a subtropical environment. In this research, zeros were retained because removing them would bias the data. There were no missing values in this data set.
The temperature values showed continuous variation without any issues with the zero point. To enhance the depiction of climate variability, the anomalies of temperature and precipitation were determined by subtracting the long-term mean of the series from the hourly measurements. Anomaly variables are used to detect abnormal conditions, such as heat waves and rainfall, and are centred variables that can be employed for trend analysis and prediction. The outliers were not removed since they are actual extreme events of high interest in climate research.
2.3. Machine Learning Models
Two machine learning models were used in this research: the Artificial Neural Network (ANN) and the Long Short-Term Memory (LSTM) network. The ANN model served as the baseline, while the LSTM model served as the main forecasting model due to its better capacity to handle temporal dependencies.
2.3.1. Artificial Neural Network (ANN)
The concept of an ANN was first proposed in 1943 by [
26], who developed a mathematical model of the artificial neuron. In 1958, the perceptron, the first algorithmically trainable neural network for binary classification, was proposed by [
27]. Although the perceptron was inefficient for nonlinear classification problems, it was not until 1986 that the backpropagation algorithm was proposed by David Rumelhart, Geoffrey Hinton, and Ronald Williams in [
28]. This was a major milestone in the field of neural networks because the algorithm enabled the training of multilayer neural networks using gradient descent to adjust the network’s weights. The algorithm works by computing the gradient of the error function with respect to each network weight and propagating the error backwards from the output layer to the input layer. Today, ANN is used for complex tasks such as image classification, natural language processing, and time series prediction.
A simple neural network in Mathematics can be defined as follows:
where Equation (
2) defines
as the input to the
neuron,
as the weight linking input
j to neuron
k, and
as the input feature. Equation (
3) represents the threshold, denoted by
.
Figure 2 illustrates a multilayer feedforward ANN, comprising an input layer, hidden layers, and an output layer. This type of network contains three essential layers: an input layer, plus one or more hidden layers, and an output layer. Finally, Equation (
4) includes
, the activation function, which can be selected from various nonlinear functions such as the sigmoid function, ReLU, tanh, or others.
2.3.2. Long Short-Term Memory Network
Long Short-Term Memory (LSTM) networks are a class of recurrent neural networks used to learn long-term dependencies in sequential data streams.
Figure 3 shows he structure of LSTM [
30]. Unlike RNNs, LSTM networks use memory cells to store information over time. Three gates control these memory cells: the input gate, the forget gate, and the output gate. These three gates help control the flow of necessary information in the network, thereby eliminating the vanishing gradient problem in RNNs [
31]. Due to LSTM networks’ ability to capture the nonlinear relationships in time series data, these models have been used in various applications, including weather forecasting and climatic analysis.
2.4. Generalised Additive Model (GAM)
A Generalised Additive Model, or GAM, is a highly flexible statistical model that allows predictor variables to take a nonlinear form with respect to the response variable. A Generalised Additive Model can thus be defined as:
where
is a response variable corresponding to a
data point in a dataset,
is an intercept term in a model, and
is a random error term in a model. From a different perspective, that is, from a link function perspective, a Generalised Additive Model can thus be defined as:
where
is a link function,
is a vector of linear predictor variables corresponding to the
i-th data point, and
β is a vector of coefficients corresponding to each predictor variable [
19].
2.5. Variable Selection
The Least Absolute Shrinkage and Selection Operator (LASSO) regression identifies the variables and coefficients that minimise prediction errors [
32]. The popularity of Lasso regression lies in its ability to minimise the L1 norm of the regression coefficient vector and set its coefficients to zero. Lasso regression is particularly useful for solving problems involving high-dimensional data with many predictor variables. Lasso regression sets the coefficients of irrelevant variables to zero, thereby enabling variable selection [
33]. Lasso regression helps identify key principal components during regression model fitting, and not the original features. Lasso regression can be described at its most basic level as shown in [
33].
where
y is a response variable, and
are measurements on the response variable,
,
;
, are the values that correspond to their respective
k predictors,
,
are parameters, and
denotes the error term.
2.6. Grid Search Optimisation
It is a common practice when developing a solution that is based on machine learning to test and implement the best-performing model for a specific problem or task from the range of available models. In this research, the machine learning model is defined as the combination of an algorithm and adjustable parameters. The process of determining the optimal parameters for a specific problem or task is referred to as hyperparameter optimisation [
34].
Hyperparameter tuning is an essential part of the overall process, as it significantly affects the model’s performance. Grid search is one of the most common methods for hyperparameter tuning. In this method, hyperparameter combinations are used to train the model fully, and the best-performing model is selected as the optimal one. The exhaustive search in the grid search method used for hyperparameter tuning ensures the model’s reliability [
35]. The grid search method has been selected over random and Bayesian search methods for hyperparameter tuning. Grid search has been chosen for hyperparameter tuning because it ensures an exhaustive search over all possible hyperparameter values. Grid search has been used to hyperparameter-tune the ANN and LSTM models in this paper to achieve optimal prediction performance.
2.7. Measures of Forecast Accuracy
Mean Absolute Scaled Error
In Equations (
9)–(
12),
n denotes the total number of observations and
t represents the time index (
). The term
denotes the actual observed value at time
t,
represents the forecasted value at time
t, and
denotes the observed value at time
, which is used in the naïve baseline for the MASE calculation.
2.8. Diebold–Mariano Test
In addition to standard evaluation metrics, it is important to assess whether differences in forecast accuracy between competing models are statistically significant. To this end, the Diebold–Mariano (DM) test [
36] was employed to compare the predictive performance of the ANN and LSTM models for temperature and precipitation anomalies.
Let
denote the observed anomaly (temperature or precipitation) at time
t, and let
represent the corresponding forecast from model
i . The forecast error for model
i at time
t is defined as
To reflect the practical importance of accurately capturing extreme anomalies, an asymmetric loss function was adopted in which underprediction errors are penalised more heavily than overprediction errors. This is because underestimating extreme positive or negative events may lead to insufficient preparation for heatwaves, unseasonal cold spells, or heavy precipitation. At the same time, slight overpredictions are generally associated with less severe consequences [
18]. The loss function is specified as
where
is the penalty parameter and
is the indicator function.
The difference in the loss function values for the two competing forecasts is expressed as
which represents the relative loss difference between the two models at time
t.
The null and alternative hypotheses for the DM test are stated as
The value of the penalty parameter was chosen to introduce a moderate additional loss on underprediction errors without significantly affecting the loss distribution. Sensitivity analysis showed that the results of the DM test were insensitive to variations in within a reasonable range. The DM test thus provides a rigorous statistical methodology for assessing the significance of differences in forecast accuracy between the ANN and LSTM models, in addition to conventional error-based performance measures.
2.9. Software Tools and Libraries
All analyses were performed using Python 3.12, which supports data preprocessing, machine learning modelling, and visualisation. The main Python packages used were pandas for data manipulation, NumPy (version 2.4.3) for numerical computations, Matplotlib (version 3.10.8.) and Seaborn (version 0.13.2) for visualisation, and TensorFlow (version 2.20.0) for implementing neural network architectures. The R programming language (version 4.3.1) was used for the BEAST time-series decomposition of the climatic variables. The programming languages Python and R enabled the development of an efficient computational process.
3. Results
3.1. Data Overview and Statistical Properties
In this section, an in-depth analysis of the statistical characteristics of the 35-year hourly temperature and precipitation data shall be presented and analysed in relation to the data used in Thohoyandou. This section also aims to identify the data characteristics and assess the distributions of the variables.
As shown in
Table 1, the temperature range was 4.4 °C to 41.3 °C, with an average of 20.15 °C and a standard deviation of 5.38 °C. The near-zero skewness of 0.179 and the negative kurtosis of −0.240 indicate that the temperature data are normally distributed, though slightly platykurtic. Such features are characteristic of Thohoyandou, which is located in a subtropical region with warm weather and moderate seasonal variations. The calculated temperature anomalies are properly normalised, with an average of zero and a moderate skewness of 0.517, indicating a greater frequency of warm anomalies.
On the other hand, precipitation has a highly skewed, leptokurtic distribution. Most hours have zero rainfall, and only a few instances contribute to the total rainfall volume. The mean precipitation is 0.12 mm, but the maximum is 18.6 mm, confirming that rainfall is intermittent in this region. The extremely high values of skewness (10.804) and kurtosis (186.258) for precipitation confirm that there are mostly dry hours interspersed with heavy rainfall, a characteristic feature of subtropical summers. The precipitation anomaly distribution shows similar characteristics, i.e., it remains skewed, confirming that standardising the anomaly values has retained the natural variability of rainfall.
To further evaluate the temporal characteristics of the data set, the Augmented Dickey–Fuller and the Kwiatkowski–Phillips–Schmidt–Shin tests were applied to the temperature and precipitation anomaly data. The former is a statistical test that assesses the stationarity of a data set, i.e., whether it exhibits a nonstationary trend. The KPSS test is similar, though it tests for the presence of a nonstationary trend.
As shown in
Table 2, the ADF test rejects the null hypothesis of a unit root for the temperature and precipitation anomalies at the 5% level of significance. This confirms the data’s stationarity. The KPSS test, however, rejects the null hypothesis of level stationarity for the data. This implies the existence of deterministic trends. The above tests therefore jointly confirm that the data are trend-stationary, a property in which short-term variations are constant around a mean level, with a long-term trend. This trend-stationarity property can therefore be interpreted as the gradual climatic changes experienced in Thohoyandou over the 35 years. The anomaly data are therefore appropriate for modelling and forecasting, as they have the required temporal dependencies and meet the requirements of statistical and machine learning algorithms.
3.2. Exploratory Analysis of Temperature and Precipitation
The relationship between hourly temperature and precipitation over the 35 years is presented in
Figure 4. The plot shows the density of observations, where darker colours represent a higher concentration of data points within each bin. Most observations are concentrated around zero precipitation, confirming the dominance of dry hours in the dataset. Temperature spans the full observed range regardless of precipitation levels, and no clear relationship between the two variables is evident, suggesting that short-term precipitation events occur largely independently of temperature variations. A few bins indicate relatively high precipitation values, representing rare but intense rainfall events associated with strong storm activity.
Temporal dynamics of the entire time series are shown in
Figure 5. Temperature shows strong seasonality and annual cycles, suggesting climatological predictability, while precipitation is highly irregular, with sporadic bursts of rainfall. Daily cycles of temperature, such as diurnal cycles of heating and cooling, are also evident in the time series, though not depicted here. This shows that temperature is deterministic and predictable, while precipitation is stochastic.
The density and Q-Q plots for temperature and precipitation are shown in
Figure 6, which illustrate differences in distribution. Temperature data have a normal distribution around 20–25 °C, while precipitation data have a highly skewed distribution with many zeros and extreme values. Seasonal variation in temperature data is evident. Summer months have higher temperatures, while winter months have lower temperatures. The months between these two seasons have a wider range of values. Precipitation data do not show a clear pattern across months. There are many zeros in precipitation data, along with some extreme values for rain hours.
The anomalies in temperature and precipitation relative to the 35-year mean are shown in
Figure 7. In terms of temperature anomalies, there have been frequent positive deviations in recent years, indicating a gradual warming trend. In precipitation anomalies, there are frequent extreme values, showing no trend. These plots again highlight that temperature changes are progressive and predictable, but precipitation changes are highly variable and unpredictable.
3.3. BEAST Decomposition and Change Point Detection
To examine long-term climate changes in Thohoyandou, the Bayesian Estimator of Abrupt Change, Seasonal Change, and Trend (BEAST) was applied to temperature and precipitation anomalies. BEAST decomposes time series into trend, seasonal, and residual components while detecting abrupt change points using Bayesian model averaging, which accounts for model uncertainty [
37].
Figure 8 presents the BEAST decomposition with panel (a) showing temperature anomalies and panel (b) showing precipitation anomalies. Each panel displays the original anomaly data over time alongside the decomposed components, including trend, seasonality, and identified abrupt change points, allowing for a comparative analysis of how temperature and precipitation patterns have evolved over the 35 years, highlighting significant shifts and underlying dynamics in each variable.
Table 3 summarises the detected trends and change points. Temperature anomalies increase by 0.0250 ± 0.0010 °C per year, with change points detected between 1992 and 2020, indicating accelerated warming beyond normal seasonal variability. Precipitation anomalies show a small upward trend of 0.0037 mm per year, with change points between 1991 and 2024, reflecting occasional abrupt shifts in rainfall patterns.
These results suggest that the temperature in Thohoyandou is rising steadily, with noticeable periods of abrupt warming likely linked to climatic events such as El Niño or anthropogenic influences. Precipitation remains irregular, with sudden changes, which emphasises the difficulty of accurately predicting rainfall patterns. In conclusion, it is important to monitor the changes for climate adaptation strategies.
3.4. Correlation Analysis
Figure 9 shows that the correlation analysis reveals that temperature anomalies are strongly related to temperature (
) and negatively correlated with relative humidity (
), with a moderate positive correlation with dew point. The anomalies have a strong correlation with precipitation data (
), but their correlation with other meteorological data is very weak. The calendar variables (day, month, hour) have minimal correlation with the anomalies. The variability of temperature is systematic and depends on many factors, whereas that of precipitation remains stochastic. These findings support the use of lagged temperature and precipitation anomalies as primary predictors for subsequent feature engineering and LASSO model selection.
3.5. Feature Engineering and Variable Selection
To capture temporal dependencies, lagged features were created: temperature anomaly (lags 1, 2, 3, 168 h) and precipitation anomaly (lags 1, 2, 3, 24 h). Calendar variables and other meteorological covariates (humidity, dew point, cloud cover, wind speed/direction, pressure) were also included.
LASSO regression with five-fold cross-validation selected predictors with non-zero coefficients, where the regularisation parameter
was chosen to minimise the mean cross-validated prediction error.
Figure 10 and
Figure 11 show the results. Temperature anomaly is strongly influenced by lag1, dew point, and lag168, while precipitation anomaly is dominated by lag1, with minor contributions from lag3 and lag24. Calendar and other meteorological variables contribute minimally. This procedure ensures robust feature selection while avoiding overfitting.
3.6. The Models
The dataset was split into 90% for training and 10% for testing. This split was selected to ensure that the models had sufficient historical data to learn the temporal dependencies present in the long hourly time series. Alternative splits, including 70–30% and 80–20%, could also be considered to evaluate the robustness of the modelling framework. These alternative configurations may produce similar patterns in model performance, although the 90–10% split was selected because it provides sufficient data for model training while retaining an independent testing set. Prior to model training, predictor variables were normalised, and LASSO regression was used to select the most significant variables. Hyperparameter tuning was performed using grid search with early stopping to achieve optimal performance while minimising overfitting. Finally, the predictive capability of the models was evaluated on the test dataset to assess their ability to capture temporal dynamics in temperature and precipitation anomalies.
3.6.1. Model Hyperparameter Selection
The optimal hyperparameters for the ANN and LSTM models are presented in
Table 4. These parameters were obtained using grid search combined with early stopping to prevent overfitting. The grid search explored the following ranges: hidden units 32, 64, dropout rate 0.2, 0.3, batch size 32, 64, learning rate 0.001, 0.0005, and the maximum number of epochs 20, 50.
The ANN architecture consisted of two dense hidden layers with ReLU activation functions, followed by dropout layers and a linear output layer. The LSTM model consisted of a single LSTM layer, followed by a dropout layer and a dense output layer. Both models were trained using the Adam optimiser with mean squared error (MSE) as the loss function. Early stopping with a patience of five epochs and a validation split of 0.1 was applied during training. For the LSTM model, the input data were reshaped to a sequence length of one time step.
For the temperature anomaly models, both ANN and LSTM achieved optimal performance with 64 units, a dropout rate of 0.2, and a learning rate of 0.001. For the precipitation anomaly models, slightly different hyperparameters were selected, particularly the number of training epochs and the LSTM learning rate. Reporting these hyperparameters improves the transparency and reproducibility of the modelling framework.
3.6.2. Temperature Anomaly Forecasting
Table 5 shows the predictive performance of the three models, namely, ANN, LSTM, and GAM, on the test set using MSE, MAE, MBE, and MASE metrics. Among the three models, LSTM performed best, with the lowest MSE of 0.458 and MAE of 0.457, demonstrating better performance in handling temporal variations in temperature anomaly data. Though the errors were slightly higher for the ANN model (MSE = 0.568, MAE = 0.546), the GAM model performed moderately (MSE = 0.511, MAE = 0.507).
The MBE values indicate a small positive bias across all models—ANN: 0.062, LSTM: 0.087, and GAM: 0.169—indicating slight overpredictions. All models have MASE values below 1, with LSTM at 0.510, GAM at 0.567, and ANN at 0.610, indicating that all models perform better than a naïve one-step-ahead forecast. Based on the above analysis, it can be concluded that the LSTM model is the most accurate in predicting temperature anomalies, followed closely by the GAM model, and then the ANN model.
In
Figure 12, we plot a comparison of observed temperature anomalies and predictions from all three models. We can see that LSTM predictions have closely tracked actual temperature anomalies, especially during periods of sudden change, whereas ANN predictions have shown larger differences. The predictions from the GAM have shown moderate differences between these two models, sometimes even smoothing out sudden spikes in temperature change. It is also noteworthy that during sudden spikes in temperature, such as during a heatwave or cold wave, LSTM predictions have been more accurate than those from the ANN and GAM models.
The results from the Diebold–Mariano test for differences in predictive accuracy between the ANN, LSTM, and GAM models for temperature anomalies are summarised in
Table 6 and show a statistically significant difference in predictive accuracy between the ANN, LSTM, and GAM models. All three pairwise differences in predictive accuracy are significant at
p-values < 0.001. The positive values of the DM test for the differences in predictive accuracy between the models “ANN vs. LSTM” and “ANN vs. GAM” show that the LSTM and GAM models have a superior performance compared to the ANN model. The negative value of the DM test for differences in predictive accuracy between the models “LSTM vs. GAM ” confirms the LSTM model’s superior performance compared to the GAM model.
This test was carried out using a HAC-corrected method for one-step-ahead forecast errors to account for autocorrelation and heteroscedasticity. It is ensured that the test is statistically sound. As suggested by this test,
Figure 12 demonstrates that the predictions made by the LSTM model closely follow the sudden changes in temperature anomalies compared to the predictions made by ANN and GAM models. This is because the LSTM model is more effective at handling abnormal climatic events such as heatwaves and coldwaves than other models.
In
Figure 13, a comparison is shown between the predictions made by the LSTM model and actual temperature anomalies. The accuracy of the predicted and actual values indicates the LSTM model’s ability to estimate the timing and magnitude of abrupt temperature changes precisely. In addition, the results from the Diebold–Mariano test, which showed high significance (
p-value < 0.001) in
Table 6, along with the performance metrics in
Table 5, demonstrate the efficiency of the LSTM model for climate anomaly prediction.
3.6.3. Precipitation Anomaly Forecasting
The study also identified the optimal hyperparameter settings for the ANN and LSTM models for precipitation prediction. To ensure consistency in comparing the effectiveness of the ANN and LSTM models in forecasting precipitation anomalies, the same hyperparameter tuning methods were used for models trained on both temperature and precipitation anomaly data. As such, the optimal hyperparameters for both models are depicted in
Table 4 and were then used to train the models on the precipitation anomaly data. The models’ effectiveness in forecasting precipitation anomalies is demonstrated by their performance on the test data, which provides a reliable basis for comparison.
Table 7 illustrates the predictive performance of the ANN, LSTM, and GAM models for the test data using MSE, MAE, MBE, and MASE for precipitation anomalies. From
Table 7, we observe that the LSTM achieves the highest performance across most metrics compared to the other two models for predicting precipitation anomalies. For instance, the LSTM has the lowest MSE of 0.187 and MAE of 0.111 compared to the other two models. To be precise, the MSE of the LSTM model is lower than that of the ANN model (0.188) and GAM model (0.216). Similarly, the LSTM model’s MAE is lower at 0.111 than that of the ANN model at 0.127, and that of the GAM model is at 0.124.
The MBE values for the three models are close to zero, indicating that they do not show significant bias in their precipitation anomaly predictions. For example, the ANN model shows a slight positive bias in its precipitation anomaly predictions. This implies that the ANN model overpredicts precipitation anomalies. This is because the MBE of the ANN model is 0.005. On the other hand, the LSTM and GAM models show a slight negative bias in their precipitation anomaly predictions. This implies that the two models underpredict precipitation anomalies. This is because the MBE values for the two models are −0.009 and −0.004, respectively.
In all the models, the MASE is greater than 1. This indicates that none of the models performs better than the naïve model. From the figure above, it can also be observed that the lowest MASE is obtained with the LSTM model (1.873), followed by the GAM model (2.089) and the ANN model (2.141). This indicates that the LSTM model has better predictive power than the other two models, even though the precipitation anomaly values are random.
Figure 14 illustrates the comparison of precipitation anomalies with their predicted values using all models. The LSTM model’s predicted precipitation values are very close to the actual precipitation anomalies, whereas the ANN model shows larger variations. The GAM model can predict the trend of precipitation anomalies, but it cannot capture the sudden variations. The LSTM model performs better than the other two, possibly because it can capture temporal dependencies in precipitation anomalies.
The DM test result shown in
Table 8 suggests that the difference in forecast accuracy between the ANN and LSTM models for precipitation anomalies is not statistically significant (DM = 0.337,
p = 0.736). Since the
p-value is greater than the standard significance levels (0.01, 0.05, and 0.10), the null hypothesis of equal predictive accuracy cannot be rejected. This implies that although there are small variations in the error measures, the ANN and LSTM models have similar forecasting capabilities for precipitation anomalies.
The comparisons with the GAM model are statistically significant, and both the ANN and LSTM models perform better than it (p-value < 0.001). This suggests that machine learning models are more appropriate for precipitation anomaly modelling than the semi-parametric GAM.
The lack of a significant difference in the performance of ANN and LSTM may be due to the high variability of precipitation data, which is often irregular or intermittent, characterised by frequent occurrences of zeros or low values interspersed with sporadic high values. This may be due to the nature of precipitation data, which makes it difficult for even the most complex temporal models to capture precipitation dynamics accurately; hence, the similarity in predictive accuracy between ANN and LSTM.
In
Figure 15, a comparative analysis of the predictions from the ANN, LSTM, and GAM models for precipitation anomaly predictions over three representative segments of the test data set is presented. A zoomed-in version of the predictions has been provided, highlighting the periods of low variability with sharp precipitation increases.
Across all data segments, the predictions from the ANN and LSTM models are comparable, as supported by the non-significant Diebold–Mariano test. Although the LSTM model has been found to track rapid increases in precipitation levels slightly better during moderate precipitation events, the ANN model has been found to smooth predictions. The predictions from the GAM model are much smoother, especially in the middle segment, where they smooth out sharp variations. Although the smoothing effect allows the GAM model to track the overall trend, it tends to respond poorly to rapid increases in precipitation.
In the final section, the extreme precipitation event, all models slightly underestimate the peak magnitude. However, the ANN and LSTM models better capture the timing and shape of the observed anomaly than the GAM model does. These visual results confirm the quantitative analysis, showing the difficulties in modelling intermittent and skewed precipitation anomalies and the benefits of using machine learning models, despite the lack of statistical significance in the differences between the neural network models.
4. Discussion
The results of this study are significant for providing information on how climate change manifests in Thohoyandou. From the BEAST decomposition result, there is an increase in temperature anomaly trend by 0.025 °C every year. This indicates local warming in the study area. This result is consistent with other studies that show that an increase in temperature is one of the clearest manifestations of climate change and is strongly related to human activities, such as greenhouse gas emissions and land surface changes [
2,
3]. The result of this study is significant because local warming is important for understanding climate change, especially because large-scale research on climate change does not always show how it is expressed across regions of the world [
23]. In this regard, this study is significant in providing information on how climate change is being expressed in a small urban centre in Limpopo Province.
These results are also consistent with other results from larger regions within Africa and Southern Africa. For example, ref. [
24] found that Africa is experiencing rapidly rising surface temperatures under low-mitigation scenarios, and Southern Africa is among the regions expected to show a strong response to this effect. This is consistent with the warming trend found within Thohoyandou. The results indicate that the warming trend observed in Thohoyandou is not isolated but part of a larger climatic change that has already been reported in other areas. Although the research subject in this study was Thohoyandou, it may be considered a typical representative of a wide range of small urban centres in subtropical southern Africa with comparable climatic conditions and urban development trends. Hence, the methodological framework of this study may be applied in other cities with comparable climatic characteristics.
It is also important to consider that changes in temperature within the specific area may be influenced by global climate change, as well as by urban development and land-use changes. Urban development and changes in land use could also contribute to increased temperatures in the specific area. However, the fact that the specific study did not directly measure the impacts of urban development on temperature increase should be considered. Nonetheless, the fact that the temperature increase in the specific area is consistent with the broader regional and global increases, as indicated in previous climate change studies [
2,
24].
However, the study area of Thohoyandou could be considered representative of many small urban centres within the subtropical regions of Southern Africa that experience similar climatic conditions and patterns of urban development. Thus, the research’s methodological framework could apply to other cities with similar climatic conditions. However, it is also important to note that factors such as land-use change and geographic factors can influence the extent of climate change. Thus, the research is important and applicable to the case study of Thohoyandou and similar towns that experience similar climatic conditions.
The results for rainfall anomaly revealed a weak positive trend; however, changes are abrupt and extreme. This is in line with other studies that have shown that climate change is often felt as changes in rainfall variability rather than in average rainfall [
8,
21]. In other words, local adaptation strategies should focus more on managing floods, droughts, and rainfall uncertainty than on average rainfall values. The rainfall results also support the difficulty of predicting rainfall using linear trends in subtropical areas, given their intermittence.
The highly irregular precipitation behaviour observed in this study is consistent with earlier research on rainfall variability in Africa. In fact, ref. [
10] demonstrated that short-term rainfall prediction is still a difficult task even with the aid of advanced machine learning techniques, owing to the frequent occurrence of zeros and sometimes extreme values in rainfall data. Similarly, ref. [
20] demonstrated that rainfall prediction using advanced techniques such as LSTMs remains a major challenge compared to temperature prediction. This is consistent with the observation made in this study that precipitation anomalies are much more difficult to predict than temperature anomalies.
The results from the forecasting models also show clear differences in performance. For temperature anomalies, the LSTM model performed better than the ANN and GAM models, with lower prediction error and superior forecast accuracy, as indicated by the Diebold–Mariano test. This result agrees with studies showing that LSTM models are appropriate for sequential data, as they can effectively capture temporal dependencies and nonlinear relationships in the data [
12,
14,
16]. Therefore, the superiority of the LSTM model in this study aligns with the growing literature suggesting that deep learning models can be useful for modelling time series related to climate.
The LSTM model’s strong performance in temperature forecasting has practical implications. For example, precise short-term temperature anomaly forecasts can help local authorities issue alerts on temperature-related issues. It can also help farmers plan agricultural activities during peak temperature stress. In areas like Thohoyandou, where livelihoods are closely linked to local weather, temperature forecasting can help support short-term adaptation planning.
It was also determined that the forecasts of precipitation anomalies were not very accurate. Although the LSTM model produced lower forecast errors than the ANN and GAM models, there was no significant difference between the ANN and LSTM models. Moreover, it was determined that all models yielded MASE values greater than 1, indicating that none performed better than the naïve model in precipitation forecasting. This situation again emphasises how hard it is to forecast rainfall. This situation is consistent with the literature, which states that rainfall is highly skewed, intermittent, and zero-inflated [
10,
20]. It should not be concluded that the models performed poorly in rainfall forecasting in this study. It is necessary to emphasise that precipitation is a very complex phenomenon.
It is also important to acknowledge several limitations of this study. Firstly, the analysis was conducted at a single location, which may limit the generalisation of the findings to other regions with different climatic and land–atmosphere interaction characteristics. Secondly, precipitation forecasting remains particularly challenging due to the intermittent and zero-inflated nature of rainfall data, especially at the hourly scale. As a result, precipitation anomaly forecasts should be interpreted as indicative of elevated risk rather than deterministic predictions.
Future research should extend the analysis to a broader spatial scale, including multiple stations across Limpopo Province, and investigate hybrid modelling approaches that combine physical climate models with machine learning techniques. The inclusion of additional atmospheric and land-surface variables may also improve forecasting accuracy.
The GAM model also plays a significant role in this study. Although the GAM model did not outperform the LSTM model, it was useful as a transparent and interpretable statistical model for comparison. This is particularly important because GAM can handle nonlinear relationships while being easier to interpret than deep learning methods [
18]. Previous research in South Africa has also shown that GAM is useful in drought forecasting and hydroclimatic applications [
19]. For decision-makers who prefer more interpretable models, GAM is a viable option, though its performance is slightly lower than that of advanced machine learning techniques.
These results have significant implications for local climate adaptation strategies. First, the warming trend underscores the need for adaptation measures to mitigate the effects of increased heat exposure. These may include building design, urban shading, and heat-stress mitigation for exposed populations [
22]. On the other hand, the high rainfall variability indicates the need for flexible adaptation options in water management, including stormwater management, rainwater harvesting, and drought management in agriculture. These results also point to the need to use local data in adaptation planning, since local climate risks may not always be captured in large-scale projections [
9,
26].
The research findings from the study have established that the use of a combination of methods, including anomaly detection, BEAST decomposition, machine learning, and statistical modelling, is a useful framework for explaining local climate change in a data-scarce region. This is significant because it contributes to the body of knowledge on climate forecasting and local climate risk analysis. At the same time, the research provides insights that may inform effective strategies for climate change adaptation in Thohoyandou and other urban centres.
5. Conclusions
The study examined 35 years of hourly temperature and precipitation data from Thohoyandou to identify local signs of climate change and assess the effectiveness of various forecasting models. Using the BEAST method, it was established that temperatures increased, with anomalies rising at an average rate of 0.025 °C annually. On the other hand, precipitation was highly unpredictable, exhibiting abrupt, extreme changes without any trend.
In terms of forecasting performance, the Long Short-Term Memory model outperformed the Artificial Neural Network and the Generalised Additive Model in predicting temperature anomalies. However, in the case of precipitation, it proved very difficult for all three models. All three models showed Mean Absolute Scaled Error greater than 1, indicating that none performed better than a naïve model in rainfall forecasting. This is a clear indication of the inherent difficulty of rainfall modelling, given its intermittent and stochastic nature, especially at the hourly scale.
The findings show that the use of anomaly detection, BEAST decomposition, machine learning, and statistical modelling is an important tool for analysing local climate change. The findings also underscore the importance of local-scale research in analysing the impacts of global climate change. The research will be important in giving useful insights to policy and planning circles on how to address the impacts of climate change in vulnerable communities such as Thohoyandou. Future research would be extended to a larger spatial scale, including other stations in Limpopo Province. It would also focus on hybrid modelling frameworks combining physical climate models and machine learning methods. More atmospheric and land-surface parameters would also improve the forecast accuracy.
It is also important to note that precipitation is challenging to model due to its intermittent, zero-inflated nature and strong stochastic properties, especially at the hourly scale. Therefore, anomalies in precipitation forecasts should be viewed as an indication of higher risk and not as deterministic. Additionally, there is a lack of quantification of uncertainty and of probabilistic forecasts.
As future research, it is recommended that the research be generalised to a broader spatial scale, including the entire Limpopo Province. Additionally, the use of more variables from the atmosphere and land surface, and hybrid models that incorporate physical climate and machine learning techniques, should be explored. To conclude, the paper has demonstrated the potential of combining statistical decomposition, machine learning, and interpretable models to advance knowledge of the local impacts of global climate change.