1. Introduction
The agricultural revolution has been actively developing in recent years with the emergence of fourth-industrial-revolution technologies such as next-generation communication technologies, big data, and artificial intelligence (AI). Smart greenhouses have emerged as a solution to many challenges in crop production owing to their ability to monitor changes in environmental variables [
1]. Prediction services focus on the development and evaluation of multi-step time-series forecasting models, with a particular emphasis on deep learning (DL) techniques [
2,
3,
4,
5,
6,
7,
8,
9,
10]. Recent research has focused on forecasting solar energy values per hour [
11,
12,
13,
14,
15]. These prediction services primarily target accurate forecasting of solar energy values based on real-time conditions. These models are capable of making multi-step predictions and accommodating long-term forecasting requirements [
16]. DL models are primarily used to extract valuable information from datasets, enhancing the ability to understand and make decisions regarding solar energy consumption in multifaceted contexts. Forecasting future values in a time series allows us to consider specific contextual variables and make informed decisions based on predictive models. In smart agricultural applications, the capacity to identify anomalies and activate sensors in response to solar energy fluctuations is realized through accurate predictions of forthcoming solar energy values. The analysis of energy forecasts plays a pivotal role in empowering farmers to optimize crop and resource management, thus reducing solar energy inefficiencies and mitigating yield losses [
17].
Nowadays, many researchers are adopting AI and DL methods in their predictive research and applications in their agricultural fields. A study based on CNN and RNN for electric load prediction has shown that convolutional computations used by CNN and feed-forward neural networks are suitable for processing data including various environmental variables for electric load prediction compared to existing models [
18]. Another study using the LSTM model to forecast the energy consumption of buildings has argued that the LSTM model is effective in processing continuous data and capturing long-term dependencies [
19]. This novel approach predicted daily day-ahead energy consumption using forecasted weather data, thereby enabling more accurate and reliable energy consumption forecasts. A study for preventing gas hydrate formation in gas and oil production systems suggested that a DL-based Adaptive Residual Long Short-Term Memory (ARLSTM) model was appropriate for processing time-series data and could capture the dynamic behavior of a gas dataset in its internal time dimension [
20]. The LSTM network is used to address classification model issues related to time-series data and TF-Keras-based algorithms, making it capable of forecasting future temperatures by learning from past temperature data [
21]. Specifically, a model that incorporates time-based coding into recurring forecasting techniques for generating forecasts was introduced, and a conditional advertising network-based data augmentation model was included to enhance the forecasting capability of multi-output models [
22]. A researcher analysis of these DL structures was performed to obtain predictions for horizon 12-ahead, and the accuracy was measured using the determination coefficient of the RMSE [
23]. These services can be beneficial for various applications, including agriculture, solar energy management, and climate control, because temperature plays a crucial role. An accurate temperature forecast enables better decision-making, resource optimization, risk management, and overall improvement in operational efficiency [
24,
25,
26,
27,
28].
This study uses DL techniques to analyze and forecast solar energy from greenhouse and environmental datasets. IoT technology facilitates the connection of devices to the internet, enabling automated operations and the integration of various remote sensors such as solar energy (kWh) and environmental variables. Recent studies have demonstrated the efficacy of IoT systems in improving the monitoring and management of energy and environmental aspects, facilitating real-time data collection and analysis as well as increasing precision rates [
29,
30,
31,
32]. The primary objective of precision agriculture is to enhance crop productivity and reduce solar energy waste using improved spatial management techniques. In this study, deep learning TF Keras time-series models are applied to predict solar energy. DL models have demonstrated the capability to generate accurate predictions, consistently achieving error metrics within the threshold range of 0 to 1 [
33]. The challenge of forecasting continuous future data using a substantial amount of historical data involves tuning hyper-parameters for time-series forecasting. The most fundamental version of this challenge is to predict a multi-step time future. However, a more complex variation involves the prediction of multiple future time steps, which is of particular interest to those seeking predictions based on extensive historical data.
This study explores TF Keras DL techniques, specifically models, to assess their performance in making multi-step forecasts. These models particularly excel in predicting solar energy readings on a smart farm, especially for short-, mid-, and long-term intervals. DL models are employed with reduction algorithms for analysis. Smart farms collect and analyze data from sensors that continuously monitor environmental variables. By constantly measuring global temperatures and collecting data on these environmental variables, the TF Keras Application Programming Interface (API) can be employed to create statistical summaries, extract evolving patterns, and perform predictive analysis. The multi-step time-series stacked-Bi-LSTM has consistently outperformed other approaches. Its flexibility decreases when decision rules are well-defined. This study presents an LSTM deep learning neural network that indicates the model’s ability to capture complex solar energy dynamics in smart agriculture. However, overfitting is a significant concern in the development of models. Therefore, supplying the model with preprocessed data is essential. This highlights the capacity of the stacked-Bi-LSTM algorithm demonstrated in this study to forecast solar energy usage in smart greenhouses, offering valuable insights for practical applications. Furthermore, the predicted energy values align well with the actual values under various conditions, including both short- and long-term forecasting. The experimental results confirm that this model is proficient in multi-time-series forecasting with the best accuracy. Prediction results were compared with TF Keras LM and different methods (CNN, stacked-LSTM, and stacked-GRU models) to evaluate the performance of deep learning models. An error metric evaluation was conducted using the smallest RMSE and MAE values and the highest R-Square value, which indicated a higher prediction accuracy of the model [
34,
35]. These prediction services provide precise and dependable energy usage forecasts for diverse time sequences using advanced time-series forecasting models. As climate change intensifies, maintaining stable greenhouse temperatures has become increasingly critical and expensive for crop growth. Herein, an analysis of short- to long-term seasonal variations in external greenhouse temperatures and the maintenance of consistent internal temperatures tailored to different crop types and growth characteristics is proposed. The proposed model can support the development of solar-energy-related services, including greenhouse policies and cost-effective management plans for both short- and long-term solar energy regulation.
Short-term predictions (hours to days) optimize real-time solar energy systems. Mid-term predictions (days to weeks) aid in maintenance and crop planning. Long-term predictions (months and years) guide infrastructure and financial planning and contribute to environmental sustainability. This demonstrates the effectiveness of the Bi-LSTM model for short- and long-term predictions of greenhouse environmental parameters. The Adam optimizer facilitates the prediction of solar energy consumption by relying on recent greenhouse environmental data. This underscores the greater impact of short-term climate conditions on future trends in greenhouse climate change, highlighting the significance of real-time and near-future predictions for stable greenhouse management.
A novel approach to enhancing solar energy usage prediction in smart agriculture is by implementing multi-timeframe prediction. While solar energy technology has already improved farming practices and crop yields, smart farming is facing new challenges due to climate change. Current methods cannot provide reliable forecasts across different time intervals, which is crucial for optimal greenhouse energy management. Our work fills this gap by using advanced DL models to predict solar energy (kWh) usage across short-term (2-h), mid-term (2-day), and long-term (2-week) intervals.
Our work’s key best prediction model is the application of stacked-Bi-LSTM for multi-timeframe solar energy forecasting. Other deep learning models such as LM, CNN, stacked-LSTM, and stacked-GRU have been limited in providing accurate predictions across different timeframes. Our experiments showed that the stackedBi-LSTM model outperforms these other deep learning models, with RMSE of 0.0048, 0.0257, and 0.0382, MAE of 0.0431, 0.1103, and 0.1460, and of 0.9243, 0.5980, and 0.3974 for short-term, mid-term, and long-term predictions, respectively.
This consistent performance across multiple timeframes proves the model’s robustness and adaptability. By using multi-timeframe forecasting, our approach not only improves the accuracy and reliability of solar energy usage prediction but also simplifies greenhouse energy management. This simplification leads to more energy efficiency, addressing a major challenge in smart farming. Moreover, our method supports the broader goal of sustainable agriculture by optimizing the use of renewable solar energy, thus reducing non-renewable electricity and contributing to climate change mitigation. This interdisciplinary innovation can change the way energy management is performed on smart farms, opening up opportunities for future research in sustainable and efficient agricultural technologies.
The structure of the manuscript is as follows:
Section 2 presents the Materials and Methods used in this research, outlining the experimental procedures and analytical techniques.
Section 3 comprises the Results and Discussion, analyzing and interpreting the findings of the study concerning the extant literature. Lastly,
Section 4 gives a Conclusion and summary analysis that highlights some of this research’s insights, including probable future work areas.
2. Materials and Methods
Data were collected from Naju City Agricultural Technology Center, South Korea.
Table 1 shows data material and description in this study. We utilized DL and its time-series model analysis to examine the influence of environmental factors and solar energy on smart farms. The first step was to prepare the datasets, including training and testing sets. After data preprocessing, we used 124,141 datasets for analysis. Preprocessing is crucial for simplifying the generation of time-series data for deep learning applications. When receiving the input time-series data and specific keyword parameters, such as train size and valid size, the initialization function customizes its operation by creating appropriate sampling windows. These windows delineate the dataset into training 70% and test 30% based on their respective sizes. We handled missing values and selected specific features from the input data as needed. This method also supports cyclic feature generation using the standard method. This method can extract cyclic features such as the day, month, and year from the timestamp. If needed, the data can be normalized using either Min-Max scaling or standard scaling. This method provides preprocessed training, validation, and test sets. The time series spans from June 2021 to November 2023 and comprises a smart farm environmental dataset.
Table 2 displays the calculated descriptive statistics for all key variables, including the mean, median, standard deviation, and interquartile range (IQR). These statistics were computed to summarize the data’s central tendency, dispersion, and overall distribution, as follows:
kWh: The standard deviation is relatively high (7.86), while the average is low, meaning that data points are varied around the mean. The interquartile range (IQR) of 11.50 further indicates a wide range within the middle 50% of the data. F_DATA71: The standard deviation (17.26) is large, and this shows that there is much spread in the data. The IQR of 26.20 supports this, suggesting variability in the central part of the data. F_DATA72: This variable also has a relatively symmetric distribution since it has a mean of 22.76 and a median of 22.33; however, its standard deviation (4.83) and IQR (8.03) indicate less variability than F_DATA71. F_DATA74: With a low mean (10.57), median (8.60), and standard deviation at 10.12, this variable does show some degree of spreading out for its values, which are moderately widespread across different ranges on either side [of zero]. The IQR of 14.40 suggests some variability in the middle range of the data. F_DATA76: This variable has a high mean (1087.53) and median (1037.00) and a standard deviation at 781.26, which indicates that it has dispersed data points [mean value ± std]. The high IQR (1161.91) shows a large spread between the 25th and 75th percentiles, which means values in the middle range fluctuate considerably; this can indicate outlier observations or a wide distribution of scores. F_DATA78: This variable has a symmetric distribution, as the mean and median are very similar (15.94 and 15.93). The slightly larger standard deviation (10.02) hints a bit at the benchmark not having very tight distributions around the mean. An IQR of 16.32 hints that the data in the middle part have values that are more or less spread over a moderate range.
2.1. Analysis and Performance Correlation of Solar Energy and Environmental Data Evaluation
This dataset was collected from a study conducted in a paprika greenhouse. The dataset consists of observations gathered from a greenhouse environment and includes four distinct variables. The lists of paprika greenhouse solar energy and environmental factors, along with the processing steps shown in
Figure 1, serve as inputs for the prediction models used in this study. The purpose of utilizing this dataset was to analyze and evaluate prediction models that can forecast and estimate certain outcomes and variables based on the given input factors. Time-series analysis focuses on solar energy usage based on internal and external environmental factors and daily recorded data for smart farming.
Figure 2 illustrates the solar energy dataset, where additional features are derived from the time-series variables. These variables include data collected from June 2021 to November 2023. Solar-energy-intensive heating and cooling systems are essential for greenhouse cultivation, as they aim to create the ideal conditions for plant growth during crop growth days. A comparative analysis of solar energy and environmental variables in
Figure 2 reveals a significant disparity, with energy usage consistently surpassing greenhouse levels throughout the year. In
Figure 2b, inside temperature fluctuations during specific months are depicted, with energy levels exceeding 25 kWh in hotter seasons and dropping as low as 26 °C in summer periods. In July and August, outside temperatures often exceed 30 °C, potentially limiting the growth of certain crops cultivated outside. The temperature pattern in the greenhouse exhibited a strong time-dependent component. From May to September, the internal temperature of the smart farm remained consistently high. As shown in
Figure 2f, in July and August, the greenhouse temperature increased early in the morning due to increased outside temperature; therefore, the humidity level increased significantly.
The air conditioning system operates every 20 min to maintain an internal temperature between 26 °C and 30 °C, even when solar energy, as shown in
Figure 2a,b, ranges from 5 kWh to 15 kWh. However, despite these temperature control efforts,
Figure 2d indicates that the humidity levels remain exceptionally high, peaking at 80–90% throughout South Korea in July and August. Furthermore,
Figure 2e reveals that the average wind speeds are higher during the evening and night-time hours, with variations due to changing climate conditions. As shown in
Figure 2c, the solar radiation heat power peaks from June to August, exceeding 1600 (W/m
2), and the average daily solar radiation heat power during this period is 1000 (W/m
2). This difference of 1500 (W/m
2) represents approximately 35% of the maximum solar radiation heat power savings in July. Maintaining stable solar energy is crucial for aligning crop growth patterns, as the summer months result in significantly elevated electricity costs. The improper management of intense solar radiation can lead to heat stress and damage to crops. Elevated humidity levels during both the summer and winter months increase the risk of plant disease spread, posing a significant challenge for greenhouse cultivation. This analysis sets the stage for examining solar energy variations and seasonal shifts, as shown in
Figure 3.
As shown in
Figure 3, the daytime temperatures exhibited remarkable stability during autumn. From September to November, solar energy decreased from 17.5 kWh to 1.5 kWh, whereas
Figure 2b shows the inside temperatures dropped from 23 °C to 10 °C. Inside temperatures remained consistently stable during this period, with night-time temperatures in the greenhouse experiencing an approximate 6 °C increase compared to outside temperatures. Moving into winter, specifically from December to January, the greenhouse maintained stable energy usage at 0–17 kWh, as shown in
Figure 3. By contrast, outside temperatures on a typical winter day plummeted to −15 °C. Air temperatures fluctuated between 20 °C and −10 °C, yet the greenhouse humidity remained constant, consistently averaging between 40% and 60%. Spring brings about a shift in climate; the outside temperatures influenced by the year 2023 from March to May fluctuated from 0 kWh to 20 kWh. However, in July and August, the energy usage decreased from 0 to 15 kWh. Evenings witness rapid cooling of outside temperatures, reaching freezing levels at night.
By contrast, the greenhouse maintained temperature and humidity stability, averaging between 15 and 20 °C and 40 to 50%, respectively. As depicted in
Figure 3, the climate performance exhibited seasonal variations, resulting in distinct solar energy. To evaluate the system’s 24-h performance under varying temperature conditions, hourly outside temperature data from the greenhouse were utilized.
Figure 2 and
Figure 3 present the projected outcomes, encompassing both inside and outside temperatures, energy differentials, and the corresponding system output across a complete 24-h day cycle for all seasons. The x-axis represents the time within this 24-h cycle.
An analysis of
Figure 3 reveals consistent temperature distributions and internal humidity trends over multiple days. The greenhouse temperature began to increase at approximately 6:00 AM, coinciding with sunrise, driven by a significant surge in solar radiation. The peak temperature difference and theoretical output typically occurred around midday, between approximately 2:00 and 3:00 PM, which is attributable to the strong greenhouse effect that intensifies temperatures at the warmer end. This continuous temperature increase continues until midday. As the day progresses, the greenhouse solar energy warmer and cooler areas gradually cool and stabilize during the night.
The correlation matrix outlines the interrelationships among various variables that are likely associated with energy consumption (kWh) and weather information. The symmetric nature of the matrix, with diagonal values consistently set to 1, signifies the perfect correlation of each variable with itself. The correlation coefficients, ranging from −1 to 1, illuminate the magnitude and direction of linear associations between variable pairs. Positive values denote a positive correlation, indicating simultaneous movement in the same direction, whereas negative values indicate a negative correlation, suggesting movement in opposite directions. As can be observed from the heatmap in
Figure 4, there are correlations between different weather-related variables and kWh. Moderately, kWh has a positive relationship with F_DATA72 (0.47), while it negatively correlates with F_DATA71 (−0.29) but has weak relationships with other variables such as F_DATA74, F_DATA76, and F_DATA78, ranging from −0.12 to 0.26. Notably, the two of them (F_DATA72 and F_DATA78) show a very strong positive correlation (0.87), which means that they are closely associated with each other. Overall, some weather factors have moderate relationships with electricity usage, while others have little effect as stand-alone characteristics, according to this heatmap.
2.2. TF Keras Linear Model
Linear models have a neural network with just a single Dense layer. A neural network can explain some key terms. The data put in (x) has one feature (multiple nodes or circles labelled), known as the Dense Layer: A single node or rectangle labelled (Dense or Linear), and what we obtain (Y) is a single number (the model’s prediction).
Y is the output or prediction.
W is the weight vector or matrix.
x is the input vector.
b is the biases term.
The number of inputs is “n”.
An LM of a neural network with time series data will be learned using TensorFlow Keras to predict future time steps [
36].
Figure 5, first, defines a sequential model. Use of a lambda layer inside the model pulls off the last time step from the input tensor. This reduces the input shape from [batch, time, features] to [batch, 1, features]. The next layer applied is a Dense layer whose weights are zeros, transforming the data to a shape [batch, 1, out_steps*features]. It delivers, according to the set prediction horizon, the desired number of output features. Consequently, a Reshape layer configures this output to the form [batch, out_steps, features], making it compatible with those dimensions in the label set. It is a structured methodology that provides the model with the capability to use the most recent data in predicting future values [
37,
38].
2.3. Convolutional Neural Networks
In CNN’s work on multi-step time-series regression, various approaches have been proposed for utilizing CNNs. The features are fused through multiple layers to facilitate the regression. In CNN’s work on multi-step time-series regression, alternative methodologies have been suggested. These included dividing single and multiple time sequences uniformly for individual feature learning, which achieved good regression performance in experiments [
39]. However, this model has a notable limitation in that it cannot reveal correlations between different stochastic time series. To overcome this drawback, the algorithm is as follows: Instead of learning individually, we collectively trained on multiple time series to extract features. The CNN model differs from the multi-step model because it can be used as an input of any length. The convolutional layer was applied using a sliding window for the inputs [
40].
The CNN model for multi-step time-series regression is as follows:
Lambda layer: ‘conv_with’ time steps rom input x and shape [batch_size, conv_width, features]
1D Convolutional layer: kernel of size conv_width and 256 filters and shape [batch_size, 1, 256].
W = weight, b = biases
Dense layer: connected layer to reduce the dimensionality to the desired output size, ‘out_step * features’.
Reshape layer: the output into the desired shape [batch_size, label_width, label_feature _number], where
. The CNN model for a multi-step time series is as follows:
Figure 6 shows how the CNN class, built on TF Keras API and inheriting from Modeling Class, constructs a CNN model tailored to time-series data [
41]. Input features are structured as [batch, time, features], with batch denoting sample size, time representing time steps, and features signifying input characteristics [
42]. The model employs a sequential container to organize layers, starting with a lambda layer extracting the last conv_width time steps. A Conv1D layer follows, utilizing 256 filters and ReLU activation, and transforming the input to [batch, 1, conv_units]. Subsequently, a Dense layer reshapes output to [batch, 1, out_steps * features], with out_steps indicating predicted time steps. The initialization of the Dense layer with zeros precedes the Reshape layer, aligning the output to [batch, out_steps, features] for accurate predictions. This architecture implements CNN-based time-series forecasting within TensorFlow and offers a robust method for predicting future values.
2.4. Stacked LSTM
The initial segment delves into RNNs, emphasizing their suitability for managing continuous data in the context of smart farming, particularly concerning solar energy and temperature for plant growth in time-series forecasting [
43]. This underscores the temporal dependence of the data, where both past and present data contribute to the RNN structure [
44,
45].
Figure 7 illustrates the subsequent section and introduces the stacked LSTM model crafted for sequence-to-sequence prediction using TF Keras API. This model, specifically designed for time-series forecasting tasks, organizes input features as [batch, time, features], where batch represents sample size, time signifies time steps, and features denote input characteristics [
46]. Implemented within the stacked-LSTM class and inheriting from Modeling Class, the architecture consists of stacked-LSTM layers within a sequential container. The initial LSTM layer, comprising 10 units, captures temporal dependencies by returning sequences [
47]. To prevent overfitting, a dropout layer with a 0.2 rate is applied, followed by another LSTM layer with 5 units and another dropout layer. The output is reshaped by a Dense layer into [batch, out_steps * features], with out_steps representing the number of output time steps to be predicted and label_feature_number indicating the features used for prediction. Initialized with zeros, this Dense layer is reshaped by a Reshape layer into [batch, out_steps, features] and aligned with the desired prediction format. This architecture captures temporal dependencies adeptly, enabling accurate predictions of future values based on input time-series data in a rigorous manner, as follows:
Stacked-LSTM: Input Sequence.
H is a hidden state:
first LSTM layer (first-time step):
Shape: [batch_Size, time_steps, 10]
Dropout layer: Dropout 20% of the LSTM output to prevent overfitting.
Second LSTM layer: Further processes the sequence, collapsing the time dimension.
Dropout layer: Dropout again to prevent overfitting. Formula:
Dense layer: output into the final prediction.
Reshape layer: the output into the desired format. Formula: ,
Stacked-LSTM to multi-step time series is as follows:
2.5. Stacked-GRU
The stacked-GRU model is specifically designed for multi-step time-series forecasting, capitalizing on the inherent strengths of the GRU architecture and the strategic stacking of multiple GRU layers. This approach exhibits exceptional performance in capturing long-range dependencies and accurately predicting multiple future time steps [
48,
49,
50]. Extensive experimentation and comparisons with existing methods underscore the superiority of the stacked GRU model in managing time-series data and architecture [
51]. A notable feature of the GRU model compared with traditional neural networks is its remarkable ability to retain long-term information while significantly reducing the number of tuning parameters, rendering it a compelling choice for various complex tasks [
52].
Figure 8 illustrates the implementation of the stacked-GRU class, inheriting from the Modeling Class, which offers a robust solution using TF Keras API. The GRU models excel in sequence-to-sequence prediction tasks, making them particularly suitable for time-series forecasting. Input features follow a structured format of [batch, time, features], with batch denoting sample size, time representing time steps, and features indicating input characteristics [
53]. The model architecture, encapsulated within a sequential container, comprises multiple stacked-GRU layers. Initially, a GRU layer with 10 units efficiently captures temporal dependencies by returning sequences [
54]. A dropout layer with a 0.2 rate is then introduced to mitigate overfitting. Another GRU layer with 5 units is added, followed by another dropout layer. A Dense layer reshapes the output into [batch, out_steps * features], where out_steps represents the number of output time steps to be predicted, and label_feature_number signifies the features used for prediction. This Dense layer is initialized with zeros; ultimately, a Reshape layer aligns the output with the desired prediction format, reshaping it into [batch, out_steps, features] [
55]. This meticulously crafted architecture empowers the model to capture long-range dependencies and deliver accurate predictions of future values based on input time-series data in a rigorous manner, as follows:
Input sequence X with shape [ batch_size, time_steps, features].
[batch_size, time_steps, features].
The number of units in the first GRU layer is 10.
The number of units in the second GRU layer is 5.
The dropout rate is 20% (0.2).
The output is reshaped into a shape defined by label_width and label_feature_number.
Shape: [batch_size, time_steps, 10]
Reshape layer: ,
Stacked-GRU to multi-step time series is as follows:
2.6. Stacked Bidirectional LSTM
The stacked-Bi-LSTM model, designed for sequence-to-sequence prediction, is derived from the Modeling Class within the Tensor Flow’s Keras API [
56]. Employing a bidirectional LSTM architecture, this model is constructed using a model-building method. Dropout layers for regularization follow the bi-directional LSTM layers, whereas a Dense layer and Reshape layer are incorporated to streamline the output dimensionality and achieve the desired output format [
57]. Parameters like the number of LSTM units, dropout rate, and layer architecture can be customized through class attributes, such as self.map dataset.label_width and self.label_feature_number. The constructed model was used for subsequent training and evaluation. A unique feature of the model is the binomial nature of LSTM layers, which enables it to capture information from past and future time steps [
58,
59], thus enhancing its understanding of temporal dependencies in the input sequences. The stacked-Bi-LSTM class, inheriting from the Modeling Class, implements a stacked bi-directional LSTM model using TF Keras API [
60].
Figure 9 shows, structured as [batch, time, and features], the input features, consisting of batch representing the number of samples, time denoting the time steps, and features indicating input features [
61]. In the model architecture, a sequential container houses multiple Bi-directional LSTM layers stacked on top of each other [
62]. Configured with 10 units, each Bi-directional LSTM layer returns sequences to comprehensively capture the temporal dependencies. A dropout layer with a 0.2 rate follows each Bi-directional LSTM layer to prevent overfitting and enhance generalization. Finally, a Dense layer reshapes the output into [batch, out_steps * features], where out_steps denotes the number of output time steps to be predicted, and label_feature_number signifies the number of features used for prediction. This Dense layer is initialized with zeros, and a subsequent reshaping layer reshapes the output into [batch, out_steps, feature], aligning it with the desired output format for prediction [
63,
64].
This architecture equips the model to effectively learn and exploit temporal dependencies in input time-series data, thereby facilitating the accurate prediction of future values rigorously.
Stacked-Bi-LSTM: Input Sequence. Formula: and Shape: [batch_Size,time_steps,20], 20 comes from 10 units in the forward direction and 10 units in the backward direction.
Dropout layer: Dropout 20% of the BiLSTM output to prevent overfitting. Formula: .
Second Bi-LSTM layer: Units: 5 (in each direction, forward and backward), to further processes the sequence, collapsing the time dimension. Formula: and shape: [batch_size, 5].
Dropout layer: Dropout again to prevent overfitting. Formula:
Dense layer: output into the final prediction. Formula. and shape [batch_size, out_steps * features]
Reshape layer: the output into the desired format. Formula: .
Stacked-Bi-LSTM to multi-step time series is as follows:
2.7. The Tunable Parameters
The proposed model highlights the significance of hyper-parameter tuning in training deep learning models, specifically linear models, CNNs, stacked-LSTM, GRU, and stacked-Bi-LSTM architectures. Hyper-parameters play a crucial role in shaping model performance and generalization capabilities [
65]. In this study, we used manual hyper-parameter tuning to improve the performance of a deep learning model. This approach, though time-consuming, allowed us to make informed and precise adjustments to key training parameters. We systematically explored a range of hyper-parameters to optimize model performance. A range of hyper-parameters is systematically explored to enhance the model’s effectiveness. The sampling window (30), configured with a designated value, facilitates data segmentation into defined units, which is particularly relevant for processing time-series data. By setting Addcyclics to False, the model avoids incorporating cyclic features into the input data, preserving the intrinsic data structure. Enabling normalization through the normalize hyper-parameter with a Min-Max Scaler type ensures consistent data scaling. The definitions of the input and output features based on the time steps align with the architectural requirements of the model. Adopting a sequence stride of 1 ensures the generation of sequences with overlapping and consecutive windows, thereby enabling the effective capture of temporal patterns. The training process integrates essential hyper-parameters such as epochs (200), batch size (2**7), learning rate (0.0001), and early stopping patience (10) epochs to prevent stagnation [
66,
67,
68,
69,
70,
71,
72,
73]. The choice of the MSE as the loss function and the utilization of the MAE, RMSE, and
as the evaluation metrics underscore the commitment of the model to accurate performance assessment. The emphasis on hyper-parameter tuning strategies, as depicted in
Table 3, underscores their pivotal role in achieving the best model performance across diverse tasks, highlighting the integral role of hyper-parameter tuning in attaining optimal outcomes.
2.8. Scoring Metrics
Performance measures are particularly important to evaluate the accuracy and efficiency of time-series analyses used in deep learning models; RMSE, MAE, and
are used to predict performance in this model. A prediction error is the estimation of lower RMSE and MAE values. A model with an R-squared value close to 1 suggests a strong fit to the data. This value always falls between 0 and 1 [
74,
75].
The number of points is n;
is the actual value,
is the predicted value. These performance measures use time series with DL models, allowing practitioners to make informed decisions regarding model selection and offering insights into the reliability of predictions [
76].
2.9. Computational Requirements
DL algorithms in the Jupyter Notebook (6.4.12) were run using Python code. During training, network convergence was accelerated by using the Adam optimizer. The imported packages support deep learning and training models, TensorFlow and TensorFlow Addons; for handling and preprocessing data, Pandas and NumPy; and for visualizing results, Matplotlib and Seaborn. Scikit-learn was used for evaluating model performance and normalizing data. The following desktop system was used: with Intel(R) Core (TM) i7-6700 CPU @ 3.40 GHz processor, Windows 10 Education, 32 GB RAM and NVIDIA GeForce GTX 1060 3 GB.
3. Results and Discussions
The proposed multi-step time-series forecast models include a simple method created for these data. These models stand out as the only ones capable of forecasting the value of multiple features in a short time step, specifically within an hour, based on current conditions. In this study, utilizing hyper-parameters, the models forecast the solar energy (kWh) value for several days, covering short-, mid-, and long-term periods in the future. The hyper-parameter forecast results of the proposed LM, CNN, stacked-LSTM, stacked-Bi-LSTM, and stacked-GRU were compared with those of DL models utilizing error metrics, and the prediction performances were assessed. The calculated error metrics included RMSE, MAE, and. Small error metric values demonstrate higher prediction accuracy. Except for the persistence approach, which only uses data from a previous timestamp as a forecast result, the average computing time for each prediction point was recorded for all the comparison methods. The proposed deep learning mode architecture, with a reasonable processing time, outperformed all other comparative forecasting algorithms on average and in most circumstances. The proposed framework had slightly higher metric values for the greenhouse. According to the prediction outcomes, the DL approaches are more suitable for describing solar energy data.
A Dense layer, utilizing the TF Keras library within the DL framework, is designed to modify the last axis of the input data, which typically consists of batch size, time steps, and features. In this context, the input shape is defined as a window of short-, mid-, and long-term steps, as represented by (128, 24, 6). After passing through the model layers, the output shape is transformed into various hourly step windows: (128, 2, 1), (128, 4, 1), (128, 6, 1), (128, 48, 1), (128, 96, 1), (128, 144, 1), (128, 336, 1), (128, 672, 1), and (128, 1008, 1). This layer is employed individually for each object within the volume and time series. The multi-step model, akin to the three periods provided, is executed over a 48-h (h) timeframe. The CNN model forecasted solar energy usage windows, exhibiting clearer predictions than the energy model most of the time. However, the stacked-LSTM model resembles a stacked-GRU because it incorporates multiple Dense layers between the input and output. Basic, linear, and dense samples are processed independently in each iteration, using several time steps as inputs to generate an output. The models create sets of 48-h inputs and short-, mid-, and long-term labels, employing a DL architecture, as depicted in
Figures S1–S3. In addition, the recurrent layer accepts multiple time steps as inputs, facilitating the generation of LSTM windows for practice and evaluation. The stacked-Bi-LSTM serves as a window generator, introducing extra input time steps to align with the label and forecast length, as illustrated in
Figures S1–S3. The forecasts in this section were based on the previous three periods. RNNs, particularly LSTM, are a suitable neural network type for time-series analysis. It sequentially processes time-series data and maintains an energy state from one step to the next. By default, the stacked-Bi-LSTM layer provides the final time result, thereby enabling time-based predictions. However, when the ‘return_sequences’ parameter is set to true, the layer outputs each input, which is beneficial when dealing with GRU layers and concurrent training on 144-time steps. This ‘return_sequences’ setting is illustrated in
Figures S1–S3, where a time-series model is trained on up to 48 h of data.
3.1. Keras Architectures
The architecture shown in
Figures S1–S3 encompasses the layers designed for LM. It initiates with an input layer handling the data shape (none, 48, 6), followed by two lambda layers preserving the input shape. Subsequently, the data were reshaped to (none, 1, 6) before traversing a Dense layer, resulting in (none, 1, 2). Finally, the data were reshaped to (none, 2, 1) to complete the process. The DL model architecture detailed in
Figures S1–S3 in the Supplementary Material encompasses various tailored variants for precise sequence-to-label predictions. The model commenced with an input layer of dimensions (none, 48, and 6), representing the batch size, time steps, and features. It traverses a sequence of layers, including lambda, Conv1D, dense, and Reshape layers, with an input sequence length of 48 and a layer configuration of 6. Following this, three subsequent Dense layers are configured for short- to long-term predictions, succeeded by a Reshape layer. These configurations produce output shapes aligned with label compatibility ranging from (none, 2, 1) to (none, 1008, 1). For
Figures S1–S3, where the input sequence length is 6, the configurations entail a layer set to 10 units, a Dense layer for short-, mid-, and long-term predictions, and reshaping to 1. These settings apply to both the LSTM and GRU models.
Figures S1–S3 incorporate a bi-directional LSTM layer with 20 units, followed by dropout layers for regularization. Another bi-directional LSTM layer further reduces the output to 10 units, followed by additional dropout layers. Finally, a Dense layer with short- to long-term units yields an output shape suitable for accurate predictions within the given label format.
3.2. Short-, Mid-, and Long-Term Predictions
This research used five algorithms (
Figures S4–S6) and concentrated on RMSE, MAE, and R-Square. Short-term and long-term hyper-parameter methods showed slower convergence. On the other hand, the algorithm in
Figure 10a has better predictive performance with faster convergence rates. Stacked-Bi-LSTM and GRU algorithms are above others in terms of faster results and more precision.
Figure 10 is a benchmark that demonstrates the efficiency to which stacked-Bi-LSTM is superior to LM, reducing the risk of local minimum traps while achieving quite high levels of accuracy at all times. Concerning fluctuations in solar energy forecasts, GRU outdoes linear models based on normal kernels, but CNN does so more effectively for optimization and prediction stability. Short term:
Figure S4a–c demonstrates training and validation versus epochs implying hyper-parameter tuning, architectural adjustments, and regularization techniques for optimization purposes. One such approach, as illustrated by stacked-Bi-LSTM, is consistently good, although models like LM or CNN may need strategies to reduce bias towards overfitting. Mid-term: Different patterns are depicted by
Figure S5a–c, with weaker convergence rates being indicated by algorithms a and b while
Figure 10 shows improved convergence for the three time steps. Iteration efficiency improves while accuracy increases through the use of stacked-Bi-LSTM rather than any other methods like LM, LSTM, or GRU.
Long-term: The stacked-Bi-LSTM is shown to have higher predictive energy and more general applicability than LM and CNN models, with the former’s MAE values being larger, while the latter has problems of overfitting. The RMSE profiles in
Figure S6a–c are not as good, except for
Figure S6c, which shows its faster convergence. Higher R-squared values indicate the best accuracy, but this requires the longest computation time. Optimization methods are important to improve generalization capability and minimize overfitting. From all time steps,
Table S1 implies that the most generalized form of stacked-Bi-LSTM has the lowest RMSE values at each step. Despite yielding higher mistakes, this model remains a powerful tool for capturing complex temporal dependencies with fast processing times and attaining competitive accuracy rates. Stacked-LSTM is recognized as a desirable foundation for load forecasting.
Table 4 and
Figure 11,
Figure 12,
Figure 13 and
Figures S7–S9 exhibit similar trends of performance across hourly time steps, except that stacked-Bi-LSTM provides the smallest MAE values (0.0367, 0.0374, and 0.0431 for training, validation, and testing, respectively) while others like LM, stacked-GRU, and stacked-LSTM, as well as CNN, perform poorly in comparison to it. Yet, regression LM and CNN models were not successful at the first stages because of their complicated network structures, which made their training as well as inference quite lengthy since they had plenty of hidden layers involving dense connections.
For mid-term predictions (2 days), CNN offers the best balance of accuracy and efficiency, boasting a low RMAE of 0.0451, an MAE of 0.1565, and a higher R-Squared of 0.2874, as well as the shortest computation time of 198.26 s. Stacked-BiLSTM offers slightly better accuracy but at a significantly longer computation time of 1650.47 s. For long-term predictions (1 month, 11 days), CNN remains the most efficient, with a low RMAE of 0.0505, an MAE of 0.1736, a higher R-Squared of 0.1973, and the shortest computation time of 375.35 s. Stacked-Bi-LSTM has better accuracy (MAE of 0.2198) but requires more time (125.35 s), while LSTM and LM show lower accuracy and longer computation times.
The proposed model is intended to ease the development of solar-energy-related services such as policies and equilibrium plans on greenhouse solar energy. This will be achieved through forecasting short- to long-term solar energy usage for maintaining an internal greenhouse environment. This study considered multi-step time-series forecasting models, which involved fundamental methodologies as well as advanced TF Keras DL approaches like LM, stacked-LSTM, CNN, stacked-GRU, and stacked-Bi-LSTM. Error-metrics-based evaluation showed that DL models generally gave more accurate predictions, with the best performer being stacked-Bi-LSTM compared to LM, CNN, and GRU. To predict complex patterns and prevent overfitting, this model combined bi-directional LSTM units, which capture both forward and backward temporal dependencies with dropout regularization. Consequently, in greenhouse solar energy, forecasting the stack Bi-LSTM produced very high performance even at different prediction horizons. In smart greenhouses, DL time-series algorithms have exhibited significant potential in improving Short-Term Load Forecasting (STLFs) while they are also adaptable to time-series data. Also, the study developed a periodic coding technique aimed at enhancing the interpretability of the time-series model leading to improved prediction accuracy. For all models, hyper-parameter tuning was vital in achieving optimal performance. The LM model is easy to use, and that makes it a good starting point for evaluating more advanced techniques. The applicability of the stacked-Bi-LSTM model with improved accuracy and reduced computational requirements highlights the significance of high-quality data in reliable results on greenhouse energy optimization. It should be noted that some areas require future work, such as improvement of architecture of models, exploration of hybrid methods, and scalability and adaptability to new datasets and real-world applications.
The optimal timeframe for stable greenhouse temperature control through solar radiation prediction is over the short term, especially over two hours. This timeframe has the highest accuracy (RMSE = 0.0048, = 0.9243), which makes it suitable for immediate and precise climate control in greenhouses. Solar energy predictions favor spring and summer times more compared to other seasons. These periods offer higher and consistent solar radiation with longer daylight hours, as well as intense sunshine that enable dependable predictions to be made continuously. To obtain maximum efficiency from the use of solar energy in greenhouses, there should be seasonal conditions at their best combined with making short-term forecasts.
One big issue regarding the greenhouse’s internal temperature stability concerns predicting exactly how much solar energy will affect them over different periods, since external atmospheric conditions change often within twelve months. This becomes worse when we talk about variations by season—shorter daytime duration and weaker sunlight during autumn and winter result in higher unpredictability levels than any other time of year. Inaccurate forecasts of solar energy may impede proper crop growth, or low-level energy usage at times of poor climate control in a greenhouse setting may lead to poor yields. Thus, it becomes difficult to balance the need for accurate short-term adjustments with long-term predictions that are uncertain and at the same time accommodate solar availability seasonality. A complex approach is necessary to achieve constant greenhouse temperature under varying solar energy and seasonal changes. Precise real-time climate control can be achieved by using high-accuracy short-term forecasting models, especially with a 2-h prediction window. Seasonal calibration of these models enhances reliability during periods of higher solar predictability, like spring and summer. Also, incorporating hybrid energy systems that combine solar power with supplemental heating or cooling guarantees consistency in less predictable seasons such as autumn and winter. To support consistent inner temperatures and optimize year-round crop growth, real-time monitoring as well as automation systems alongside energy storage solutions should be applied.
4. Conclusions
This study aimed to propose an optimal smart farm solar energy use strategy by analyzing solar energy usage in time steps (short-, mid-, and long-term) considering seasonal external temperature and environmental fluctuations to provide consistent internal greenhouse temperature in line with crop type and growth attributes in smart farms. The proposed model can be used to develop solar-energy-related services, including greenhouse solar energy policies and solar energy balance schemes, as it can predict the cost of solar energy in time steps to maintain constantly optimized temperature for crop growth. Through evaluation of single- and multi-step time-series forecasting models, which include LM, CNN, stacked-LSTM, and stacked-GRU, stacked-Bi-LSTM outperformed others in solar energy usage forecasting in time steps. The stacked-Bi-LSTM architecture consistently demonstrated excellent performance and effectively captured intricate temporal patterns. As a result, the proposed model can be useful for supporting more sophisticated solar energy use predictions depending on the growing season of the user’s crop and effectively planning energy use balance policies in smart farms.
The performance of models is determined by speed and accuracy. In general, CNNs are faster and better for short-term predictions than LSTMs and BiLSTMs, which are suited for long-term forecasting, albeit at slower speeds. GRUs offer an intermediate solution with faster computation, though at times slightly lower accuracy compared to LSTMs. These are the best for balancing forecast horizon, efficiency, and accuracy while choosing the right model for time-series prediction tasks.
Data: The data in this study are related to solar energy and the environment. This indicates how it is related to climate changes and ecological changes without a greenhouse. Deep Learning Models: Using deep learning models to analyze data tells us how to accurately and deeply predict the problem of information. Through this, the data can be subtly understood.
Method: This study utilized deep learning models like stacked-Bi-LSTM for solar energy prediction. Though the stacked-Bi-LSTM model had strong results, this study is called into question because its exploration is partially limited by a dependency on particular models and methodologies. Evaluate the accuracy and efficiency of time-series analyses used in deep learning models, RMSE of 0.0048, MAE of 0.0431, and of 0.9243 are used to analyze model performance.
Scope: In this study, mainly focused on multi-timeframe forecasting for solar energy as well as the environmental parameters regarding the smart farm data.
Future work needs to overcome these hurdles with the integration of a diverse set of data and enriched model architectures and adopt hybrid module designs while testing the scalability and transferability to real environments.