Abstract
Under the influence of the coronavirus disease and other factors, agricultural product prices show non-stationary and non-linear characteristics, making it increasingly difficult to forecast accurately. This paper proposes an innovative combinatorial model for Chinese hog price forecasting. First, the price is decomposed using the Seasonal and Trend decomposition using the Loess (STL) model. Next, the decomposed data are trained with the Long Short-term Memory (LSTM) and Seasonal Autoregressive Integrated Moving Average (SARIMA) models. Finally, the prepared data and the multivariate influence factors after Factor analysis are predicted using the gated recurrent neural network and attention mechanisms (AttGRU) to obtain the final prediction values. Compared with other models, the STL-FA-AttGRU model produced the lowest errors and achieved more accurate forecasts of hog prices. Therefore, the model proposed in this paper has the potential for other price forecasting, contributing to the development of precision and sustainable agriculture.
Introduction
Agricultural product prices are affected by various factors, such as production costs, substitute prices, and market environment. The fluctuations in agricultural product prices will increase stakeholders’ risk in producing and supplying agricultural products. The risk can affect producers’ motivation, change consumers’ purchase costs, and is not conducive to government regulation of the market and the long-term development of agricultural production. In particular, the coronavirus pandemic 2020 hit the economy and the agricultural product supply chain, causing large fluctuations in agricultural prices [1]. The Russia-Ukraine war that erupted in 2022 exacerbated these problems and jeopardized global food security, with rising prices of major agricultural products and changes in energy prices even affecting political stability worldwide [2]. Based on the historical data on agricultural prices and related influencing factors, it is of great reference significance to accurately predict the changing trend through scientific mining and analysis of the changing rules of agricultural prices.
As a common meat agricultural product, pork is the largest-produced and most-consumed meat in the world; China is the largest pork-producing and consuming country globally [3]. However, hog prices have been exceptionally volatile over the past ten years, negatively affecting consumers and related farmers. The lowest cost was 10.07 yuan per kilogram in the 19th week of 2018, and the highest was 40.19 yuan per kilogram in the 44th week of 2019. The fluctuation between the highest and lowest prices is close to 300%. Accurate prediction of pig prices is a challenge. Therefore, conducting in-depth research on the law of pig price fluctuation is essential in establishing scientific and practical price prediction models and methods for the healthy development of the pig industry and agriculture.
In previous studies on price forecasting, agricultural price forecasting has been the subject of many papers, and much research has been done on factors affecting agricultural prices and price transmission mechanisms, etc. [4, 5]. For constructing time series combination models, most of the traditional studies decompose the time series into linear and nonlinear components and then use different models according to the characteristics of the components. The final forecasting results are the superposition of the predicted values of each model. However, when the price series are too volatile by external factors, the prediction results of traditional combination methods are not very satisfactory. They may even be less accurate than those of individual models.
Therefore, according to the time series characteristics and multi-factor influence characteristics of agricultural price data, this paper proposes the STL-FA-AttGRU combination model. The flow chart of this study is shown in Fig. 1. The STL model has good stability for outliers and is used for the preliminary decomposition of time series data. The trend, seasonal, and residual term components are obtained after decomposition. The SARIMA model is very effective in predicting periodic time series and is used to train seasonal components. LSTM model has the characteristics of rapid adaptation to the sharp changes of time series data and the function of long-term memory, which is used to train the residual and trend components. FA is a dimensionality reduction method in statistics used to simplify analyzing multi-factor variables that affect hog prices. GRU retains the advantages of LSTM, but its parameter quantity is less, and its training speed is faster. Introducing the attention mechanism in the GRU model can give different weights to the input characteristics, making the model more effective in processing the input of long time series. We propose using the AttGRU model to train and simulate their relationship. This paper combines statistical and machine learning methods to overcome certain limitations of traditional combinatorial models.

