Lithium carbonate price prediction method and system, storage medium and electronic equipment
Through the combination of attention mechanism and particle swarm optimization algorithm, a time series prediction model is constructed, which solves the problem of lack of quantitative standards and insufficient accuracy in lithium carbonate price prediction, and achieves more efficient and accurate price prediction.
Patent Information
- Application Number
- CN202411136435.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, there are few quantitative standards for lithium carbonate price prediction, insufficient prediction accuracy and long time. There are few specific standards based on micro and macro analysis, and the statistical analysis modeling process is single, and the influence of multiple factors cannot be fully considered.
The attention mechanism is combined with the particle swarm optimization algorithm, and by collecting and preprocessing historical and real-time price data, the time series data set is constructed, the particle swarm optimization algorithm is initialized, the optimal hyperparameter is determined, the timing prediction model with attention mechanism is trained, and the timing prediction model with attention mechanism is carried out. Lithium carbonate price forecast.
It improves the accuracy and efficiency of lithium carbonate price prediction, solves the time-consuming and labor-intensive problems of manual debugging and grid search, and provides more accurate and fast prediction results.
Smart Images

Figure CN119107108A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure belongs to the field of data processing technology, and in particular, relates to a lithium carbonate price prediction method, system, storage medium and electronic device. Background Art
[0002] Lithium carbonate is one of the important materials for companies to produce batteries. Its price fluctuation will affect the nerves of the industry. Therefore, when companies make business decisions, they usually need to predict and analyze the price of lithium carbonate.
[0003] In the prior art, the price of lithium carbonate is usually predicted using the following three methods: (1) statistical analysis; (2) micro-level analysis; and (3) macro-level analysis.
[0004] Micro-level analysis is based on macro-level analysis and can provide qualitative research and analysis reports for enterprises, but there is no specific quantitative standard. It only provides an analysis perspective and the analysis results vary from person to person. Although statistical analysis can provide quantitative standards, its modeling process is often based on a single goal for prediction, and the price of lithium carbonate of enterprises is usually affected by many factors.
[0005] In summary, the current prediction of lithium carbonate prices has problems such as lack of quantitative standards, insufficient prediction accuracy and relatively time-consuming prediction. Summary of the invention
[0006] To solve the above problems, the present disclosure provides a lithium carbonate price prediction method and system, which adopts an attention mechanism combined with a particle swarm optimization algorithm to make lithium carbonate price prediction more accurate and save time and effort.
[0007] The present invention is achieved through the following technical solutions:
[0008] In a first aspect, an embodiment of the present disclosure provides a method for predicting the price of lithium carbonate, the method comprising:
[0009] Collect historical and real-time price data of lithium carbonate;
[0010] Preprocessing the historical price data and the real-time price data of lithium carbonate to obtain a time series data set, and dividing the time series data set into a training set, a validation set, and a test set;
[0011] Initialize the hyperparameters of the particle swarm optimization algorithm, input the time series data set into the time series prediction benchmark model with attention mechanism for pre-training, and calculate the mean square error of the pre-trained model on the validation set as the fitness function value of the particle swarm optimization algorithm;
[0012] Calculate the fitness function value of each particle in the particle swarm optimization algorithm, update the optimal position information of the particle as well as the position and speed of the particle, determine the global optimal position information, and obtain the optimal hyperparameters of the particle swarm optimization algorithm;
[0013] According to the optimal hyperparameters, a time series prediction benchmark model with an attention mechanism is trained to obtain a lithium carbonate price prediction model;
[0014] The real-time lithium carbonate price related information is input into the lithium carbonate price prediction model to make a real-time prediction of the current lithium carbonate price.
[0015] Furthermore,
[0016] Performing outlier removal, missing value filling, data normalization and time series data construction on the historical price data and the real-time price data of lithium carbonate to obtain the time series data set;
[0017] The time series data set is divided into a training set, a validation set and a training set according to the data time series and a preset ratio.
[0018] Furthermore,
[0019] Perform feature extraction on the time series data set; wherein feature extraction includes time series statistics feature extraction and time factor feature extraction.
[0020] Furthermore,
[0021] Initialize the number of particles n in the particle swarm and the initial position of each particle, where the initial position X = [x1, x2, ..., x n ] T ;
[0022] An attention mechanism is constructed in the Seq2Seq model, and the time series dataset is input into the Seq2Seq model with the attention mechanism for pre-training.
[0023] Furthermore,
[0024] On the Encoder side of the backbone network LSTM, all the intermediate layer outputs are taken out, and after matrix operation, they are input into the softmax function to obtain the attention value. The calculation method is as follows:
[0025] atte = SoftMax(W*outputs);
[0026] Among them, W represents the weight of the attention mechanism, outputs represents all outputs on the Encoder side, and atte represents the attention value;
[0027] The input calculation method on the Decoder side of the backbone network LSTM is as follows:
[0028] dec_input=atte*enc_output+s;
[0029] Among them, enc_output represents the output of the last layer on the Encoder side, s represents the hidden state on the Decoder side, and dec_input represents the input on the Decoder side of the backbone network LSTM.
[0030] Furthermore,
[0031] Determine the inertia factor of the particle swarm optimization algorithm;
[0032] Calculate the fitness function value of each particle in the particle swarm optimization algorithm;
[0033] Update the position and velocity of each particle in the particle swarm optimization algorithm;
[0034] It is determined whether a preset iteration termination condition is met, and when the preset iteration termination condition is met, the global optimal position information is determined.
[0035] Furthermore,
[0036] The inertia factor of the particle swarm optimization algorithm is calculated as follows:
[0037]
[0038] Among them, w min 、w max They represent the maximum and minimum values of the inertia factor w, t represents the current iteration number, and t max Indicates the maximum number of iterations.
[0039] Furthermore,
[0040] The calculation of the fitness function value of each particle in the particle swarm optimization algorithm includes: using the mean absolute percentage error as the fitness function value, and calculating the fitness function value in a way of the mean absolute percentage error, and the calculation method is as follows:
[0041]
[0042] Among them, y represents the label of the current input data, It represents the predicted output of the model under the current particle parameters, m represents the amount of data, mape represents the mean absolute percentage error, i is the number of particles in the particle swarm, and the value range of i is 0 to m.
[0043] Furthermore,
[0044] The position and velocity of each particle in the particle swarm optimization algorithm are updated and calculated as follows:
[0045]
[0046] Among them, w represents the inertia factor, c1 and c2 represent constants, r1 and r2 represent random numbers, t represents the number of iterations, v represents the speed, x represents the position, p i represents individual extreme value, p g It represents the extreme value of the group, i is the number of particles in the particle group, and the value range of i is 0 to m.
[0047] Furthermore,
[0048] According to the optimal hyperparameters, a time series prediction benchmark model with an attention mechanism is trained to obtain an experimental model;
[0049] The test set is used to test the accuracy of the experimental model in predicting the price of lithium carbonate. When the preset accuracy is met, the experimental model is used as the lithium carbonate price prediction model.
[0050] In a second aspect, the embodiment of the present disclosure further provides a lithium carbonate price prediction system, the lithium carbonate price prediction system comprising: a data acquisition module, a data preprocessing module, a feature extraction module, a model processing module, an algorithm optimization module and a prediction output module;
[0051] The data acquisition module is used to collect historical price data and real-time price data of lithium carbonate;
[0052] The data preprocessing module is used to preprocess the historical price data and the real-time price data of lithium carbonate;
[0053] The feature extraction module is used to extract features from the time series data set; wherein the feature extraction includes time series statistics feature extraction and time factor feature extraction;
[0054] The model processing module is used to input the time series data set into a time series prediction benchmark model with an attention mechanism for pre-training;
[0055] The algorithm optimization module is used to execute a particle swarm optimization algorithm to determine the global optimal position information of a particle swarm through the particle swarm optimization algorithm;
[0056] The prediction output module is used to train the time series prediction benchmark model with the attention mechanism using the optimal hyperparameters corresponding to the global optimal position information, obtain a lithium carbonate price prediction model, and predict the current lithium carbonate price based on real-time lithium carbonate price-related information.
[0057] In a third aspect, an embodiment of the present disclosure provides a computer-readable storage medium storing one or more programs, wherein:
[0058] When the one or more programs are executed, any of the above-mentioned lithium carbonate price prediction methods can be implemented.
[0059] In a fourth aspect, an embodiment of the present disclosure provides an electronic device, including a processor, a communication interface, the above-mentioned computer-readable storage medium and a communication bus; wherein the processor, the communication interface, and the computer-readable storage medium communicate with each other via the communication bus;
[0060] in,
[0061] The processor is configured to execute a program stored in a computer-readable storage medium.
[0062] Compared with the prior art, the present invention has the following advantages:
[0063] 1. An attention mechanism was built in the time series prediction benchmark model to provide accurate prediction of lithium carbonate prices;
[0064] 2. Use the particle swarm optimization algorithm to optimize the time series data set representing the historical price data and real-time price data of lithium carbonate to obtain the best hyperparameters, solving the time-consuming and labor-intensive problems of manual debugging and grid search.
[0065] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or be understood by implementing the present disclosure. The purpose and other advantages of the present disclosure can be realized and obtained by the structures pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] In order to more clearly illustrate the embodiments of the present disclosure 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 some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0067] Figure 1 A schematic diagram of a lithium carbonate price prediction method provided in an embodiment of the present disclosure;
[0068] Figure 2 A flow chart of a lithium carbonate price prediction method provided in an embodiment of the present disclosure;
[0069] Figure 3 A schematic diagram of a lithium carbonate price prediction system provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0071] In a first aspect, the present disclosure provides a method for predicting lithium carbonate prices. Figure 1 A schematic diagram of a lithium carbonate price prediction method provided in an embodiment of the present disclosure, such as Figure 1 As shown, the lithium carbonate price prediction method of the embodiment of the present disclosure includes:
[0072] S1: Collect historical price data and real-time price data of lithium carbonate.
[0073] Specifically, the historical price data and real-time price data of lithium carbonate are collected through price databases, real-time network information, etc. The historical price data and real-time price data specifically include: year, month, day time information, daily average price of electrolytic copper, daily average price of lithium ore, daily average price of metallic lithium and other related material prices.
[0074] S2: Preprocess the historical price data and real-time price data of lithium carbonate to obtain a time series data set, and divide the time series data set into a training set, a validation set, and a test set.
[0075] Specifically, the historical price data and real-time price data of lithium carbonate are subjected to outlier removal, missing value filling, data normalization and time series data construction to obtain a time series data set. The time series data set is divided into a training set, a validation set and a test set according to a certain ratio and the data time series.
[0076] S3: Initialize the hyperparameters of the particle swarm optimization algorithm, input the time series dataset into the time series prediction benchmark model with attention mechanism for pre-training, and calculate the mean square error of the pre-trained model on the validation set as the fitness function value of the particle swarm optimization algorithm.
[0077] Specifically, the time series prediction benchmark model with the attention mechanism is pre-trained. The training set of the time series data set can be used to pre-train the time series prediction benchmark model, and the mean square error of the pre-trained model on the validation set is calculated, and the mean square error is used as the fitness function value of the particle swarm optimization algorithm. The mean square error of the pre-trained model on the validation set can be used to evaluate the current model; it can also be used as a reference value for each subsequent particle to select the best position information according to the fitness function value. In the embodiment of the present disclosure, the time series prediction benchmark model adopts a Seq2Seq (Sequence-to-Sequence) model, and uses LSTM (Long Short-Term Memory) as the backbone network.
[0078] S4: Calculate the fitness function value of each particle in the particle swarm optimization algorithm, update the optimal position information of the particle as well as the position and speed of the particle, determine the global optimal position information, and obtain the optimal hyperparameters of the particle swarm optimization algorithm.
[0079] Specifically, after obtaining the optimal position information of the particle swarm, the position and speed of the individual particles are updated by calculating the inertia factor, the current position and speed information of each particle, and then judging whether the iteration termination condition is met according to the preset conditions. If the preset iteration termination condition is met, the global optimal position information is determined, and the hyperparameters of the particle swarm optimization algorithm are the optimal hyperparameters of the model at this time; if the preset iteration termination condition is not met, the time series data set is brought back to the time series prediction benchmark model with the attention mechanism for pre-training again, and the mean square error of the pre-trained model on the validation set is calculated, which is used as the fitness function value of the particle swarm optimization algorithm, and step S4 is executed again. Among them, the iteration termination condition includes but is not limited to the number of iterations or constraints on the global optimal position information.
[0080] S5: Based on the optimal hyperparameters, the time series prediction benchmark model with attention mechanism is trained to obtain the lithium carbonate price prediction model.
[0081] Specifically, according to the optimal hyperparameters determined in step S4, the time series prediction benchmark model with attention mechanism is trained to obtain a lithium carbonate price prediction model. In order to meet the preset accuracy requirements, before determining the lithium carbonate price prediction model, the accuracy of the model predicting the price of lithium carbonate will be tested using a test set. When the required accuracy is met, the training is completed and the lithium carbonate price prediction model is determined; when the required accuracy is not met, step S4 is repeated to obtain a new optimal hyperparameter, and the time series prediction benchmark model with attention mechanism is trained again until a lithium carbonate price prediction model that meets the required accuracy is obtained.
[0082] S6: Input the real-time lithium carbonate price related information into the lithium carbonate price prediction model to make a real-time prediction of the current lithium carbonate price.
[0083] Specifically, the real-time lithium carbonate price-related information is input into a lithium carbonate price prediction model that meets the actual accuracy requirements to predict the current lithium carbonate price. The lithium carbonate price-related information includes the daily average price of electrolytic copper, the daily average price of lithium ore, the daily average price of metallic lithium and other related material prices.
[0084] In some examples, historical price data and real-time price data of lithium carbonate are preprocessed to obtain a time series data set, specifically including:
[0085] S21: Remove outliers, fill in missing values, normalize data, and construct time series data for the historical price data and real-time price data of lithium carbonate to obtain a time series data set.
[0086] Specifically, outlier removal refers to removing data points that deviate from the normal trend in the process of processing the historical price data and real-time price data of lithium carbonate; missing value filling adopts the local window average method, that is, taking m steps back and finding the average of the missing data; data normalization refers to using the standard normalization method to convert the data to the range of 0 to 1 to eliminate the influence of different dimensions; time series data construction refers to using the sliding window method to construct the historical price data of lithium carbonate into a time series sequence so that the model can learn the time series dependency of the data. The preprocessed historical price data and real-time price data of lithium carbonate are constructed into a time series data set.
[0087] S22: Divide the time series data set into a training set, a validation set, and a training set according to the data time series and a preset ratio.
[0088] Specifically, the time series data set is divided into a training set, a validation set, and a test set according to a certain ratio and the data time series. For example, the ratio of the training set, the validation set, and the test set can be 8:1:1 or 6:2:2. The specific ratio can be adjusted according to the actual situation of the time series data set.
[0089] In some examples, historical price data and real-time price data of lithium carbonate are preprocessed to obtain a time series data set, further comprising:
[0090] S2': Extract features from the time series data set; wherein the feature extraction includes time series statistic feature extraction and time factor feature extraction.
[0091] In some examples, the hyperparameters of the particle swarm optimization algorithm are initialized, and the time series dataset is input into the time series prediction benchmark model with attention mechanism for pre-training, including:
[0092] S31: Initialize the number of particles n in the particle swarm and the initial position of each particle, where the initial position X = [x1, x2, ..., x n ] T .
[0093] Specifically, the hyperparameters include the number of particles in the particle swarm, the initial particle positions and particle velocities of the particle swarm optimization algorithm, the learning factor, and other parameters. The hyperparameters that need to be set can be selected and initialized according to the actual situation.
[0094] S32: Construct an attention mechanism in the Seq2Seq model, and input the time series dataset into the Seq2Seq model with the attention mechanism for pre-training; specifically, the training set in the time series dataset can be input into the Seq2Seq model with the attention mechanism for pre-training.
[0095] Among them, the attention mechanism is constructed in the Seq2Seq model, including:
[0096] On the Encoder side of the backbone network LSTM, all the intermediate layer outputs are taken out, and after matrix operation, they are input into the softmax function to obtain the attention value. The calculation method is as follows:
[0097] atte = SoftMax(W*outputs);
[0098] Among them, W is the weight of the attention mechanism, outputs is all outputs on the Encoder side, and atte is the attention value.
[0099] The input calculation method on the Decoder side of the backbone network LSTM is as follows:
[0100] dec_input=atte*enc_output+s;
[0101] Among them, enc_output represents the output of the last layer on the Encoder side, s represents the hidden state on the Decoder side, and dec_input represents the input on the Decoder side of the backbone network LSTM.
[0102] In some examples, step S4 of the lithium carbonate price prediction method further includes:
[0103] S41: Determine the inertia factor of the particle swarm optimization algorithm, which is calculated as follows:
[0104]
[0105] Among them, w min 、w maxThey represent the maximum and minimum values of the inertia factor w, t represents the current iteration number, and t max Indicates the maximum number of iterations.
[0106] Specifically, in the particle swarm optimization algorithm in the embodiment of the present disclosure, a larger inertia factor is conducive to jumping out of the local minimum point and facilitating global search; a smaller inertia factor is conducive to accurate local search of the current search area, which is conducive to algorithm convergence and reduces model training time. For this purpose, an adaptive linear change weight is set.
[0107] S42: Calculate the fitness function value of each particle in the particle swarm optimization algorithm. The fitness function value is calculated using the mean absolute percentage error (MAPE) as follows:
[0108]
[0109] Among them, y represents the label of the current input data, It represents the predicted output of the model under the current particle parameters, m represents the amount of data, i is the number of particles in the particle swarm, the value range of i is 0 to m, and mape represents the mean absolute percentage error, that is, mape is used as the fitness function value.
[0110] Specifically, the fitness function value of each particle is evaluated, and the position and fitness function value of the current particle are stored in the particle best position information pbest corresponding to each particle, and the best position information in the best position information pbest of each particle is stored as the best position information gbest of the particle group. When the preset iteration termination condition is met, the best position information gbest of the corresponding particle group is used as the global best position information.
[0111] S43: Update the position and velocity of each particle in the particle swarm optimization algorithm. The calculation method is as follows:
[0112]
[0113] Among them, w represents the inertia factor, c1 and c2 represent constants, r1 and r2 represent random numbers, t represents the number of iterations, v represents the speed, x represents the position, p i represents individual extreme value, p g It represents the extreme value of the group, i is the number of particles in the particle group, and the value range of i is 0 to m.
[0114] S44: Determine whether a preset iteration termination condition is met, and when the preset iteration termination condition is met, determine the global optimal position information.
[0115] Specifically, if the preset iteration termination condition is met, the global optimal position information is determined, and the hyperparameters of the particle swarm optimization algorithm at this time are the optimal hyperparameters of the model; wherein, the iteration termination condition may be the maximum number of iterations or the convergence of the fitness function value, which is not specifically limited here, and only an example is provided. If the preset iteration termination condition is not met, the time series data set is brought back to the time series prediction benchmark model with the attention mechanism for pre-training again, and the mean square error of the pre-trained model on the validation set is calculated and used as the fitness function value of the particle swarm optimization algorithm, and step S4 is executed again.
[0116] In some examples, step S5 of the lithium carbonate price prediction method further includes:
[0117] S51: Based on the optimal hyperparameters, train the time series prediction benchmark model with attention mechanism to obtain the experimental model.
[0118] Specifically, according to the optimal hyperparameters, a time series prediction benchmark model with an attention mechanism is trained to obtain an experimental model, which is used to test the accuracy of the model in predicting the price of lithium carbonate on the test set.
[0119] S52: Using the test set to test the accuracy of the experimental model in predicting the price of lithium carbonate, when the preset accuracy is met, the experimental model is used as a lithium carbonate price prediction model.
[0120] Specifically, after the test set tests the accuracy of the experimental model in predicting the price of lithium carbonate, if the required accuracy is met, the training is completed, and the experimental model at this time is used as the lithium carbonate price prediction model. When the test set tests the accuracy of the experimental model and does not meet the required accuracy, repeat step S4 to obtain a new optimal hyperparameter, train the time series prediction benchmark model with the attention mechanism again, obtain a new experimental model, and use the training set to test the accuracy of the new experimental model until an experimental model that meets the required accuracy is obtained and used as a lithium carbonate price prediction model.
[0121] A lithium carbonate price prediction method provided in an embodiment of the present disclosure constructs an attention mechanism in a time series prediction benchmark model, and provides accurate prediction of lithium carbonate prices by designing the attention mechanism. A particle swarm optimization algorithm is used to self-optimize a time series data set representing historical price data and real-time price data of lithium carbonate to obtain the best hyperparameters, thereby solving the time-consuming and labor-intensive problems of manual debugging and grid search.
[0122] In order to more clearly illustrate the lithium carbonate price prediction method provided by the present disclosure, the following is described in conjunction with specific embodiments and drawings. Figure 2 A flow chart of a lithium carbonate price prediction method provided in an embodiment of the present disclosure, such as Figure 2 As shown, the lithium carbonate price prediction method in the embodiment of the present disclosure specifically includes:
[0123] S101: Collect historical price data and real-time price data of lithium carbonate.
[0124] S102: Remove outliers, fill in missing values, normalize data, and construct time series data for historical price data and real-time price data of lithium carbonate.
[0125] S103: Construct a time series data set, and divide the time series data set into a training set, a validation set, and a test set.
[0126] S104: Initialize the number of particles n in the particle swarm and the initial position of each particle, where the initial position X = [x1, x2, ..., x n ] T .
[0127] S105: Building attention mechanism in Seq2Seq model.
[0128] S106: Input the time series dataset into the Seq2Seq model with attention mechanism for pre-training.
[0129] S107: Calculate the mean square error of the pre-trained model on the validation set, and use the mean square error as the fitness function value of the particle swarm optimization algorithm.
[0130] S108: Calculate the fitness function value of each particle in the particle swarm, and update the global optimal position information of the particle swarm and the position and speed of the individual particles.
[0131] S109: Determine whether the preset iteration termination condition is met, if so, proceed to the next step, if not, return to step S106.
[0132] S110: Determine the global optimal position information, and obtain the optimal hyperparameter corresponding to the global optimal position information.
[0133] S111: According to the optimal hyperparameters, the time series prediction benchmark model with attention mechanism is trained to obtain the experimental model.
[0134] S112: Use the test set to test the accuracy of the experimental model in predicting the price of lithium carbonate. If the required accuracy is met, the experimental model is used as a lithium carbonate price prediction model. If the required accuracy is not met, return to step S106.
[0135] S113: Inputting the real-time lithium carbonate price-related information into the lithium carbonate price prediction model to make a real-time prediction of the current lithium carbonate price.
[0136] In the second aspect, based on the same inventive concept, the disclosed embodiment also provides a lithium carbonate price prediction system corresponding to the above method, Figure 3A schematic diagram of a lithium carbonate price prediction system provided in an embodiment of the present disclosure, such as Figure 3 As shown, the lithium carbonate price prediction system includes: a data acquisition module 1, a data preprocessing module 2, a feature extraction module 3, a model processing module 4, an algorithm optimization module 5 and a prediction output module 6.
[0137] The data acquisition module 1 is used to collect historical price data and real-time price data of lithium carbonate, for example, to collect historical price data of lithium carbonate and related materials and output time series data in real time.
[0138] The data preprocessing module 2 is used to preprocess the historical price data and real-time price data of lithium carbonate, wherein the preprocessing includes missing value filling, data normalization and time series data construction, and the time series data set is divided into a training set, a validation set and a test set.
[0139] The feature extraction module 3 is used to extract features from the time series data set, wherein the feature extraction includes time series statistic feature extraction and time factor feature extraction. At the same time, the feature extraction module 3 can also be used to output the time series data set to the model processing module 4 and the algorithm optimization module 5.
[0140] The model processing module 4 is used to input the time series data set into the time series prediction benchmark model with attention mechanism for pre-training.
[0141] The algorithm optimization module 5 is used to execute the particle swarm optimization algorithm to determine the global optimal position information of the particle swarm through the particle swarm optimization algorithm.
[0142] The prediction output module 6 is used to use the optimal hyperparameters corresponding to the global optimal position information to train the time series prediction benchmark model with the attention mechanism to obtain a lithium carbonate price prediction model, and predict the current lithium carbonate price based on real-time lithium carbonate price-related information.
[0143] Continue to refer Figure 3 The data acquisition module is connected to the data preprocessing module; the data preprocessing module is connected to the feature extraction module; the feature extraction module is connected to the model processing module; the model processing module is connected to the prediction output module; among them, the algorithm optimization module and the model processing module are connected head to tail to form a closed loop.
[0144] On the third aspect, based on the same inventive concept, the embodiments of the present disclosure also provide a computer-readable storage medium storing one or more programs, which, when executed, can implement the aforementioned lithium carbonate price prediction method.
[0145] In a fourth aspect, based on the same inventive concept, an embodiment of the present disclosure further provides an electronic device, including a processor, a communication interface, a memory, and a communication bus. The processor, the communication interface, and the memory communicate with each other via the communication bus. The processor is used to execute the program stored in the aforementioned computer-readable storage medium.
[0146] It should be noted that the electrical connection between the above-mentioned units does not necessarily mean the connection between lines. An indirect connection method can be applied to the embodiments of the present disclosure as long as the purpose of the present disclosure is achieved.
[0147] Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A lithium carbonate price prediction method, characterized in that: The lithium carbonate price prediction method comprises: Collect historical and real-time price data of lithium carbonate; Preprocessing the historical price data and the real-time price data of lithium carbonate to obtain a time series data set, and dividing the time series data set into a training set, a validation set, and a test set; Initialize the hyperparameters of the particle swarm optimization algorithm, input the time series data set into the time series prediction benchmark model with attention mechanism for pre-training, and calculate the mean square error of the pre-trained model on the validation set as the fitness function value of the particle swarm optimization algorithm; Calculate the fitness function value of each particle in the particle swarm optimization algorithm, update the optimal position information of the particle as well as the position and speed of the particle, determine the global optimal position information, and obtain the optimal hyperparameters of the particle swarm optimization algorithm; According to the optimal hyperparameters, a time series prediction benchmark model with an attention mechanism is trained to obtain a lithium carbonate price prediction model; The real-time lithium carbonate price related information is input into the lithium carbonate price prediction model to make a real-time prediction of the current lithium carbonate price.
2. The method according to claim 1, characterized in that The preprocessing of the historical price data and the real-time price data of lithium carbonate to obtain a time series data set, and dividing the time series data set into a training set, a validation set, and a test set, comprises: Performing outlier removal, missing value filling, data normalization and time series data construction on the historical price data and the real-time price data of lithium carbonate to obtain the time series data set; The time series data set is divided into a training set, a validation set and a training set according to the data time series and a preset ratio.
3. The method according to claim 1 or 2, characterized in that: The lithium carbonate price prediction method further includes: Perform feature extraction on the time series data set; wherein feature extraction includes time series statistics feature extraction and time factor feature extraction.
4. The method according to claim 1, characterized in that: Initializing the hyperparameters of the particle swarm optimization algorithm, inputting the time series data set into the time series prediction benchmark model with an attention mechanism for pre-training, and calculating the mean square error of the pre-trained model on the validation set as the fitness function value of the particle swarm optimization algorithm, including: Initialize the number of particles n in the particle swarm and the initial position of each particle, where the initial position X = [x1, x2, ..., x n ] T ; An attention mechanism is constructed in the Seq2Seq model, and the time series dataset is input into the Seq2Seq model with the attention mechanism for pre-training.
5. The method according to claim 4, characterized in that The attention mechanism is constructed in the Seq2Seq model, including: On the Encoder side of the backbone network LSTM, all the intermediate layer outputs are taken out, and after matrix operation, they are input into the softmax function to obtain the attention value. The calculation method is as follows: atte = SoftMax(W*outputs); Among them, W represents the weight of the attention mechanism, outputs represents all outputs on the Encoder side, and atte represents the attention value; The input calculation method on the Decoder side of the backbone network LSTM is as follows: dec_input=atte*enc_output+s; Among them, enc_output represents the output of the last layer on the Encoder side, s represents the hidden state on the Decoder side, and dec_input represents the input on the Decoder side of the backbone network LSTM.
6. The method according to claim 1, characterized in that The method of calculating the fitness function value of each particle in the particle swarm optimization algorithm, updating the optimal position information of the particle and the position and speed of the particle, determining the global optimal position information, and obtaining the optimal hyperparameters of the particle swarm optimization algorithm includes: Determine the inertia factor of the particle swarm optimization algorithm; Calculate the fitness function value of each particle in the particle swarm optimization algorithm; Update the position and velocity of each particle in the particle swarm optimization algorithm; It is determined whether a preset iteration termination condition is met, and when the preset iteration termination condition is met, the global optimal position information is determined.
7. The method according to claim 6, characterized in that The inertia factor of the particle swarm optimization algorithm is calculated as follows: Among them, w min 、w max They represent the maximum and minimum values of the inertia factor w, t represents the current iteration number, and t max Indicates the maximum number of iterations.
8. The method according to claim 6, characterized in that The calculation of the fitness function value of each particle in the particle swarm optimization algorithm includes: using the mean absolute percentage error as the fitness function value, and calculating the fitness function value in a way of the mean absolute percentage error, and the calculation method is as follows: Among them, y represents the label of the current input data, It represents the predicted output of the model under the current particle parameters, m represents the amount of data, mape represents the mean absolute percentage error, i represents the number of particles in the particle swarm, and the value range of i is 0 to m.
9. The method according to claim 6, characterized in that The position and velocity of each particle in the particle swarm optimization algorithm are updated and calculated as follows: Among them, w represents the inertia factor, c1 and c2 represent constants, r1 and r2 represent random numbers, t represents the number of iterations, v represents the speed, x represents the position, p i represents individual extreme value, p g It represents the extreme value of the group, i is the number of particles in the particle group, and the value range of i is 0 to m.
10. The method according to claim 1, characterized in that The method of training a time series prediction benchmark model with an attention mechanism according to the optimal hyperparameters to obtain a lithium carbonate price prediction model includes: According to the optimal hyperparameters, a time series prediction benchmark model with an attention mechanism is trained to obtain an experimental model; The test set is used to test the accuracy of the experimental model in predicting the price of lithium carbonate. When the preset accuracy is met, the experimental model is used as the lithium carbonate price prediction model.
11. A lithium carbonate price prediction system, characterized in that: The lithium carbonate price prediction system comprises: a data acquisition module, a data preprocessing module, a feature extraction module, a model processing module, an algorithm optimization module and a prediction output module; The data acquisition module is used to collect historical price data and real-time price data of lithium carbonate; The data preprocessing module is used to preprocess the historical price data and the real-time price data of lithium carbonate; The feature extraction module is used to extract features from the time series data set; wherein the feature extraction includes time series statistics feature extraction and time factor feature extraction; The model processing module is used to input the time series data set into a time series prediction benchmark model with an attention mechanism for pre-training; The algorithm optimization module is used to execute a particle swarm optimization algorithm to determine the global optimal position information of a particle swarm through the particle swarm optimization algorithm; The prediction output module is used to train the time series prediction benchmark model with the attention mechanism using the optimal hyperparameters corresponding to the global optimal position information, obtain a lithium carbonate price prediction model, and predict the current lithium carbonate price based on real-time lithium carbonate price-related information.
12. A computer-readable storage medium storing one or more programs, characterized in that: When the one or more programs are executed, the lithium carbonate price prediction method described in any one of claims 1 to 10 can be implemented.
13. An electronic device comprising a processor, a communication interface, the computer-readable storage medium of claim 12, and a communication bus; wherein: The processor, the communication interface, and the computer-readable storage medium communicate with each other via a communication bus; It is characterized in that The processor is configured to execute a program stored in a computer-readable storage medium.
Citation Information
Cited By
Lithium-magnesium separation nanofiltration membrane based on particle swarm optimization design and preparation method thereof
CN120257810A
