Agricultural product price prediction method based on seasonal decomposition and random forest integration

By decomposing agricultural product price data using the SARIMA model and combining it with the feature matrix of the random forest model, high-precision and highly interpretable predictions of agricultural product prices are achieved, solving the prediction error and interpretability problems of traditional models when dealing with linear and nonlinear fluctuations.

CN121120122APending Publication Date: 2025-12-12HOHAI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511039550.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-28
Publication Date
2025-12-12

AI Technical Summary

Technical Problem

Existing agricultural product price forecasting systems suffer from large prediction errors and poor interpretability when dealing with linear and nonlinear fluctuations. In particular, deep learning models are prone to overfitting in small and medium-sized data scenarios, and traditional model combinations lack systematic integration strategies, making it difficult to fully utilize the differences in characteristics between different models.

Method used

The SARIMA model is used to perform seasonal decomposition to obtain trend components and residual components. A feature matrix containing month number encoding, lag features and derived features is constructed. The random forest model is used to train and generate residual prediction values. The trend components and residual prediction values ​​are linearly superimposed to achieve accurate prediction of agricultural product prices.

Benefits of technology

It improves the accuracy and interpretability of agricultural product price forecasts, effectively captures seasonal changes in data, and handles nonlinear fluctuations caused by sudden market policies or extreme weather, making it suitable for small to medium-sized data scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121120122A_ABST
    Figure CN121120122A_ABST
Patent Text Reader

Abstract

The invention discloses an agricultural product price prediction method based on seasonal decomposition and random forest integration. The method comprises the steps of collecting original time sequence data of agricultural product prices; performing SARIMA seasonal decomposition on the original time sequence data to obtain a trend component and a residual component; constructing a feature matrix containing a time sequence feature, a lag feature and a derivative feature based on the residual component; training the feature matrix by using a random forest model to generate a residual prediction value; and linearly superposing the trend component and the residual prediction value to obtain a final prediction result. According to the method, the seasonal change of the data can be effectively captured, nonlinear fluctuation caused by factors such as market sudden policies or extreme weather can be processed, and the prediction precision and the result interpretability are greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of agricultural decision-making and artificial intelligence technology, and in particular relates to a method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble. Background Technology

[0002] With anomalous climate change and intensified market demand volatility, accurately understanding and predicting agricultural product price fluctuations has become particularly important. However, existing forecasting systems face multiple challenges in practical applications. First, distinguishing the driving factors of price fluctuations is a major difficulty. Second, deep learning models are prone to overfitting in small- to medium-scale data scenarios, while traditional model combinations lack systematic integration strategies and struggle to fully utilize the differences in characteristics among different models. These problems severely restrict the effective application of decision support systems in modern agricultural risk management, especially in providing scientific guidance for accurate forecasting and risk early warning in complex and dynamic environments, which remains a pressing issue.

[0003] Existing technologies exhibit significant limitations in addressing the aforementioned challenges. Traditional time series models (such as ARIMA and SARIMA), while adept at capturing linear trends and seasonal cycles and possessing good interpretability, perform poorly when faced with nonlinear fluctuations, leading to substantial prediction errors. Pure machine learning models (such as random forests and gradient boosters), while demonstrating powerful capabilities in nonlinear fitting, struggle to directly leverage dependencies within time series data, typically requiring manual feature construction, increasing model complexity, and resulting in poor interpretability. Furthermore, simply combining the predictions of different models fails to fully leverage their respective strengths, thus limiting further improvements in prediction accuracy. Therefore, developing a novel time series forecasting system that effectively handles both linear and nonlinear components while maintaining good interpretability is particularly urgent. Summary of the Invention

[0004] Purpose of the Invention: The purpose of this invention is to provide an agricultural product price forecasting method based on seasonal decomposition and random forest ensemble. This method not only effectively captures seasonal variations in data but also handles nonlinear fluctuations caused by sudden market policies or extreme weather, significantly improving forecast accuracy and interpretability.

[0005] Technical solution: The present invention provides a method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble, comprising the following steps:

[0006] Step 1: Collect raw time-series data on agricultural product prices;

[0007] Step 2: Perform SARIMA seasonal decomposition on the original time series data to obtain trend components and residual components;

[0008] Step 3: Construct a feature matrix containing time-series features, lag features, and derived features based on the residual components;

[0009] Step 4: Use a random forest model to train the feature matrix and generate residual prediction values;