Flow chart of the study.
Time series forecasting is an important research topic for effective forecasting of future trends based on available information, and the results can provide strong support for many practical applications, such as financial forecasting [6], transportation forecasting [7], and agricultural price forecasting [8]. Traditional statistics and machine learning methods are widely used in time series prediction, and time series prediction based on a combination model has also been studied more and more. This section discusses the development trend of relevant forecasting methods by sorting out the relevant literature on price forecasting.
Statistical methods in agricultural product price forecasting
Statistical methods were applied earlier in time series forecasting, and the standard procedures are regression analysis, time series method, Markov forecasting method, etc. Zhang et al. proposed a model selection framework with time series characteristics and a forecasting horizon for agricultural prices [9]. Tatarintsev et al. accurately predicted sugar price changes by analyzing an autoregressive integrated moving average (ARIMA) type time series [10]. Şahinli used The Holt-Winters multiplicative (HWM) method of exponential smoothing and the ARIMA method to forecast the consumer potato prices in Turkey and achieved good forecasting results [11]. LI et al. used quantile regression models to predict the prices of hog, chicken, and eggs in the Chinese market [12]. Assis et al. investigated the performance of different time series methods for cocoa bean price prediction and experimentally showed that generalized autoregressive conditional heteroskedasticity (GARCH) has a better predictive effect [13].
Using statistical methods to predict the price of agricultural products can achieve good results in the linear data part. Still, it often fails to achieve satisfactory accuracy when dealing with nonlinear data.
Machine learning methods in agricultural product price forecasting
Machine learning algorithms often have an advantage in handling non-stationary and non-linear data, and machine learning methods tend to produce better predictions than traditional regression-based models [14]. In recent years, the price of agricultural products has fluctuated dramatically, and the use of machine learning models to predict the price of agricultural products has been widely studied.
Yu et al. optimized the BP neural network by introducing the GA algorithm, which significantly improved agricultural price prediction [15]. Weng et al. took the example of predicting the prices of agricultural products in the short and long term. They found that daily, weekly, and monthly price fluctuations could be well expected using neural network methods (including BP networks and RNNs) and were more suitable for large-scale data [16]. Zhao et al. use machine learning methods to predict agricultural futures prices [17]. Wang used the RBF neural network theory and analysis method to improve the agricultural product price prediction model. This initiative subverted the traditional way of applying neural networks in the agricultural product price prediction model and created a theoretical short-term prediction model of China’s agricultural product market price based on the innovative method of information technology [18].
In agricultural price prediction, compared with traditional statistical methods, machine learning can better integrate multivariate factors and show better prediction ability when prices show non-linear changes. However, when epidemics, wars, or other unexpected factors cause dramatic price fluctuations, traditional machine-learning methods may not be able to achieve accurate predictions. Therefore, using the model combination approach to forecast agricultural prices becomes crucial.
Combinatorial modeling methods in agricultural product price forecasting
Time series data is complex and variable, and a linear model may not be able to identify all the features in the data. Combination models combine different models appropriately, which can combine the characteristics of each model and improve the prediction effect [19].
With the rapid development of computer science and technology, many scholars have applied combination models to agricultural price forecasting in recent years. Zhang took advantage of the unique benefits of ARIMA and ANN models in linear and nonlinear modeling and proposed a hybrid method combining ARIMA and ANN models [20]. Zou et al. compared the prediction performance of ARIMA, artificial neural network, and linear combination model in wheat price prediction. The results show that the combination model can significantly improve the prediction performance in error evaluation measurement [21]. Liu et al. proposed a hog price prediction based on a similar subsequence search and support vector regression, which better solves the pseudo-cycle problem caused by the change in pig price data cycle length [22]. Zhou and Pei introduced a grey generalized Verhulst model, called Grey Generalized Verhulst Model GGVM, to accurately predict the Chinese hog price index series [23]. Guo et al. used multidimensional spatiotemporal association rule mining to verify the existence of the butterfly effect in the agricultural price system. They proposed a price prediction model combining data mining theory with RNN algorithms [24]. Wang et al. proposed a combined artificial bee colony-based agricultural price forecasting method to predict soybean and corn futures prices, which better solved the nonlinear characteristics of agricultural futures price series [25]. Wu et al. innovated a long-short memory network model based on variational modal decomposition and improved bald eagle search algorithm optimization for aquatic product price prediction. The experiments show that the model can effectively capture agricultural futures prices’ linear and nonlinear characteristics [26].
In addition, using STL decomposition during time series prediction pre-processing can improve prediction accuracy compared to using the initial data directly. Yin et al. proposed an STL-ATTLSTM model for predicting vegetable prices, and the results showed that the prediction accuracy of the STLATTLSTM model was higher than that of the LSTM model without the STL or Attention mechanism in both [27]. Zhu et al. proposed a new STL-based hybrid model for predicting Chinese hog prices, which effectively improved the accuracy of the decomposition of the STL in the tail of the hog price series [28].
Although the current research on agricultural price forecasting has yielded many valuable results and laid the foundation for this paper, there is room for further improvement in agricultural price forecasting due to the high volatility and seasonal trend characteristics of agricultural price data:
1. Adding STL and other preprocessing processes to the time series prediction can improve the prediction accuracy.
2. Combination models can improve prediction accuracy, but the appropriate model and combination must be chosen according to the characteristics of different time series.
3. The choice of model parameters will significantly impact the final prediction effect of the model, and only by choosing the appropriate parameters can we get the ideal prediction results.
In summary, combining statistics, machine learning, and data decomposition methods using combinatorial modeling makes it possible to make accurate predictions in the price forecasting of agricultural products when there are jumps and fluctuations in the data.
The innovation of this paper is: (1) There is a substitution effect between the prices of agricultural products, and the fluctuation of the prices of different agricultural products will impact the price of pigs. This paper adopts a multivariate forecasting method to conduct an in-depth study of pig prices. Specifically, we combine cost data, substitute prices, piglet prices, profit data, economic indicators, consumer behavior, and other influencing factors to forecast hog prices. (2) This study introduces STL decomposition to deal with seasonality and trends in time series data and incorporates factor analysis methods from statistics to deal with multi-factor influence variables to improve the accuracy of the model; (3) For trend and residual terms after STL decomposition, the LSTM model is used for training, and the SARIMA model is used for training seasonal terms to obtain the best training effect; (4) It overcomes the problem that the traditional models cannot predict the price data of jumping fluctuations or the prediction effect cannot reach the expectation, and enables it to predict the complex changes of the price accurately. (5) Finally, the trained trend term, seasonal term, residual term, and the four columns of data obtained after factor analysis were used as input variables, and the attention mechanism was introduced to calculate the importance of each input variable. The AttGRU model was used for the final hog price prediction. The results showed that compared with other commonly used prediction models, the RMSE of the STL-FA-AttGRU combination model proposed in this paper is 0.649, which is far lower than that of other models.
Related methods
SARIMA model
The Seasonal Autoregressive Integrated Moving Average (SARIMA) model was developed from the ARIMA model proposed by Box and Jenkins and combined with the stochastic seasonal model [29]. When the time series shows trend and seasonality, the series can be smoothed by period-by-period and seasonal differencing to create a SARIMA model [30]. This model can effectively capture and process seasonal changes in time series data, making it outstanding in prediction problems that require consideration of seasonal changes. The general expression is:
The Long Short-Term Memory (LSTM) model was proposed by Hochreiter and Schmidhuber in 1997 [31], LSTM has some advantages in time series modelling problems with long-term memory and easy implementation. The LSTM neural network controls the retention and transmission of relevant data information through forgetting gates, memory gates and output gates, solving the problem of gradient disappearance and gradient explosion that exists during the training of long sequences [32]. Its structure is shown in Fig. 2.

