Agricultural product price prediction method based on self-attention mechanism and meteorological factors

By using the Transformers model based on the self-attention mechanism, combining meteorological factors and agricultural product price data, an agricultural product price prediction model is constructed, which solves the shortcomings of meteorological factors predicting agricultural product prices in the existing technology, and achieves higher precision and stable price prediction.

CN119648281AInactive Publication Date: 2025-03-18四川省农村经济综合信息中心
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510162022.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-14
Publication Date
2025-03-18
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the prior art, there are few methods to predict agricultural product prices based on meteorological factors, and meteorological factors are complex, making it difficult to effectively use artificial intelligence algorithms to predict.

Method used

The Transformers model based on the deep learning architecture based on the self-attention mechanism is adopted, and combined with the agricultural product price data and related meteorological factor data over the years, a price prediction model is constructed, and the agricultural product price prediction is achieved through training and preprocessing data.

Benefits of technology

It improves the accuracy and stability of agricultural product price prediction, is significantly better than other benchmark models, has strong sequence modeling capabilities, can effectively capture long-term dependencies in time series, and enhances the robustness and generalization capabilities of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119648281A_ABST
    Figure CN119648281A_ABST
Patent Text Reader

Abstract

The invention discloses an agricultural product price prediction method based on a self-attention mechanism and meteorological factors, and the method comprises the steps: obtaining the price data over the years according to the types of agricultural products, obtaining the meteorological factors of the corresponding agricultural products in the corresponding time periods of a selected agricultural product region, and carrying out the preprocessing of the selected agricultural product price data and the meteorological factor data of the corresponding region; analyzing the correlation between the meteorological factor data and the agricultural product price in the corresponding time period, dividing the obtained meteorological factor data into a training set and a test set, constructing a price prediction model of a self-attention mechanism, and inputting the meteorological factors related to the historical agricultural product price data into the price prediction model as input data, and training the model, and for each agricultural product, predicting and outputting the corresponding agricultural product price through the trained price prediction model by taking the meteorological factor data related to the agricultural product price as input. According to the scheme, the prediction stability and reliability are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of artificial intelligence prediction of agricultural product prices, and in particular to a method for predicting agricultural product prices based on a self-attention mechanism and meteorological factors. Background Art

[0002] Meteorological conditions have a decisive influence on agricultural production because it involves the direct impact of climate conditions on agricultural production, including temperature, precipitation and sunshine, which determine the growth cycle and yield of crops, and thus affect the market supply and demand relationship and price fluctuations. Therefore, forecasts based on meteorological factors play a key role in the formation of agricultural product prices. Accurate meteorological forecasts can help farmers and market participants make more informed decisions, thereby affecting the supply and demand relationship and price fluctuations of agricultural products. Global climate change and the increase in extreme weather events have further exacerbated this impact, making accurate meteorological forecasts an indispensable part of agricultural production and agricultural product market planning.

[0003] At present, there are many studies on using historical agricultural product prices to predict subsequent price trends. However, there are fewer studies on methods to predict agricultural product prices based on meteorological factors. Meteorological factors are numerous and complex. Therefore, using artificial intelligence algorithms to predict agricultural product prices based on meteorological factors is a technical problem that needs to be solved. Summary of the invention

[0004] In response to the above technical problems, the present invention provides a method for predicting agricultural product prices based on a self-attention mechanism and meteorological factors.

[0005] The present invention is implemented by adopting the following technical scheme: a method for predicting agricultural product prices based on a self-attention mechanism and meteorological factors, comprising the following steps: Step S1: According to the types of agricultural products, obtain the price data of previous years and the meteorological factors of the corresponding agricultural products in the corresponding time period in the selected agricultural product area; Step S2: pre-processing the selected agricultural product price data and the corresponding regional meteorological factor data; Step S3: Analyze the correlation between meteorological factor data and agricultural product prices in the corresponding time period; Step S4: Divide the obtained meteorological factor data into a training set and a test set; Step S5: construct a price prediction model of the self-attention mechanism, use the meteorological factors related to the historical agricultural product price data as input data into the price prediction model, and train the model; Step S6: For each agricultural product, the meteorological factor data related to the agricultural product price is used as input, and the trained price prediction model is used to predict the output of the corresponding agricultural product price.