[0010] Step 5: Linearly superimpose the trend component and the residual prediction value to obtain the final prediction result.

[0011] Furthermore, step 2 specifically includes the following steps:

[0012] Step 2.1: Use an automatic search algorithm to determine the SARIMA model parameters (p,d,q,P,D,Q,m), where m=12 is the annual cycle of the corresponding monthly data;

[0013] Step 2.2: First, perform first-order differencing on the raw time-series data of agricultural product prices to eliminate long-term trends, and then perform seasonal differencing with a period of 12 to eliminate annual periodicity.

[0014] Step 2.3: Verify the stationarity of the differencing series using the ADF unit root test. When the ADF statistic is less than the critical value of -3.457286 at the 1% significance level and the p value is <0.05, determine the model order based on ACF / PACF analysis. The autoregression order of the ordinary part is p=1, the moving average order is q=1, and the autoregression order of the seasonal part is P=1, the moving average order is Q=1.

[0015] Step 2.4, using the formula:

[0016]

[0017] Where φ represents the conventional autoregressive coefficient, controlling the relationship between the current value and historical values; Φ is the seasonal autoregressive coefficient, capturing cross-cycle dependence; θ corresponds to the conventional moving average coefficient, reflecting the impact of historical errors; Θ is the seasonal moving average coefficient; B acts as the lag operator, B... m The lag is m periods; d and D represent the conventional differencing order and the seasonal differencing order, respectively; m is the seasonal period, specifically 12 months; p is the conventional partial autoregressive order; q is the moving average order; P is the seasonal partial autoregressive order; and Q is the moving average order.

[0018] Decompose the original time series data to obtain the result that satisfies y t =T t +S t +∈ t Trend component T t With residual components ∈ t S t This is a seasonal component.

[0019] Furthermore, step 3 specifically includes the following steps:

[0020] Step 3.1: Extract the month codes from 1 to 12 to represent the annual seasonality and extract year information to distinguish the trend differences between different years as time series features;

[0021] Step 3.2: Extract the lag 1 period residual ∈ t-1 4-period residuals ∈ t-4 12-period residuals ∈ t-12 Using time-series dependencies that reflect short-term, quarterly, and annual timeframes as lag characteristics;

[0022] Step 3.3, using the formula Δ∈ t-1 =(∈ t -∈ t-1 ) / ∈ t-1 The residual variation rate is calculated to characterize the fluctuation trend of the residual sequence as a derived feature.

[0023] Furthermore, step 4 specifically includes the following steps:

[0024] Step 4.1: The random forest model uses the sklearn regressor, with the number of trees set to 100 and no maximum depth limit.

[0025] Step 4.2: Rank the features by their importance using the Gini coefficient, with the month number encoding feature having the highest importance. Residual prediction values ​​are then generated after training.

[0026] Furthermore, step 5 specifically includes the following steps:

[0027] Step 5.1: Verify that the residuals are white noise using the Young-Box Q(18) test. Confirm the model validity when the significance level is >0.05.

[0028] Step 5.2: The final predicted value must meet the fitting index requirements: stationary R². 2 ≥0.485, R 2 ≥0.997, RMSE≤0.025, MAPE≤0.722;

[0029] Step 5.3: Output the predicted values ​​for the next n periods and the corresponding confidence intervals.

[0030] The present invention also discloses a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method of the present invention.

[0031] The present invention also discloses a computer-readable storage medium having a computer program / instructions stored thereon, which, when executed by a processor, implements the steps of the method of the present invention.

[0032] The present invention also discloses a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the method of the present invention.

[0033] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages:

[0034] This invention proposes a time series forecasting method based on seasonal decomposition and random forest ensemble. It uses a SARIMA model to seasonally decompose the original time series data to obtain trend and residual components. Based on the residuals, a feature matrix containing month codes, lag residuals, and rates of change is constructed. A random forest model is then used to train and generate residual prediction values, which are linearly superimposed with the trend components, achieving accurate prediction of data with significant seasonal and nonlinear characteristics. The system adopts a modular architecture of SARIMA decomposition, residual feature engineering, random forest modeling, and ensemble prediction. It overcomes the limitations of traditional models in fitting nonlinear fluctuations through a divide-and-conquer modeling strategy. Combining explicit utilization of time series features with a lightweight ensemble method, it achieves both prediction accuracy and interpretability in small- to medium-scale data scenarios, making it applicable to fields such as agricultural product prices and energy consumption, providing a systematic solution for time series forecasting.