LSTM structure diagram.
The variables associated with the input of the LSTM cell include the current input x
t
, the output of the previous cell ht-1, and the state of the previous cell Ct-1, and the output variables are the current output h
t
and the current cell state C
t
. The LSTM cell includes forgetting gates, input gates, and output gates, the mechanisms of which can be described as follows:
The Multilayer Perceptron (MLP) is a feedforward artificial neural network structure comprising an input layer (single layer), hidden layer (single or multiple layers), and output layer (single layer) [33]. The connections between layers are fully connected, with no connections between neurons within the same layer. MLP demonstrates unique characteristics and advantages in handling nonlinear relationships, learning complex patterns, and accommodating multi-task performance evaluations. The input layer receives datasets containing price data for various agricultural products, which are then passed through the hidden layer for data processing and analysis. The analyzed data is subsequently forwarded to the output layer for final output. The input layer is represented by X, and the output of the hidden layer is given by f (W1X + B1), where W1 represents the weight of the hidden layer, and B1 represents the bias of the hidden layer. The activation function chosen is the Sigmoid function, defined as Sigmoid (x) =1/[1 + exp(- x)], which transforms the value of x into the (0,1) interval [34]. The transition from the hidden layer to the output layer involves multi-class Sigmoid regression. The output layer is denoted as Y, and its output is calculated as Y = Soft max(W2X1 + B2), where W2 represents the weight of the output layer,X1 is the output of the hidden layer, and B2 is the bias value of the output layer. Finally,W1, W2, B1, and B2 values are determined through iterative training to achieve the model’s optimal solution.
RF model
The Random Forest (RF) algorithm is an extension of the Bootstrap Aggregating (Bagging) algorithm [35]. This algorithm possesses the functionality of sampling with replacement for training samples and pieces without replacement for different attributes. This effectively enhances the global search capability and achieves higher classification accuracy. The weak classifier employed in the RF algorithm is a decision tree. Each decision tree undergoes sampling of training samples using the Bagging algorithm and can additionally perform attribute sampling based on the random subspace algorithm.
Moreover, each decision tree in RF is independent and unique, demonstrating strong adaptability to training samples. In this study, the RF model is trained for K rounds, forming a sequence of base estimators {h1 (X) , h2 (X) , h3 (X) ⋯ h
k
(X)}. Then, the ensemble estimator’s result is determined from the averaged or majority voting results of the trained predictions, represented as
LightGBM model
The Light Gradient Boosting Machine (LightGBM) model was proposed to address the context of the low efficiency of Gradient Boosting Decision Tree (GBDT) based algorithms in the presence of high feature dimensions and large amounts of data [36]. Suppose a dataset
In the above way, GradientBoosting is iteratively updated. When the iteration is completed, the weak learners are linearly summed to obtain the strong learners. To speed up the training of the GradientBoosting framework model without compromising accuracy, the LightGBM model adopts many optimization methods, among which the core methods are the histogram algorithm and the depth-constrained leaf-wise growth strategy.
SVR model
The Support Vector Regression (SVR) model places the data in the same plane and uses a linear model to fit the regression problem [37]. The linear model equation is f (x) = w T x + b. The determined linear model corresponds to w and b, which define a hyperplane w T x + b = 0. SVR is different from general linear regression in that there is an interval band on either side of the hyperplane, denoted by ∈. Loss is calculated only when the absolute difference between f (x) and y is more significant than ∈. Using gradient descent and iterative training can lead to the convergence of parameters w and b, thereby minimizing the error of the parameters. The obtained formula is as follows:
Where C is the regularization coefficient, the SVR model differs from ordinary regression models in that it can adjust the parameter C, addressing overfitting issues. Lɛ is the insensitivity coefficient. The kernel function in SVR utilizes Lagrange functions and Wolfe’s dual theory to transform the problem into a quadratic programming problem to find the optimum.
The STL (Seasonal and Trend decomposition using the Loess) is a typical time series additive decomposition method that allows the seasonal components to vary over time and the rate of change can be varied, and the method is more robust in dealing with outliers than traditional seasonal decomposition methods [38]. STL decomposes the data Y
t
(t = 1, 2, ⋯ , n) at a moment in time into seasonal component S
t
, trend component C
t
and residual component R
t
based on Loess with the following decomposition expressions.
The Factor analysis model present most of the information in the data with as few common factors as possible by studying the internal relationships of the data to achieve the goal of data streamlining and ’dimensionality reduction’. The correlation coefficient matrix in the model is determined by the respective factor scores, and each common factor is a linear combination of the original variables, effectively avoiding the subjective arbitrariness of human assignment [39]. The mathematical model for factor analysis is represented as follows.
The Gate Recurrent Unit (GRU) model is a network model that improves the forgetting gate and input gate in the LSTM model to update the entrance, and it has only two gate structures: update gate and reset gate [40]. The update gate determines how much of the state information from the previous moment is retained in the current moment of learning [41]. The larger the value of the update gate, the greater the degree of retention. The reset gate controls how much the state information of the previous moment is combined with the state information of the current moment. The larger the value of the reset gate, the greater the degree of combination. Compared with the LSTM network, the GRU model reduces the training parameters and the learning time requirement and, therefore, outperforms the LSTM network in most of the prediction results. The structure of the GRU is shown in Fig. 3:

GRU structure diagram.
The Attention Mechanism is a model that can simulate human attention well, and its essence is to give higher attention weight to important information. While giving lower weight to less relevant information [42]. By dynamically adjusting the weights assigned to data information during the training process, the contribution of key input information to the model output is thus highlighted, resulting in a neural network with better scalability and robustness. The mechanism of Attention Mechanism is shown in Fig. 4:

Structure of the attention mechanism.
The formula for the Attention mechanism is shown below:
Where,s is the vector from the beginning hidden layer to the nearest hidden layer,α i is the weight coefficient of each hidden state in the weight of the nearest hidden layer, e i is the vector of hidden layers at the ith moment,g i is the individual hidden layer states entered at the beginning,q i is the offset at the ith moment,v i is the matrix of weight coefficients at the ith moment, and w i is the energy value determined at the ith moment.
Data description and preprocessing
Dataset description
This study aims to forecast the hog price in China. The data used in this study include hog price and other influencing factors data, which can be broadly divided into data on farming cost categories, substitution prices data, profit data, economic indicators, and consumer behavior. Farming cost data include rapeseed meal (RM), Soybean meal (SM), batches (B), wheat bran (WB), wheat price (W), fish meal (FM), corn (Co), corn starch (CS), and egg (E). Substitute price data include piglet (P), meat chicken (C), two-breed cross sows (TBCS), outside the ternary piglet (OTTP), and pig carcass (PC). Profit data include pig grain ratio (PGR) and Breeding profit (BP). Economic indicators include the Consumer Price Index (CPI) and the Wholesale Price Index of Vegetable Basket Products (WPIOVBP). Consumer behavior comprises Slaughter volume (SV) and Consumer confidence index (CC). Data on the PGR are from the China Development and Reform Commission, and the rest are from the China Brake Agriculture Big Data Platform. The time of the data is 33 weeks, from August 8, 2011, to July 9, 2022. Since some of the data interval period units are days, we grouped this data by week and used the average value as our weekly data to facilitate the experiment, i.e., the time is week 33 of 2011 to week 28 of 2022. The details of the data for each variable are shown in Table 1.
Data information description
Data information description
Data pre-processing focuses on improving the accuracy and consistency of the model by cleaning and normalizing the input data [43]. In this paper, the min-max normalization method is used to map each variable data between [0,1], and the expressions are
In China, the pig farming industry exhibits a pattern where small-scale household farming takes the lead, with larger-scale operations supporting it [44]. This structure renders hog supply susceptible to herd behavior, causing periodic fluctuations where oversupply and undersupply scenarios occur intermittently, which results in cyclical price changes. Hence, this study primarily employs the STL model to analyze the periodicity and trends in hog prices.
STL is an iterative denoising method whose computational process consists of two parts: inner and outer loops. Each cycle through the inner circle contains a seasonal smoothing with an updated seasonal component and a trend smoothing with an updated trend component. After the inner loop is completed, robust weights are calculated for the outer circle, thus reducing the impact of the outer loop on the update of the seasonal and trend components in the next inner loop [45].
From Fig. 5, we can see the changes in the pig prices. It was found that the price data had been steadily changing before 400 weeks, but after 400 weeks, the price jumped and reached its maximum value in a short time. This jump in data poses difficulties for traditional predictive models. Considering that STL decomposition can reduce the interaction between different parts of the data, a more accurate prediction can be achieved by studying other amounts of the data. Therefore, we considered using STL to denoise the hog price data and then analyze the overall data.