[0006] Specifically, the data preprocessing in step S2 includes the following sub-steps: Step S21: completing agricultural product price data and meteorological factor data by linear interpolation method; Step S22: normalize the padded data.

[0007] Specifically, the linear interpolation in step S21 is as follows: let the function At two o'clock , The values ​​on , , the linear interpolation calculation formula is: .

[0008] Specifically, the normalization process in step S22 is as follows: normalizing the agricultural product price data and the meteorological factor data, scaling the data proportionally and mapping them to [0, 1]. The specific calculation formula is: ; in , Represents the minimum and maximum values ​​of the data column respectively.

[0009] Specifically, the step S3 correlation analysis specifically includes: Step S31: sort the pre-processed meteorological factor data and agricultural product price data by rank, and if the data points of the variables are the same, sort them by average; Step S32: For each pair of observed values , calculate the difference in ranking between two variables, the calculation formula is: , and calculate the sum of squares of all rank differences ; Step S33: Perform correlation analysis on meteorological factors and agricultural product prices through Spearman rank correlation coefficient to obtain meteorological factor data with significant correlation with agricultural product prices. The formula is: ; in, is the number of observations, is the Spearman coefficient, ranging from -1 to 1. =1, indicating a positive correlation; =-1, indicating negative correlation; =0, indicating no correlation.

[0010] Specifically, the price prediction model is a Transformers model based on a deep learning architecture of a self-attention mechanism. Model training and prediction include the following steps: Step S51: The meteorological factor data is used as encoder input, and after embedding processing, it is converted into a numerical representation that the model can understand, and position encoding is added to retain the time series data. The corresponding agricultural product price data is used as decoder input to generate the target sequence; Step S52: Using the scaled dot product self-attention mechanism, each element in the target sequence is processed with three different linear transformations to obtain a query vector, a key vector, and a value vector. The dot product between the query vector and the key vector is calculated and scaled, and the softmax function is applied to obtain the attention weight. The weight is applied to the value matrix to obtain the weighted summation result. The weighted summation calculation formula is: ; in is the dimension of the key vector, , , denote the query vector, key vector and value vector respectively, Represents the transpose operation of a matrix; Step S53: Use a multi-head self-attention mechanism to perform multiple self-attention operations in parallel, concatenate the results, and transform them through a linear layer; Step S54: In each encoder and decoder layer, and after the self-attention layer, the output data is further processed using a feedforward neural network, including two linear transformations and an activation function; Step S55: The meteorological factor data processed by the encoder and the agricultural product price data processed by the decoder are directly passed to the subsequent layers through residual connections, and layer normalization is applied to the outputs of the encoder and decoder to ensure that the mean of each feature is 0 and the variance is 1; Step S56: Use position encoding to provide the Transformers model with the position information of the words in the sequence. Position encoding generates a unique vector for each position in the sequence, so that the Transformers model can distinguish elements at different positions and perceive the relative order. Step S57: Use historical meteorological factor data and agricultural product price data to train the model. After the model training is completed, use new meteorological factor data as input to predict future agricultural product prices through the model.

[0011] Specifically, the step S53 performs transformation calculation through a linear layer as follows: ; Among them, each The calculation is: ; in, , and Represent three weight matrices respectively.

[0012] Specifically, the feedforward neural network expression in step S54 is: ; in, is the output of the self-attention layer, , , , are the parameters of the network.

[0013] Specifically, the layer normalization expression in step S55 is: ; in, is the input, is the output after transformation.

[0014] Specifically, the position encoding formula in step S56 is: ; ; in, is the index of the position in the sequence, is the index of the position encoding dimension, is the dimension size of the model.

[0015] The beneficial effects of the present invention are as follows: the present invention uses a Transformers model of a deep learning architecture based on a self-attention mechanism, which has a powerful sequence modeling capability, can process sequence data, and effectively capture long-term dependencies in time series, which is particularly important for predicting the impact of meteorological factors on agricultural product prices; improves prediction accuracy, and when predicting agricultural product prices, the prediction accuracy is significantly better than other benchmark models; parallel processing capability, the self-attention mechanism of the Transformers model allows parallel processing of all elements in the input sequence, significantly improving the training efficiency of the model; strong robustness, in complex environments, such as agricultural product price prediction affected by multiple meteorological factors, the model exhibits strong robustness, and improves the stability and reliability of the prediction; improves the generalization ability of the model, the model can automatically learn important features in the input meteorological factor data, reduces dependence on artificial feature engineering, and enhances the generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.