[0035] This invention extracts linear seasonal trends from time series using the SARIMA model and models nonlinear patterns in the residuals using the random forest algorithm, ultimately achieving joint prediction using both methods. This approach not only effectively captures seasonal variations in data but also handles nonlinear fluctuations caused by sudden market policies or extreme weather, significantly improving prediction accuracy and interpretability. Attached Figure Description

[0036] Figure 1 This is a flowchart of the present invention.

[0037] Figure 2 This is a comparison chart of the fitting and prediction results of the SARIMA model.

[0038] Figure 3 This is a comparison chart of prediction results from the random forest model. Detailed Implementation

[0039] The technical solution of the present invention will be further described below with reference to the accompanying drawings.

[0040] like Figure 1 As shown, an embodiment of the present invention provides a method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble, comprising the following steps:

[0041] S1 performs SARIMA seasonal decomposition on the original time series data to obtain the trend component and residual component.

[0042] Specifically, for the original time series data Y = {y1, y2, ..., y...} T Perform double difference preprocessing, firstly executing the first-order difference. To eliminate the linear trend term, seasonal differencing with a period of 12 is then performed. Eliminate annual cyclical fluctuations.

[0043] Specifically, the stationarity test is performed using the ADF unit root test. When the ADF statistic of the differencing sequence is less than the 1% significance level critical value of -3.457286 and the p value is less than 0.05, the sequence is considered stationary.

[0044] Specifically, the model parameters are determined, and the optimal parameter combination (p,d,q,P,D,Q) is automatically searched using the auto_arima algorithm, where m=12 is fixed as the monthly data period. The model order is determined based on ACF / PACF analysis, with the autoregression order p=1 and the moving average order q=1 for the ordinary part, and the autoregression order P=1 and the moving average order Q=1 for the seasonal part.

[0045] Specifically, construct a mathematical decomposition model: using the formula:

[0046]

[0047] Decompose the original data, where B is the lag operator. As a difference operator, we finally obtain y t =T t +S t +∈ t T t For the trend component, S t For seasonal components, ∈ t It is a nonlinear residual component.

[0048] S2, constructs a feature matrix containing time-series features, lag features and derived features based on residual components.

[0049] Specifically, construct time-series features, and encode the number of months w. t The months 1-12 are mapped to integer codes from 1 to 12, representing the annual cyclical pattern. Year characteristic y t Extract the data to the corresponding year and distinguish the trend differences between different years.

[0050] Specifically, constructing lag characteristics, lag 1 residual ∈ t-1 : Capture short-term time-series dependencies (1-month time interval), with 4-period residuals ∈ t-4: Corresponding to quarterly cycle dependence (time interval 4 months), 12-period lag residual ∈ t-12 This reflects the annual cycle dependence (12-month time interval).

[0051] Specifically, derived features are constructed using the formula Δ∈ t =(∈ t -∈ t-1 ) / ∈ t-1 Calculate the residual rate of change to quantify the direction of fluctuation trend when Δ∈ t A value greater than 0 indicates an increasing trend in the residual;

[0052] Specifically, the final construction is a K≥6 dimensional feature matrix X∈R T×K , where T is the number of samples and K is the feature dimension.

[0053] S3 uses a random forest model to train the feature matrix and generate residual prediction values.

[0054] Specifically, model parameters are configured, with n_estimators = 100 decision trees to reduce variance through ensemble learning, max_depth = None to allow individual trees to grow fully and adapt to the non-linear complexity of residual data, and the feature splitting criterion is the Gini coefficient, calculated using the following formula: Where p k denoted as the proportion of the k-th class of samples in the node.

[0055] Specifically, residual predictions are generated by inputting the feature matrix X, training the model through fit(X,∈), and outputting the residual prediction value ∈^t, where the importance score of the month number encoding feature is usually more than 40% higher than that of other features.

[0056] S4, the trend component and the residual prediction value are linearly superimposed to obtain the final prediction result.

[0057] Specifically, the final predicted value in These are the predicted values ​​of the trend components output by SARIMA. These are the residual predictions output by the random forest.

[0058] Specifically, the model validity was validated using the Young-Box Q test: the Q(18) statistic was calculated using the following formula: Where n is the number of samples. The autocorrelation coefficient is the result of a lag of k periods. When the significance level is >0.05, the residual is confirmed to be white noise.