Raw hog prices data.
In the combinatorial algorithm of the traditional STL model, the seasonal component S t , the trend component C t and the residual component R t obtained from the STL model are trained by feeding them into different machine learning models and treating the trained results as linear relationships. The resultant values of each model training are summed up using the linear summation method to finally obtain the prediction results, as shown in the following equation.
However, in practical applications, the trained resultant relationship may be both linear and nonlinear. At the same time, the linear summation method is only a study done for its single column of data. Without considering the problem that other influencing factors may cause lag, so the simple linear summation may not get the ideal prediction effect. Additionally, recognizing the substitutive effects among agricultural product prices, where fluctuations in different agricultural product prices impact hog prices, this paper conducts an in-depth examination of hog prices using multivariate forecasting methods. Our experiments found that some of the influences in the data are weakly correlated with hog prices. To study hog prices in detail regarding substitute prices, economic indicators, and consumer behavior and to retain all vital information in the data as much as possible. Instead of filtering out the factors that impact hog prices most from the data, this paper uses the FA model to extract all necessary information.
The GRU model inherits the advantages of the RNN (Recurrent Neural Network) model that can automatically learn features and effectively model long-range dependent information. It inherits the RNN prediction performance and significantly improves the speed, making the structure more straightforward while maintaining the effect [46]. Therefore, this study selects GRU as the baseline model for hog price prediction. In addition, introducing the attention mechanism helps the model focus its computational resources on the factors more capable of influencing hog price movements when considering multivariate prediction. Considering the inconsistent influence weights of the three components decomposed by the STL and the multiple comprehensive factor expressions obtained from the FA model on hog prices, we continue to study the data using the Attention Mechanism to achieve the best prediction results. Therefore, this paper will incorporate the attention mechanism into the GRU model and use it as the final prediction model to obtain more accurate price prediction results.
The methodology proposed in this study not only comprehensively considers the cyclical and trend characteristics of hog price movements but also significantly preserves the critical information in the data. The model presents unique features and advantages in dealing with nonlinear relationships, learning complex patterns, and adapting to multi-task effectiveness evaluation. Therefore, the STL-FA-AttGRU model was selected as the final research model. In the specific study of Chinese hog price forecast, the operation steps are as follows:
Step 1. Perform the STL decomposition on the raw hog price, and the seasonal component S
t
, the trend component C
t
, the residual component R
t
were decomposed. The decomposed C
t
and R
t
are trained using the LSTM model to obtain
Step 2. After normalization of the raw data, KMO and Bartlett’s sphericity tests were performed to determine whether the KMO value was greater than 0.5 and the Bartlett was less than 0.05. Then, check whether the cumulative contribution rate of the data was larger than 60%. If these conditions are met, it indicates that the hog price data can be characterized for the factor analysis [47].
Step 3. Construct the GRU network through the Sklearn package in Python and add the attention layer to the network to form the AttGRU model for experiments.
Step 4. Collate the three components after decomposition by STL and training, multiple sets of comprehensive factor expressions, and hog price into experimental data. Divide the data into test and validation sets in a ratio of 7 to 3, set the appropriate model parameters, and then put them into the model for training to get the final prediction results.
In the specific selection of the parameters of the article, to accurately reflect the periodicity of the original time series, the number of periods of the decomposed time series in the STL model must be consistent with the number of periods of the original data. Given that the number of weeks recorded in each year of this paper is 52, the parameter for the STL model period is set to 52. To avoid the limitation of one’s expertise leading to the inability to find the appropriate model parameters from the autocorrelation and partial autocorrelation graphs, this paper uses Python programming to obtain the model with the smallest AIC value using hyperparameter optimization. The parameter search ranges of p, q, P, and Q are set to 0,1,2,3,4,5,6,7, and the search ranges of d and D are set to 0,1,2,3. The hyper-parameter optimization results show that model SARIMA (3, 0, 1) (0, 1, 0) 52 has the smallest AIC value, and thus, the specific parameters of the SARIMA model are confirmed.
This paper established different prediction models based on the Python language environment and Tensorflow framework. The optimal sliding window of the STL-FA-AttGRU model is determined to be 4 through repeated experiments, i.e., the data of the previous four periods (one month) are used to predict the hog price in the next period. Based on the idea of the ablation experiment, the number of all sliding windows in this paper is set to 4 to facilitate the comparison of model prediction effects. According to the grid search method, to find the optimal parameters and finally get the optimal prediction results of each model.
To study the prediction effect of the hog price, we use the value of the determined coefficient R2 to analyze the fitting of the predicted value and the real value of the hog price. The larger the value of R2, the more fitting the real value of the hog price with the predicted value. We also calculate the prediction errors of each model by using the root mean square error (RMSE) and the mean absolute error (MAE). The smaller the error value, the better the model method. The calculation formulas of R2 RMSE and MAE are as follows:
Where y
t
represents the real value;
This section may be divided into subheadings. It should provide a concise and precise description of the experimental results, their interpretation, and the practical conclusions that can be drawn.
Forecasting the raw data
To understand the prediction effect of the raw data under each model and to facilitate the subsequent improvement of the algorithm, we used the RF (Random Forest) and LightGBM (Light Gradient Boosting Machine) models in ensemble learning, and the MLP (Multilayer Perceptron), SVR (Support Vector Regression), LSTM (Long Short-Term Memory), AttLSTM (Long Short-Term Memory + attention), GRU (Gate Recurrent Unit), and AttGRU (Gate Recurrent Unit + attention) models in neural networks respectively to study the raw price data. The codes in the experiment were all implemented using the TensorFlow framework in Python, and the experimental results for each model are shown in Fig. 6. As can be seen intuitively in Fig. 6, although the predicted values of each model in the first 20 and the last 60 groups can maintain similar trends and fluctuations to the accurate hog price, the ensemble learning cannot make predictions when the price data changes with leaps and bounds, and the prediction effect of other models on this data is not desirable. The prediction results were divided into three parts, namely the first 20 groups, the middle 90 groups, and the last 60 groups. The MAE values of each part were calculated respectively, and the error values were collated into Table 2. From it, we can see that when the data changes steadily, the model errors are all relatively small. However, when the price changes with leaps and bounds, none of the models can accurately predict the raw data. The reason is that the range of data change is too large for the individual models to thoroughly learn the trend and fluctuation when the data fluctuates with leaps and bounds.