[0017] Figure 1 This is a price prediction flow chart in an embodiment of the present invention; Figure 2 This is a flow chart of the self-attention mechanism algorithm of the ransformers model in one embodiment of the present invention. DETAILED DESCRIPTION

[0018] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0019] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0020] The following is combined with Figure 1-2 , some embodiments of the present invention are described in detail. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0021] The present invention proposes a method for predicting agricultural product prices based on a self-attention mechanism and meteorological factors, comprising the following steps: Step S1: According to the types of agricultural products, obtain the price data of previous years and the meteorological factors of the corresponding agricultural products in the corresponding time period in the selected agricultural product area; Step S2: pre-processing the selected agricultural product price data and the corresponding regional meteorological factor data; Step S3: Analyze the correlation between meteorological factor data and agricultural product prices in the corresponding time period; Step S4: Divide the obtained meteorological factor data into a training set and a test set; Step S5: construct a price prediction model of the self-attention mechanism, use the meteorological factors related to the historical agricultural product price data as input data into the price prediction model, and train the model; Step S6: For each agricultural product, the meteorological factor data related to the agricultural product price is used as input, and the trained price prediction model is used to predict the output of the corresponding agricultural product price.

[0022] In this embodiment, step S2 data preprocessing includes the following sub-steps: Step S21: completing agricultural product price data and meteorological factor data by linear interpolation method; Step S22: normalize the padded data.

[0023] In this embodiment, the linear interpolation in step S21 is specifically as follows: let the function At two o'clock , The values ​​on , , the linear interpolation calculation formula is: .

[0024] In this embodiment, the normalization process in step S22 is specifically: normalizing the agricultural product price data and the meteorological factor data, scaling the data proportionally and mapping them to [0, 1]. The specific calculation formula is: ; in , Represents the minimum and maximum values ​​of the data column respectively.

[0025] In this embodiment, step S3 correlation analysis specifically includes: Step S31: sort the pre-processed meteorological factor data and agricultural product price data by rank, and if the data points of the variables are the same, sort them by average; Step S32: For each pair of observed values , calculate the difference in ranking between two variables, the calculation formula is: , and calculate the sum of squares of all rank differences ; Step S33: Perform correlation analysis on meteorological factors and agricultural product prices through Spearman rank correlation coefficient to obtain meteorological factor data with significant correlation with agricultural product prices. The formula is: ; in, is the number of observations, is the Spearman coefficient, ranging from -1 to 1. =1, indicating a positive correlation; =-1, indicating negative correlation; =0, indicating no correlation.

[0026] In this embodiment, the price prediction model is a Transformers model based on a deep learning architecture of a self-attention mechanism. Model training and prediction include the following steps: Step S51: The meteorological factor data is used as encoder input, and after embedding processing, it is converted into a numerical representation that the model can understand, and position encoding is added to retain the time series data. The corresponding agricultural product price data is used as decoder input to generate the target sequence; Step S52: Using the scaled dot product self-attention mechanism, each element in the target sequence is processed with three different linear transformations to obtain a query vector, a key vector, and a value vector. The dot product between the query vector and the key vector is calculated and scaled, and the softmax function is applied to obtain the attention weight. The weight is applied to the value matrix to obtain the weighted summation result. The weighted summation calculation formula is: ; in is the dimension of the key vector, , , denote the query vector, key vector and value vector respectively, Represents the transpose operation of a matrix; Step S53: Use a multi-head self-attention mechanism to perform multiple self-attention operations in parallel, concatenate the results, and transform them through a linear layer; Step S54: In each encoder and decoder layer, and after the self-attention layer, the output data is further processed using a feedforward neural network, including two linear transformations and an activation function; Step S55: The meteorological factor data processed by the encoder and the agricultural product price data processed by the decoder are directly passed to the subsequent layers through residual connections, and layer normalization is applied to the outputs of the encoder and decoder to ensure that the mean of each feature is 0 and the variance is 1; Step S56: Use position encoding to provide the Transformers model with the position information of the words in the sequence. Position encoding generates a unique vector for each position in the sequence, so that the Transformers model can distinguish elements at different positions and perceive the relative order. Step S57: Use historical meteorological factor data and agricultural product price data to train the model. After the model training is completed, use new meteorological factor data as input to predict future agricultural product prices through the model.