[0059] Specifically, the fitting index system, the stationary R... 2 The formula for measuring the explanatory power of a model for differencing data is: Overall R 2The RMSE (Root Mean Square Error) formula is used to measure the goodness of fit to the original data. The formula for MAE (Mean Absolute Percentage Error) is:

[0060] Specifically, the output format generates predicted values ​​for the next n periods and 95% confidence intervals. The formula for calculating the confidence intervals is as follows: Where SE is the standard error.

[0061] Preferably, according to an embodiment of the present invention, the current market price of wheat (medium) from January 2023 to June 2025 is used as an example to deeply verify the model performance. During this period, the wheat market was affected by a variety of complex factors, such as abnormal global climate leading to reduced production in some major producing areas, and adjustments in international trade policies causing changes in the import and export pattern, providing a rich sample for testing the model's ability to cope with complex fluctuation scenarios.

[0062] Preferably, the model input data is processed by SARIMA decomposition. For the original price series from 3.05 yuan / kg in January 2023 to 2.81 yuan / kg in June 2025, the first-order differencing eliminates the price correction trend at the beginning of 2023, and the seasonal differencing smooths annual cyclical fluctuations (such as the price decline during the harvest season in June 2023). The SARIMA(1,1,1)(1,1,1) is constructed. 12 The model decomposes the trend and residuals. For example, the trend value in March 2024 was 3.01 yuan / kg, and the residual was 0.03 yuan / kg (the actual price was 3.04 yuan / kg due to adjustments in the inventory strategies of international grain traders).

[0063] Preferably, taking the data from March 2024 as an example, the month code 3, the year 2024, the residuals lagged by 1 month (residual of February 2024: 0.01 yuan / kg), the residuals lagged by 4 months (residual of November 2023: 0.02 yuan / kg), and the residuals lagged by 12 months (residual of March 2023: 0.01 yuan / kg) are extracted. The residual variation rate is calculated as (0.03-0.01) / 0.01 = 2, and a feature matrix is ​​constructed.

[0064] Preferably, during the period of continuous price decline from May to August 2023, the mean absolute error (MAE) between the model's predicted and actual values ​​was 0.04 yuan / kg, a 50% reduction compared to the single SARIMA model (MAE = 0.08 yuan / kg). For example, in June 2023, the actual price was 2.96 yuan / kg, the model predicted 2.98 yuan / kg, while the SARIMA predicted 3.04 yuan / kg.

[0065] Preferably, from September to December 2024, prices rose due to flooding in Australia's main wheat-producing areas. The model captured the upward trend two months in advance, and the root mean square error (RMSE) between the predicted and actual values ​​was 0.05 yuan / kg, effectively reflecting price fluctuations, while the RMSE of the random forest model was 0.12 yuan / kg.

[0066] Preferably, the comparison between the present invention and traditional models is shown in Table 1. The model of the present invention reduces the MAE by 11.3% compared to the SARIMA model, while maintaining a similar RMSE, thus preserving the high interpretability advantage of linear models. Although the random forest model has strong nonlinear fitting ability, its RMSE reaches 0.136, which is 4.7 times higher than the combined model, verifying the limitations of pure black-box models in time series prediction.

[0067] This empirical analysis, such as Figure 2 , 3 As shown, compared to the SARIMA model and the random forest model, a time series forecasting method and system based on seasonal decomposition and random forest ensemble achieves a balance between "high accuracy and high interpretability" through a divide-and-conquer strategy. Furthermore, the divide-and-conquer framework does not lose the interpretive advantages of linear models, effectively addressing the limitations of traditional models in predicting complex fluctuations in wheat prices and providing market participants with more accurate decision-making support. Table 1 is a comparison and scoring table between this model and traditional models.

[0068] Table 1. Comparison and scoring table between this model and the traditional model.

[0069]

[0070] In summary, according to this invention, the original time-series data is subjected to SARIMA seasonal decomposition to obtain trend components and residual components; a feature matrix containing time-series features, lag features, and derived features is constructed based on the residual components; the feature matrix is ​​trained using a random forest model to generate residual prediction values; and the trend components and residual prediction values ​​are linearly superimposed to obtain the final prediction result. Therefore, this invention innovatively proposes a divide-and-conquer ensemble framework of "linear seasonal trend + nonlinear residual," and for the first time deeply couples the linear time-series decomposition capability of the SARIMA model with the nonlinear pattern recognition advantage of the random forest algorithm. By constructing a sequential architecture of "trend decomposition-residual modeling," we achieve separate modeling of linear trends, seasonal cycles, and nonlinear fluctuations in time series, breaking through the bottleneck of traditional single models in fitting sudden shocks. We design a multidimensional feature matrix that includes month number encoding, multi-order lag residuals, and rates of change, transforming time series dependencies into structured inputs, significantly enhancing the ability of random forests to capture seasonal patterns, and solving the problem of inefficient use of time series features in pure machine learning models. We adopt a lightweight ensemble strategy, forming a collaborative optimization mechanism based on mature model combinations, achieving a balance between prediction accuracy and interpretability in small-to-medium scale data scenarios, and providing a systematic solution with both theoretical rigor and engineering practicality for time series prediction with significant seasonal and nonlinear characteristics.