Prediction results of each model under the raw data.
MAE values under the raw data
Considering that the STL (Seasonal and Trend decomposition using the Loess) decomposition can reduce the interaction between different data, and it is difficult to achieve the ideal prediction effect on the direct prediction of hog price, we used the STL model to decompose the hog price into three parts: trend, period, and residual. The results are shown in Fig. 7. From the trend term and residual term, we can see that the changes in these two components are closely correlated, i.e., the overall data shows a regular up-and-down trend, but there are fluctuations by leaps and bounds. From the seasonal term, we can see that the data has strong characteristics of cyclical changes.

STL decomposition of hog price.
Given these characteristics, we trained the trend and residual terms of the data using the LSTM (Long Short-term Memory) model and the seasonal terms of the data using the SARIMA (Seasonal Autoregressive Integrated Moving Average) model, respectively. We recorded and saved the prediction results of each model. Since ensemble learning and the SVR (Support Vector Regression) model cannot predict better when the price changes dramatically, we used the traditional linear addition method and machine learning model to study the trained data. The prediction results are shown in Fig. 8. shows that the traditional linear addition method can achieve the ideal prediction effect when the price fluctuates by leaps and bounds. However, there is a lag. And machine learning can make predictions when the price fluctuates by leaps and bounds, and the lag only appears in the prediction results of the GRU model. Table 3 shows the MAE error values for the three parts of the first 20 groups, the middle 90, and the last 60 groups. From it, we can find that compared with the error values of the original data prediction results, the prediction effect of the model when the price fluctuates has been dramatically improved after STL decomposition, especially that of the LSTM model. The error value is reduced from 6.248 to 2.535, and the prediction accuracy increases by 59.4%. However, compared with the error values of the prediction results when the data changes steadily, the model after STL decomposition cannot achieve the corresponding prediction effect when the price fluctuates by leaps and bounds. The specific manifestation is that when the price fluctuates, the error is still much larger than when the data changes steadily. Therefore, we must also improve the prediction model to achieve the ideal prediction effect when the price changes complexly.