[0027] In this embodiment, step S53 performs transformation through a linear layer as follows: ; Among them, each The calculation is: ; in, , and Represent three weight matrices respectively.

[0028] In this embodiment, the feedforward neural network expression in step S54 is: ; in, is the output of the self-attention layer, , , , are the parameters of the network.

[0029] In this embodiment, the layer normalization expression in step S55 is: ; in, is the input, is the output after transformation.

[0030] In this embodiment, the position encoding formula in step S56 is: ; ; in, is the index of the position in the sequence, is the index of the position encoding dimension, is the dimension size of the model.

[0031] In one embodiment, if Figure 1 As shown in FIG. 1 , a method for predicting agricultural product prices based on meteorological factors, based on a self-attention mechanism algorithm, includes the following steps: S1: Collect historical price data based on agricultural product types and meteorological factors in the corresponding time period for the selected agricultural product areas; S2: Preprocessing the selected agricultural product price data and the corresponding regional meteorological factor data; S3: Analyze the correlation between meteorological factors and agricultural product prices in the corresponding time period; S4: Divide the obtained data into a training set and a test set; S5: constructing a prediction model of a self-attention mechanism, wherein the price prediction model is used to take meteorological factors related to historical agricultural product price data as input data, and predict output corresponding agricultural product price prediction; S6: For each agricultural product, the meteorological factor data related to the agricultural product price is used as input, and the corresponding agricultural product price is predicted and output through the corresponding trained price prediction model.

[0032] In one embodiment, in the above step S1, the regions are divided by writing Python scripts, and the agricultural product price data is automatically obtained from the specified interface using the Requests library. The meteorological factor data of previous years are obtained through basic meteorological data and products such as ground, high altitude, meteorological satellite, weather radar, etc., such as: daily temperature (T), precipitation (R), evaporation (EVP), air pressure (P), humidity (RH), surface temperature (T0), solar radiation (SSH), etc.

[0033] In this embodiment, in step S2, the agricultural product price data and meteorological factor data are supplemented by linear interpolation method. Linear interpolation is a relatively simple interpolation method, and its interpolation function is a first-order polynomial, and the interpolation error at each interpolation node is 0. Assume that the function At two o'clock , The values ​​on , , the linear interpolation calculation formula is: ; In this embodiment, the agricultural product price data and meteorological factor data are normalized by Min-MaxNormalization, and the data are scaled and mapped to [0, 1]. The specific calculation formula is: ; in , Represents the minimum and maximum values ​​of the data column respectively.

[0034] In this embodiment, in the above step S3, the meteorological factor data and agricultural product price data that have been preprocessed in the early stage are ranked, and if the data points of the variables are the same, they are assigned an average ranking.

[0035] For each pair of observations , calculates the difference in ranking between two variables , and calculate the sum of squares of all rank differences ; The Spearman rank correlation coefficient (SROCC) was used to conduct correlation analysis on meteorological factors and agricultural product prices. The specific formula is as follows: ; in, is the number of observations, is the Spearman coefficient, ranging from -1 to 1. =1, indicating positive correlation; =-1, indicating negative correlation; =0, indicating no correlation, and the meteorological factors data with significant correlation with agricultural product prices were obtained. For example, for the prices of thermophilic agricultural products, the meteorological factors with the greatest impact are surface temperature (T0), solar radiation (SSH), and air pressure (P).

[0036] In one embodiment, in the above step S4, 80% of the obtained data is divided into a training set and 20% into a test set.

[0037] like Figure 2 As shown, a Transformers model with a deep learning architecture based on a self-attention mechanism is constructed. The price prediction model is used to take meteorological factors related to historical agricultural product price data as input data, and the prediction output corresponds to the agricultural product price prediction.