Claims

1. A method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble, characterized in that, Includes the following steps: Step 1: Collect raw time-series data on agricultural product prices; Step 2: Perform SARIMA seasonal decomposition on the original time series data to obtain trend components and residual components; Step 3: Construct a feature matrix containing time-series features, lag features, and derived features based on the residual components; Step 4: Use a random forest model to train the feature matrix and generate residual prediction values; Step 5: Linearly superimpose the trend component and the residual prediction value to obtain the final prediction result.

2. The method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble as described in claim 1, characterized in that, Step 2 specifically includes the following steps: Step 2.1: Use an automatic search algorithm to determine the SARIMA model parameters p, d, q, P, D, Q, m, where m = 12 is the annual cycle of the corresponding monthly data; Step 2.2: First, perform first-order differencing on the raw time-series data of agricultural product prices to eliminate long-term trends, and then perform seasonal differencing with a period of 12 to eliminate annual periodicity. Step 2.3: Verify the stationarity of the differencing series using the ADF unit root test. When the ADF statistic is less than the critical value of -3.457286 at the 1% significance level and the p value is <0.05, determine the model order based on ACF / PACF analysis. The autoregression order of the ordinary part is p=1, the moving average order is q=1, and the autoregression order of the seasonal part is P=1, the moving average order is Q=1. Step 2.4, using the formula: Where φ represents the conventional autoregressive coefficient, controlling the relationship between the current value and historical values; Φ is the seasonal autoregressive coefficient, capturing cross-cycle dependence; θ corresponds to the conventional moving average coefficient, reflecting the impact of historical errors; Θ is the seasonal moving average coefficient; B acts as the lag operator, B... m This indicates a lag of m periods; d and D represent the conventional differencing order and the seasonal differencing order, respectively; m is the seasonal period, specifically 12 months; p is the order of the conventional partial autoregression; q is the order of the moving average; P is the order of the seasonal partial autoregression; Q is the order of the moving average. Decompose the original time series data to obtain the result that satisfies y t =T t +S t +∈ t Trend component T t With residual components ∈ t S t This is a seasonal component.

3. The method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble as described in claim 1, characterized in that, Step 3 specifically includes the following steps: Step 3.1: Extract the month codes from 1 to 12 to represent the annual seasonality and extract year information to distinguish the trend differences between different years as time series features; Step 3.2: Extract the lag 1 period residual ∈ t-1 4-period residuals ∈ t-4 12-period residuals ∈ t-12 Using time-series dependencies that reflect short-term, quarterly, and annual timeframes as lag characteristics; Step 3.3, using the formula Δ∈ t-1 =(∈ t -∈ t-1 ) / ∈ t-1 The residual variation rate is calculated to characterize the fluctuation trend of the residual sequence as a derived feature.

4. The method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble as described in claim 1, characterized in that, Step 4 specifically includes the following steps: Step 4.1: The random forest model uses the sklearn regressor, with the number of trees set to 100 and no maximum depth limit. Step 4.2: Rank the features by their importance using the Gini coefficient, with the month number encoding feature having the highest importance. Residual prediction values ​​are then generated after training.

5. The method for predicting agricultural product prices based on seasonal decomposition and random forest ensemble as described in claim 1, characterized in that, Step 5 specifically includes the following steps: Step 5.1: Verify that the residuals are white noise using the Young-Box Q18 test. The model validity is confirmed when the significance level is >0.

05. Step 5.2: The final predicted value must meet the fitting index requirements: stationary R². 2 ≥0.485, R 2 ≥0.997, RMSE≤0.025, MAPE≤0.722; Step 5.3: Output the predicted values ​​for the next n periods and the corresponding confidence intervals.

6. A computer device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method of claim 1.

7. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method of claim 1.

8. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method of claim 1.