Experimental results under the STL model.
MAE values under the STL model
Given that a direct study of the raw data would lead to a failure in predicting changes in price jumps and fluctuations. And that STL decomposition could improve the accuracy of the model’s predictions and would suffer from lagging, we decided to add other influencing factors to the STL decomposed data to optimize the model’s prediction. In Fig. 9, we can see the analysis results of the Pearson correlation coefficient method on data and find that too many factors show a weak correlation with hog prices. To reduce the negative impact of weakly correlated data on the experiment and to preserve all the essential information in the data as much as possible, we decided to use the factor analysis model as a feature selection method for the data.

Pearson correlation coefficient results of each group of variables.
Table 4 shows that the KMO value after the experiment is greater than 0.6, the Bartlett value is less than 0.05, and the cumulative contribution rate is larger than 60%, so the factor analysis experiment is meaningful. The experiment finally transformed the multiple groups of related factors affecting the hog price into four groups of comprehensive factor expressions. The coefficient matrixes of each component score are shown in Table 5.
Results of the factor analysis
Component matrix coefficient under the factor analysis
By putting the five groups of comprehensive factor expressions, the training results of each component after the STL decomposition model and the hog prices are to be predicted into different prediction models, and the final prediction results are obtained in Fig. 10. The figure shows that the STL-FA-AttGRU model achieves a satisfactory fitting effect between the predicted value when the price fluctuates with leaps and bounds and the real hog price value. From Table 6, we can see the MAE errors of the first 20 groups, the middle 90 groups, and the last 60 groups, and find that the prediction accuracy of all models improved significantly when the price fluctuates with leaps and bounds, especially the STL-FA-AttGRU model, which achieves a satisfactory prediction result with minimal prediction errors in different data ranges.

Forecast results under STL and factor analysis models.
MAE values under STL and factor analysis models
In this part, we respectively use methods MAPE, MAE, RMSE, R2 and DM (Diebold and Mariano) [48] test to determine further which model has the best prediction effect and whether the proposed method could significantly improve the grape price prediction accuracy.
As can be seen in Fig. 11, the overall error values for the ensemble learning under the raw data are large. The reason is that ensemble learning and the SVR model cannot successfully learn the change rules between data when the price fluctuates with leaps and bounds over short periods. The model with the lowest error is AttGRU, and its MAPE value is 0.144, MAE value of 3.576 and RMSE value is 4.374. Next, we can see the values of three errors under the denoising techniques and the factor analysis in Fig. 12, from which we find that the STL-FA-AttGRU has the smallest error values. Through calculation, we find the MAPE value of STL-FA-GRU model is 0.025, the MAE value 0.494 and the RMSE value 0.649, which are smaller than the AttGRU model under the raw data. Therefore, in the prediction of hog price, data analysis technology can reduce the prediction error of each model and make the STL-FA-AttGRU model achieve the best prediction effect. From Fig. 13, we can see the R2 values of the prediction results of each model. Among them, the value of STL-FA-AttGRU is the highest, which is 0.9957, indicating that the predicted price of this model fits the real hog price best.

Three error values under the raw data.

Three error values under the denoising techniques and the factor analysis.