[0038] In one embodiment, in the above step S5, the above-mentioned sorted meteorological factor data is used as the encoder input, and is converted into a numerical representation that can be understood by the model after embedding processing, and position encoding is added to retain the time series data. The corresponding agricultural product price data is used as the decoder input, and these representations and its own previous output are used to generate the target sequence.

[0039] In this embodiment, the Scaled Dot-Product Attention mechanism is used. Each element in the target sequence generated by meteorological factors and agricultural product prices is processed by three different linear transformations (i.e., weight matrices) to obtain the query (Query, Q), key (key, k), and value (Value. V). The dot product between the query and the key is calculated and scaled, and then the softmax function is applied to obtain the attention weight. Finally, these weights are applied to the value matrix to obtain the weighted summation result. The specific formula is as follows: ; in is the dimension of the key vector, , , denote the query vector, key vector and value vector respectively, Represents the transpose operation of a matrix.

[0040] In one embodiment, the query, key, and value are split into multiple heads, each head corresponds to a set of Q, K, and V, and a multi-head self-attention mechanism is used to perform multiple self-attention operations in parallel, concatenate the results, and then transform them through a linear layer: ; Among them, each The calculation is: , , and Represent three weight matrices respectively.

[0041] In one embodiment, in each encoder and decoder layer, the output data is further processed by a feed-forward network after the self-attention layer, including two linear transformations and an activation function (ReLU). The formula of FFN can be expressed as: ; in, is the output of the self-attention layer, , , , is the parameter of the network. It enables the model to capture long-distance dependencies in sequence data and perform effective feature extraction.

[0042] In this embodiment, the meteorological factor data processed by the encoder and the agricultural product price data processed by the decoder are directly passed to the subsequent layers through residual connection, and layer normalization is applied to the output of the encoder and decoder to ensure that the mean of each feature is 0 and the variance is 1. The specific formula is: ; in, is the input, It is the output after some transformation (such as convolution, full connection, etc.).

[0043] In this embodiment, positional encoding is used to provide the Transformers model with the position information of words in the sequence. Positional encoding generates a unique vector for each position in the sequence, so that the Transformers model can distinguish elements at different positions and perceive their relative order. The formula is: ; ; in, is the index of the position in the sequence, is the index of the position encoding dimension, is the dimension size of the model;

[0044] In one embodiment, in the above step S5, 80% of the historical meteorological factor data and agricultural product price data sets are used to train the model. After the model training is completed, the 20% test set divided in the above step is used for testing. Through the result analysis, it is concluded that the model prediction result is more consistent with the actual result, and the prediction accuracy is higher. In one embodiment, new meteorological factor data predicted by the Meteorological Bureau is used as input to predict future agricultural product prices through a Transformers model based on a deep learning architecture with a self-attention mechanism.

[0045] For the aforementioned embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily required by the present application.

[0046] The above embodiments describe the basic principles and main features of the present invention and the advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the changes and modifications made by those skilled in the art shall be within the scope of protection of the appended claims of the present invention without departing from the spirit and scope of the present invention.

Claims

1. The agricultural product price prediction method based on self-attention mechanism and meteorological factors is characterized by: The following steps are involved: Step S1: According to the types of agricultural products, obtain the price data of previous years and the meteorological factors of the corresponding agricultural products in the corresponding time period in the selected agricultural product area; Step S2: pre-processing the selected agricultural product price data and the corresponding regional meteorological factor data; Step S3: Analyze the correlation between meteorological factor data and agricultural product prices in the corresponding time period; Step S4: Divide the obtained meteorological factor data into a training set and a test set; Step S5: construct a price prediction model of the self-attention mechanism, use the meteorological factors related to the historical agricultural product price data as input data into the price prediction model, and train the model; Step S6: For each agricultural product, the meteorological factor data related to the agricultural product price is used as input, and the trained price prediction model is used to predict the output of the corresponding agricultural product price.

2. The agricultural product price prediction method based on self-attention mechanism and meteorological factors according to claim 1, characterized in that: The step S2 data preprocessing includes the following sub-steps: Step S21: completing agricultural product price data and meteorological factor data by linear interpolation method; Step S22: normalize the padded data.