Validation set results under the denoising techniques and the factor analysis.
To find the optimal number of sliding windows for the BiGRU model and to verify the accuracy and robustness of the model’s prediction effect under different datasets, this paper sets up different sliding window numbers and data split ratios and conducts experiments. The detailed experimental results are listed in Table 7 and Table 8. The experimental results show that when the number of sliding windows is set to 4, the model predicts the minor error value and the best-fitting effect. In addition, the STL-FA-BiGRU model shows good prediction results with different data partition ratios.
Prediction effect under different sliding window numbers
Prediction effect under different data split ratios
The DM test can be used to verify whether there is a significant difference between the predictive effect of the STL-FA-AttGRU model and other models. Therefore, we used the DM test to determine whether the proposed model significantly improves the hog price prediction accuracy. Table 9 and Table 10, respectively, show the results of the DM test in terms of MAE under the STL and FA model. From Table 9, we find that the P-values of the DM test between the STL-FA-AttGRU model and other models are less than 0.05, indicating that the prediction effect of the proposed model is better than other models at the 99% confidence level. Also, given that the DM-values between the STL-FA-AttGRU model and the other models in Table 10 are all less than 0, it suggests that the STL-FA-AttGRU model improves each model’s prediction.
P-values of the DM test under the STL and FA model
DM-values of the DM test under the STL and FA model
Risk assessment and uncertainty handling are very important for predictive models. In this study, based on the trained STL-FA-BiGRU model, selected data features were input, and the model was used to predict the data for the next four weeks. The prediction results are shown in Table 11. Fig. 14 shows that the predicted four weeks of data remain within the 90 percent confidence interval, and the of the prediction result is 0.965. Thus, the STL-FA-AttGRU model demonstrates reliability and superior ability to assess future risk and deal with uncertain data.
Predictions from the STL-FA-AttGRU model for the next 4 weeks

Forecast results for the next 4 weeks.
Due to the influence of uncontrollable factors, the recent hog price data fluctuated by leaps and bounds. Traditional prediction models usually achieve good prediction effects when prices change steadily, but poor effects when data fluctuates with leaps and bounds [49]. Therefore, the focus of this paper is to develop a combination model that can accurately predict when data fluctuates with leaps and bounds.
The prediction results from the raw data reveal that ensemble learning is unable to make predictions when there are fluctuations with leaps and bounds in prices. Although the model with the best prediction effect in the raw data is AttGRU, it is still unable to accurately predict the price under fluctuations. According to the changing characteristics of hog price, we respectively use STL and Factor analysis models to denoise and reduce the dimension of the raw data. Given that the STL decomposition alone can improve the prediction accuracy but there will be lag, so we input the data after the Factor analysis and the data after STL decomposition and training into the model together. Finally, we got the prediction results. Since the three error values of STL-FA-AttGRU are the smallest, its R2 value is the largest and the performance effect is the best in the DM test, the model can achieve the best prediction effect.
Conclusion
In recent years, under the influence of various factors such as COVID-19, war, and the global economic situation, food prices such as meat and grain have frequently fluctuated significantly in the country, which has caused problems for those involved in the industry chain. Accurate prediction of hog prices will enable the relevant merchants to keep abreast of market trends and thus plan their farming structure rationally to maximize the benefits of farming. It can also provide a scientific basis for the government to formulate relevant policies and promote the healthy and sustainable development of the agricultural industry. To successfully predict the data of hog prices, this paper proposes a combined modeling method based on time series and multivariate analysis. Firstly, the STL model was used to decompose and denoise the data of the hog prices. Then, the FA model was applied to reduce the dimensionality of multivariate factors. Finally, the AttGRU model was utilized to learn and train the data obtained from the previous models to get the hog’s final predicted prices. By comparing the methods of this experiment with other advanced methods and combining the data on various indicators, it was found that the STL-FA-AttGRU model can achieve the best prediction results for hog prices in China, no matter when the data changes steadily or fluctuates with leaps and bounds. Therefore, the model and optimization method proposed in this paper will have a broader application in the study of time series data and has the potential to be applied to other fields.
In subsequent studies, we will increase the robustness and usefulness of the model by adding perturbation factors to the model and assigning different weights to the predictions of each model. To improve the accuracy of the model’s predictions, we will also consider the impact of factors such as transportation, storage, and natural disasters on Chinese hog prices. The prediction model proposed in this paper will enrich the existing theories of price-prediction models, energize market regulation and economic development, and have a positive significance to the harmonious development of society.
Footnotes
Acknowledgment
This work was supported by the China Scholarship Council under Grant (202106915002) and Research on Mechanisms and Path of Agricultural Digitization (2022SYZD03).