3. The agricultural product price prediction method based on self-attention mechanism and meteorological factors as claimed in claim 2, characterized in that: The linear interpolation in step S21 is specifically as follows: let the function At two o'clock , The values ​​on , , the linear interpolation calculation formula is: 。 4. The agricultural product price prediction method based on self-attention mechanism and meteorological factors as claimed in claim 2, characterized in that: The normalization process in step S22 is specifically: normalizing the agricultural product price data and the meteorological factor data, scaling the data proportionally and mapping them to the range [0, 1]. The specific calculation formula is: ; in , Respectively represent the minimum and maximum values ​​of the data column.

5. The agricultural product price prediction method based on self-attention mechanism and meteorological factors as claimed in claim 4, characterized in that: The step S3 correlation analysis specifically includes: Step S31: sort the pre-processed meteorological factor data and agricultural product price data by rank, and if the data points of the variables are the same, sort them by average; Step S32: For each pair of observed values , calculate the difference in ranking between two variables, the calculation formula is: , and calculate the sum of squares of all rank differences ; Step S33: Perform correlation analysis on meteorological factors and agricultural product prices through Spearman rank correlation coefficient to obtain meteorological factor data with significant correlation with agricultural product prices. The formula is: ; in, is the number of observations, is the Spearman coefficient, ranging from -1 to 1. =1, indicating positive correlation; =-1, indicating negative correlation; =0, indicating no correlation.

6. The agricultural product price prediction method based on self-attention mechanism and meteorological factors according to claim 5, characterized in that: The price prediction model is a Transformers model based on a deep learning architecture of the self-attention mechanism. Model training and prediction include the following steps: Step S51: The meteorological factor data is used as encoder input, and after embedding processing, it is converted into a numerical representation that the model can understand, and position encoding is added to retain the time series data. The corresponding agricultural product price data is used as decoder input to generate the target sequence; Step S52: Using the scaled dot product self-attention mechanism, each element in the target sequence is processed with three different linear transformations to obtain a query vector, a key vector, and a value vector. The dot product between the query vector and the key vector is calculated and scaled, and the softmax function is applied to obtain the attention weight. The weight is applied to the value matrix to obtain the weighted summation result. The weighted summation calculation formula is: ; in is the dimension of the key vector, , , denote the query vector, key vector and value vector respectively, Represents the transpose operation of a matrix; Step S53: Use a multi-head self-attention mechanism to perform multiple self-attention operations in parallel, concatenate the results, and transform them through a linear layer; Step S54: In each encoder and decoder layer, and after the self-attention layer, the output data is further processed using a feedforward neural network, including two linear transformations and an activation function; Step S55: The meteorological factor data processed by the encoder and the agricultural product price data processed by the decoder are directly passed to the subsequent layers through residual connections, and layer normalization is applied to the outputs of the encoder and decoder to ensure that the mean of each feature is 0 and the variance is 1; Step S56: Use position encoding to provide the Transformers model with the position information of the words in the sequence. Position encoding generates a unique vector for each position in the sequence, so that the Transformers model can distinguish elements at different positions and perceive the relative order. Step S57: Use historical meteorological factor data and agricultural product price data to train the model. After the model training is completed, use new meteorological factor data as input to predict future agricultural product prices through the model.

7. The agricultural product price prediction method based on self-attention mechanism and meteorological factors according to claim 6, characterized in that: The step S53 is transformed by a linear layer and the calculation formula is: ; Among them, each The calculation is: ; in, , and Represent three weight matrices respectively.

8. The agricultural product price prediction method based on self-attention mechanism and meteorological factors according to claim 6, characterized in that: The feedforward neural network expression of step S54 is: ; in, is the output of the self-attention layer, , , , are the parameters of the network.

9. The method for predicting agricultural product prices based on self-attention mechanism and meteorological factors according to claim 6, characterized in that: The normalized expression of the step S55 layer is: ; in, is the input, is the output after transformation.

10. The agricultural product price prediction method based on self-attention mechanism and meteorological factors according to claim 6, characterized in that: The position coding formula of step S56 is: ; ; in, is the index of the position in the sequence, is the index of the position encoding dimension, is the dimension size of the model.

Citation Information

Patent Citations

  • Agricultural product price prediction method, storage medium and computing device

    CN112446735A

  • Agricultural product prediction method and system

    CN113469746A

  • Agricultural product market price early warning management system and method based on big data analysis

    CN116664213A