Financial stock prediction method fusing clustering and ensemble learning

Through dynamic clustering adjustment and integrated learning technology, a highly adaptable stock prediction model is built, which solves the accuracy and stability problems of traditional methods when facing complex markets, and achieves more accurate and reliable stock price predictions.

CN118967329APending Publication Date: 2024-11-15HEBEI YUAN DA INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411159029.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

When facing complex and changing financial markets, traditional stock prediction methods are difficult to meet actual needs, and they cannot adapt to changes in stock data and the characteristics of different stock clusters in a timely manner, resulting in poor prediction results.

Method used

The dynamic clustering adjustment mechanism is used to regularly re-cluster analysis, combine integrated learning technology to build a prediction model, and utilize the advantages of different machine learning algorithms to adapt to market changes and optimize the prediction results.

Benefits of technology

It improves the accuracy and stability of stock price prediction, enables the prediction model to quickly adapt to market changes, captures the intrinsic connections between stocks, reduces the instability of a single algorithm, and provides more accurate market analysis and investment guidance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118967329A_ABST
    Figure CN118967329A_ABST
Patent Text Reader

Abstract

The invention discloses a financial stock prediction method fusing clustering and ensemble learning, and relates to the technical field of stock prediction, and the system comprises the following components: regularly collecting financial stock data including stock price, trading volume and market profit rate indexes, and carrying out the preprocessing of the data; the method comprises the following steps: preprocessing stock data, carrying out clustering analysis on the preprocessed stock data by utilizing a clustering algorithm to obtain different stock clusters, and regularly carrying out clustering analysis again and updating division of the stock clusters along with the arrival of new data. According to the method, the division and prediction model of the stock cluster can be updated in real time according to the newly arrived financial stock data, so that the prediction model can quickly adapt to the dynamic change of the market, the accuracy and reliability of the prediction result are improved, and investors are helped to timely grasp the market trend and make a more accurate investment decision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of stock prediction, and in particular to a financial stock prediction method integrating clustering and ensemble learning. Background Art

[0002] In the financial market, stock price prediction has always been the focus of investors and analysts. Accurate stock price prediction can help investors make more informed investment decisions and obtain higher returns on investment. It also affects and reflects the country's macroeconomic policies, and therefore has received widespread attention. In recent years, the use of hybrid algorithms that integrate multiple machine learning models for financial stock prediction has become a research hotspot. Predicting future stock closing price changes based on historical stock price indices is a challenging problem.

[0003] Traditional stock prediction methods are mainly based on fundamental analysis of macroeconomic indicators, industry trends, and company financial status, as well as technical analysis and market sentiment analysis. However, these methods are often powerless when dealing with complex and changing financial markets, and the prediction accuracy and stability are difficult to meet actual needs. With the rapid development of artificial intelligence and machine learning technologies, cluster analysis and ensemble learning technologies have been widely used in the field of financial stock prediction. Although cluster analysis and ensemble learning technologies have achieved certain results in financial stock prediction, there are still some challenges. First, stock data changes over time, and traditional cluster analysis and ensemble learning models often cannot adapt to these changes in time, resulting in a decrease in prediction accuracy. Second, different stock clusters have different characteristics and patterns, and different prediction models are required for prediction. However, traditional cluster analysis and ensemble learning models cannot automatically adjust to the needs of different stock clusters.

[0004] In view of the above situation, it is necessary to optimize the existing financial stock prediction method by introducing a dynamic clustering adjustment mechanism and regularly re-performing clustering analysis to adapt to market changes. At the same time, the prediction model is constructed using ensemble learning technology, which can fully utilize the advantages of different algorithms and improve prediction accuracy and stability. Therefore, it is of great significance to develop a financial stock prediction method that integrates clustering and ensemble learning and can comprehensively realize the above characteristics. Summary of the invention

[0005] The purpose of the present invention is to make up for the shortcomings of the existing technology and provide a financial stock prediction method that integrates clustering and ensemble learning. It can introduce a dynamic clustering adjustment mechanism to regularly re-perform clustering analysis to adapt to market changes. At the same time, it adopts ensemble learning technology to build a prediction model, which can make full use of the advantages of different algorithms and improve prediction accuracy and stability.

[0006] In order to solve the above technical problems, the present invention provides the following technical solutions: a financial stock prediction method integrating clustering and ensemble learning, the method comprising the following specific steps:

[0007] S100, data collection and processing: regularly collecting financial stock data, including stock prices, trading volumes, and price-earnings ratio indicators, and pre-processing the financial stock data;

[0008] S200, dynamic clustering adjustment: performing cluster analysis on the pre-processed financial stock data using a preset clustering algorithm to obtain different stock clusters. With the arrival of new data in the later period, regularly re-clustering the new data in the later period and the existing financial stock data, updating the division of the stock clusters and evaluating the quality of the clustering results, and adjusting the parameters of the clustering algorithm according to the evaluation results.

[0009] S300, building an integrated learning model: for each of the stock clusters, selecting at least one preset machine learning algorithm for training, and during the training process, using a preset cross-validation method to evaluate the performance of the model, and integrating the output results of different machine learning algorithms to obtain a final prediction result;

[0010] S400, prediction result evaluation and optimization: compare the prediction result with the actual stock price to evaluate the performance of the prediction model, adjust the parameters of the preset clustering algorithm and ensemble learning model according to the evaluation result, and perform online learning and real-time update of the prediction model.

[0011] Furthermore, the S100 performs standardization processing on the financial stock data by using a Z-score standardization algorithm, and the calculation formula is:

[0012]

[0013] Among them, z i is the standardized value, x i is the ith value in the original data set, μ is the mean of the original data set, and σ is the standard deviation of the original data set.

[0014] Further, the S200 includes:

[0015] S201, selecting a clustering algorithm according to the characteristics and requirements of the financial stock data, wherein the clustering algorithm includes K-means, hierarchical clustering, and DBSCAN, and using the selected clustering algorithm to perform initial clustering on the preprocessed financial stock data to obtain initial stock clusters;

[0016] S202, setting a time interval to re-perform clustering analysis, when the new data arrives, adding it to the existing data set, running a clustering algorithm on the data set to update the division of stock clusters;

[0017] S203, evaluating the quality of the clustering result, and adjusting the parameters of the clustering algorithm according to the evaluation result.

[0018] Furthermore, if the hierarchical clustering algorithm is used in S201 to perform initial clustering on the preprocessed financial stock data, the Euclidean distance matrix D between the preprocessed financial stock data samples is first calculated, and the calculation formula is:

[0019]

[0020] Among them, x i [k] and x j [k] are samples x in the financial stock data. i and x j The kth eigenvalue of ; According to the distance matrix D, the minimum distance method is used to construct a clustering tree, and the stock data samples are initially clustered into different stock clusters. The calculation formula of the minimum distance method is:

[0021]

[0022] Among them, min means taking the minimum value, D[p][q] is the distance between samples p and q, dist(C i ,C j ) represents cluster C i and C j The minimum distance between all pairs of data points in the dataset is calculated. With the arrival of new data in the later stage, the Euclidean distance matrix D is regularly recalculated and the clustering tree is updated to update the division of stock clusters.

[0023] Furthermore, the step S203 of evaluating the quality of the clustering result and adjusting the parameters of the clustering algorithm according to the evaluation result includes:

[0024] Calculate the clustering results of the preprocessed financial stock data samples to obtain n stock clusters. For each stock cluster i, calculate its center point and calculate the average distance d between any two sample points in the stock cluster i. ij , the average value d ij As the internal distance of stock cluster i, its calculation formula is:

[0025]

[0026] For each pair of stock clusters i and j, the distance Rij between the center points of cluster i and cluster j is calculated, and the calculation formula is:

[0027]

[0028] For each stock cluster i, the internal distance d of the stock cluster i is used ij As well as the center point distance Rij between cluster i and cluster j, calculate the maximum similarity between all other clusters and cluster i except stock cluster i, and the calculation company is:

[0029] max(R ij +R ik ) / d ij (6)

[0030] Where R ik is the distance between the center points of cluster i and cluster k;

[0031] The maximum similarities of all stock clusters i are summed and divided by the number of clusters n to obtain the DBI index, which is calculated as follows:

[0032]

[0033] The quality of clustering results is evaluated based on the DBI index. The smaller the DBI value, the better the clustering effect. With the arrival of new data in the later period, clustering analysis is regularly re-performed and the DBI index is recalculated to update the division of stock clusters and evaluate the quality of clustering results.

[0034] Further, the S300 includes:

[0035] S301, for each stock cluster, select multiple machine learning algorithms for training, including support vector machine algorithm and random forest algorithm;

[0036] S302, using the data in the stock cluster to train each selected machine learning algorithm, and during the training process, using cross validation to evaluate the performance of the model and adjust the parameters;

[0037] S303, integrating the output results of different machine learning algorithms to obtain the final prediction result.

[0038] Furthermore, if the support vector machine algorithm is used to construct the model in S301, then for each stock cluster obtained through the dynamic clustering adjustment step, the feature vector and corresponding category label of the samples in the cluster are extracted to form a training data set.

[0039] According to the principle of SVM algorithm, for each stock cluster training data set, an SVM classifier is trained to obtain the classification model of each cluster;

[0040] If the training data set is linearly separable, a linear SVM is used for processing, where the linear SVM is calculated as follows:

[0041] f(x)=sign(w·x+b) (8)

[0042] The constraint condition is: for all sample points (x i ,y i ), must satisfy y i (w·x i +b)≥1, the optimization goal is: and satisfy the constraints;

[0043] If the training data set is nonlinearly separable, nonlinear SVM is used for processing, where

[0044] The calculation formula of nonlinear SVM is:

[0045]

[0046] Among them, K(x,x i ) is the kernel function, α i is the Lagrange multiplier;

[0047] The SVM classifiers of multiple stock clusters are integrated to form an integrated learning model to obtain the final stock prediction.

[0048] Furthermore, the data in the stock cluster is used to train each selected machine learning algorithm. During the training process, cross-validation is used to evaluate the performance of the model and adjust the parameters, including:

[0049] A preprocessed financial stock data set is obtained, and the data set is randomly divided into K mutually exclusive subsets; wherein each subset has an equal size;

[0050] The current subset is used as a validation set, and the remaining K-1 subsets are used as training sets, the SVM model is trained using the training set, and the performance of the model is evaluated using the validation set to obtain relevant evaluation information;

[0051] If the relevant evaluation information carries relevant information that the model performance is not ideal, a grid search parameter adjustment method is used to try different parameter combinations. For each parameter combination, the K-fold cross validation process is repeated to evaluate the model performance under the parameter combination, and the parameter combination with the best performance on the validation set is selected as the parameters of the final model;

[0052] For each stock cluster, the determined optimal parameter combination is used to train the SVM model on the entire data set, and multiple sub-models are integrated according to the selected integration strategy to form an integrated learning model;

[0053] The current subset is used as a validation set, and the remaining K-1 subsets are used as training sets. The training set is used to train the SVM model, and the validation set is used to evaluate the performance of the model to obtain relevant evaluation information, including:

[0054] Iterate the model and record the performance indicators of the model on the validation set. After all K iterations are completed, calculate the average of the performance indicators to obtain relevant evaluation information about the performance estimate of the model on the entire dataset.

[0055] Further, the S400 includes:

[0056] S401, comparing the prediction results with the actual stock prices, calculating the prediction error, and evaluating the performance of the prediction model;

[0057] S402, adjusting the parameters of the clustering algorithm and the ensemble learning model according to the evaluation results to optimize the prediction effect, and trying to use different machine learning algorithms or ensemble strategies to further improve the prediction accuracy;

[0058] S403, when new data arrives later, it is used to update the integrated learning model in real time. By setting a threshold, when the quantity or quality of new data reaches a certain level, the retraining and updating of the model is triggered.

[0059] Furthermore, in S403, by setting a threshold, when the quantity or quality of new data reaches a certain level, retraining and updating of the model is triggered, including:

[0060] Monitor the arrival of new data in real time, including the quantity and quality of the data. When the quantity or quality of new data reaches the set threshold, trigger the model retraining and update process.

[0061] Compared with the prior art, this financial stock prediction method integrating clustering and ensemble learning has the following beneficial effects:

[0062] 1. The present invention can update the division of stock clusters and the prediction model in real time according to the newly arrived financial stock data through dynamic clustering adjustment and integrated learning model construction, so that the prediction model can quickly adapt to the dynamic changes of the market, improve the accuracy and reliability of the prediction results, and help investors grasp the market trends in time and make more accurate investment decisions.

[0063] 2. The present invention performs cluster analysis on the preprocessed stock data, divides similar stocks into the same stock cluster, and constructs a targeted ensemble learning model on each stock cluster, which can more accurately capture the intrinsic connections and characteristics between stocks and improve prediction accuracy. At the same time, ensemble learning can reduce the instability of a single algorithm by combining the output results of multiple machine learning algorithms, improve the stability and reliability of prediction results, provide investors with more accurate market analysis and investment guidance, and reduce investment risks.

[0064] Other advantages, objectives and features of the present invention will be set forth in part in the following description and, in part, will be apparent to those skilled in the art based on an examination of the following or may be taught from the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] 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 prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0066] Figure 1 This is a schematic diagram of the overall process structure of a financial stock prediction method that integrates clustering and ensemble learning;

[0067] Figure 2 This is a flowchart of a financial stock prediction method that integrates clustering and ensemble learning;

[0068] Figure 3 Flowchart of a financial stock prediction method that integrates clustering and ensemble learning. DETAILED DESCRIPTION

[0069] The technical solutions in the embodiments of the present invention are described clearly and completely below. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0070] Example 1

[0071] This embodiment aims to provide a method that can accurately predict financial stock prices, by combining clustering algorithms and ensemble learning models to achieve sensitive capture and accurate prediction of market changes.

[0072] See also Figure 1 , Figure 1The figure is a schematic diagram of the overall process structure of a financial stock prediction method integrating clustering and ensemble learning, wherein the method comprises:

[0073] S100, data collection and processing: regularly collecting financial stock data, including stock prices, trading volumes, and price-earnings ratio indicators, and pre-processing the financial stock data;

[0074] S200, dynamic clustering adjustment: performing cluster analysis on the pre-processed financial stock data using a preset clustering algorithm to obtain different stock clusters. With the arrival of new data in the later period, regularly re-clustering the new data in the later period and the existing financial stock data, updating the division of the stock clusters and evaluating the quality of the clustering results, and adjusting the parameters of the clustering algorithm according to the evaluation results.

[0075] S300, building an integrated learning model: for each of the stock clusters, selecting at least one preset machine learning algorithm for training, and during the training process, using a preset cross-validation method to evaluate the performance of the model, and integrating the output results of different machine learning algorithms to obtain a final prediction result;

[0076] S400, prediction result evaluation and optimization: compare the prediction result with the actual stock price to evaluate the performance of the prediction model, adjust the parameters of the preset clustering algorithm and ensemble learning model according to the evaluation result, and perform online learning and real-time update of the prediction model. Figure 2 , Figure 3 ,For the data collection and processing stage (S100), financial stock data is collected regularly, including stock prices, trading volume, and price-earnings ratio indicators, and the data is preprocessed using the Z-score standardization algorithm to eliminate the dimensional differences between different indicators. The calculation formula is: Among them, z i is the standardized value, x i is the ith value in the original data set, μ is the mean of the original data set, and σ is the standard deviation of the original data set.

[0077] It should be noted that during the data collection stage, the financial stock data to be processed needs to be processed, which generally includes missing value filling, data standardization, outlier processing, etc.

[0078] In the dynamic clustering adjustment stage (S200), the preprocessed stock data is clustered using a hierarchical clustering algorithm. First, the Euclidean distance matrix D between the preprocessed stock data samples is calculated. The calculation formula is: Among them, x i [k] and x j [k] are samples x iand x j The kth eigenvalue of is taken, and according to the distance matrix D, the minimum distance method is used to construct a clustering tree, and the stock data samples are initially clustered into different stock clusters. The calculation formula of the minimum distance method is: Among them, min means taking the minimum value, D[p][q] is the distance between samples p and q, dist(C i ,C j ) represents cluster C i and C j The minimum distance between all pairs of data points in the cluster. In the clustering process, the appropriate clustering algorithm is selected according to the characteristics and requirements of the data. After the initial clustering, different stock clusters are obtained. These stock clusters represent stock groups with similar characteristics or market behaviors. With the arrival of new data, clustering analysis is performed again regularly. Specifically, a time interval (daily, weekly or monthly) is set. When new data arrives, it is added to the existing data set and the clustering algorithm is rerun to update the division of stock clusters. The DBI (Davies-Bouldin Index) index is used to evaluate the quality of the clustering results. Specifically, the clustering results of the preprocessed stock data samples are calculated to obtain n stock clusters. For each stock cluster i, its center point is calculated, and the average distance d between any two sample points in cluster i is calculated. ij , as the internal distance of cluster i, its calculation formula is: For each pair of stock clusters i and j, the distance Rij between the center points of cluster i and cluster j is calculated, and the calculation formula is: For each stock cluster i, calculate the maximum similarity between all other clusters except cluster i and cluster i, that is, max(R ij +R ik ) / d ij , where R ik is the distance between the center points of cluster i and cluster k. The maximum similarities of all stock clusters i are summed and divided by the number of clusters n to obtain the DBI index, which is calculated as follows: The quality of clustering results is evaluated according to the DBI index. The smaller the DBI value, the better the clustering effect. The DBI index is recalculated regularly to evaluate the quality of clustering results and adjusted as needed.

[0079] In the integrated learning model construction stage (S300), for each stock cluster, the support vector machine (SVM) algorithm is selected for training. For each stock cluster obtained through the dynamic clustering adjustment step, the feature vector and corresponding category label of the sample in the cluster are extracted to form a training data set. According to the principle of SVM algorithm, for each stock cluster training data set, train an SVM classifier to obtain the classification model of each cluster. When training the SVM classifier, choose to use linear SVM or nonlinear SVM according to the linear separability or nonlinear separability of the data. For linear SVM, the calculation formula is: f(x) = sign(w·x+b), and the constraint condition is: for all sample points (x i ,y i ), must satisfy y i (w·x i +b)≥1, the optimization goal is: And satisfy the constraints, for nonlinear SVM, the calculation formula is: Among them, K(x,x i ) is the kernel function, α i It is a Lagrange multiplier. It integrates the SVM classifiers of multiple stock clusters to form an integrated learning model for the final stock prediction. During the training process, the cross-validation method is used to evaluate the performance of the model to ensure that the model can accurately predict the trend of stock prices. The output results of different machine learning algorithms are integrated. This can be achieved through voting, averaging or other integration strategies to obtain the final prediction results. Ensemble learning can comprehensively utilize the advantages of different algorithms to improve the accuracy and stability of predictions.

[0080] For the prediction result evaluation and optimization stage (S400), the prediction result is compared with the actual stock price to evaluate the performance of the prediction model. According to the evaluation result, the parameters of the clustering algorithm and the ensemble learning model are adjusted. For example, the K value of the clustering algorithm, the distance measurement method parameters, and the weights of different algorithms in the ensemble learning can be adjusted to optimize the prediction effect. At the same time, online learning and real-time updating of the prediction model are supported. With the arrival of new data and changes in the market, the prediction model is continuously updated and optimized to adapt to market changes and maintain the accuracy and timeliness of the prediction.

[0081] In summary, this embodiment can achieve accurate prediction of the financial stock market and provide investors with valuable reference information. Through dynamic clustering adjustment and the construction of an integrated learning model, this method can capture market trends and stock characteristics and improve the accuracy of predictions. At the same time, it supports online learning and real-time updating of prediction models, so that the method can adapt to market changes and maintain the effectiveness of predictions.

[0082] Example 2

[0083] This embodiment describes in detail a financial stock prediction method that integrates clustering and ensemble learning, and how to update the prediction algorithm when new data arrives.

[0084] First, financial stock data, including stock prices, trading volumes, and price-to-earnings ratio indicators, are collected regularly. When new data arrives, they are added to the existing data set according to established rules. In order to ensure the consistency and comparability of the data, the new data is standardized using the Z-score standardization algorithm.

[0085] As new data is added, clustering analysis is performed again regularly to update the division of stock clusters. The Euclidean distance matrix D between the newly added data samples and the existing data samples is calculated, and a clustering tree is constructed based on the distance matrix D using the minimum distance method to obtain new stock clusters. Next, the DBI index (Davies-Bouldin Index) is used to evaluate the quality of the clustering results. Specifically, the internal distance (the average distance between any two sample points in the cluster) and the inter-cluster distance (the distance between the center points of different clusters) of each stock cluster are calculated, and an evaluation value is obtained according to the calculation formula of the DBI index. The smaller the DBI value, the better the clustering effect. If the addition of new data causes the DBI value to increase significantly (that is, the clustering effect deteriorates), the parameters of the clustering algorithm (such as the number of clusters, distance threshold) will be adjusted, and the clustering algorithm will be rerun to optimize the clustering results.

[0086] For each updated stock cluster, the support vector machine algorithm is selected for training. During the training process, the cross-validation method is used to evaluate the performance of the model, and the output results of different algorithms are integrated to obtain the final prediction results. In order to verify the accuracy of the prediction model, the prediction results are compared with the actual stock prices, and the relevant performance indicators are calculated. If the performance of the prediction model is not good, the parameters of the clustering algorithm and the integrated learning model are adjusted according to the evaluation results to optimize the prediction effect.

[0087] After evaluating the performance of the prediction model, it supports online learning and real-time updating of the prediction model. When new data continues to arrive, the above steps are repeated to ensure that the prediction model can continue to adapt to dynamic changes in the market.

[0088] In summary, the update of the algorithm in this embodiment enables the financial stock prediction algorithm to process new data in real time and dynamically adjust the clustering results and prediction model according to market changes to improve the accuracy and effectiveness of the prediction.

[0089] It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above and that the invention can be implemented in other specific forms without departing from the spirit or essential features of the invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations falling within the meaning and scope of the equivalent elements of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.

Claims

1. A financial stock prediction method integrating clustering and ensemble learning, characterized in that: The method comprises: S100, data collection and processing: regularly collecting financial stock data, including stock prices, trading volumes, and price-earnings ratio indicators, and pre-processing the financial stock data; S200, dynamic clustering adjustment: using a preset clustering algorithm to perform cluster analysis on the pre-processed financial stock data to obtain different stock clusters. With the arrival of new data in the later period, regularly re-clustering the new data in the later period and the existing financial stock data, update the division of the stock clusters and evaluate the quality of the clustering results, and adjust the parameters of the clustering algorithm according to the evaluation results; S300, ensemble learning model construction: for each of the stock clusters, select at least one preset machine learning algorithm for training, and during the training process, use a preset cross-validation method to evaluate the performance of the model, and integrate the output results of different machine learning algorithms to obtain the final prediction result; S400, prediction result evaluation and optimization: compare the prediction result with the actual stock price to evaluate the performance of the prediction model, adjust the parameters of the preset clustering algorithm and ensemble learning model according to the evaluation result, and perform online learning and real-time update of the prediction model.

2. A financial stock prediction method integrating clustering and ensemble learning according to claim 1, characterized in that: The S100 performs standardization processing on the financial stock data by using a Z-score standardization algorithm, and the calculation formula is: Among them, z i is the standardized value, x i is the ith value in the original data set, μ is the mean of the original data set, and σ is the standard deviation of the original data set.

3. A financial stock prediction method integrating clustering and ensemble learning according to claim 1, characterized in that: The S200 includes: S201, selecting a clustering algorithm according to the characteristics and requirements of the financial stock data, wherein the clustering algorithm includes K-means, hierarchical clustering, and DBSCAN, and using the selected clustering algorithm to perform initial clustering on the preprocessed financial stock data to obtain initial stock clusters; S202, setting a time interval to re-perform clustering analysis, when the new data arrives, adding it to the existing data set, running a clustering algorithm on the data set to update the division of stock clusters; S203, evaluating the quality of the clustering result, and adjusting the parameters of the clustering algorithm according to the evaluation result.

4. A financial stock prediction method integrating clustering and ensemble learning according to claim 3, characterized in that: If the hierarchical clustering algorithm is used in S201 to perform initial clustering on the preprocessed financial stock data, the Euclidean distance matrix D between the preprocessed financial stock data samples is first calculated, and the calculation formula is: Among them, x i [k] and x j [k] are samples x in the financial stock data. i and x j The kth eigenvalue of ; According to the distance matrix D, the minimum distance method is used to construct a clustering tree, and the stock data samples are initially clustered into different stock clusters. The calculation formula of the minimum distance method is: Among them, min means taking the minimum value, D[p][q] is the distance between samples p and q, dist(C i , C j ) represents cluster C i and C j The minimum distance between all pairs of data points in the dataset is calculated. With the arrival of new data in the later stage, the Euclidean distance matrix D is regularly recalculated and the clustering tree is updated to update the division of stock clusters.

5. The financial stock prediction method integrating clustering and ensemble learning according to claim 3 is characterized in that: The step S203 evaluates the quality of the clustering result and adjusts the parameters of the clustering algorithm according to the evaluation result, including: Calculate the clustering results of the preprocessed financial stock data samples to obtain n stock clusters. For each stock cluster i, calculate its center point and calculate the average distance d between any two sample points in the stock cluster i. ij , the average value d ij As the internal distance of stock cluster i, its calculation formula is: For each pair of stock clusters i and j, the distance Rij between the center points of cluster i and cluster j is calculated, and the calculation formula is: For each stock cluster i, the internal distance d of the stock cluster i is used ij As well as the center point distance Rij between cluster i and cluster j, calculate the maximum similarity between all other clusters and cluster i except stock cluster i, and the calculation company is: max(R ij +R ik ) / d ij (6) Where R ik is the distance between the center points of cluster i and cluster k; The maximum similarities of all stock clusters i are summed and divided by the number of clusters n to obtain the DBI index, which is calculated as follows: The quality of clustering results is evaluated based on the DBI index. The smaller the DBI value, the better the clustering effect. With the arrival of new data in the later period, clustering analysis is regularly re-performed and the DBI index is recalculated to update the division of stock clusters and evaluate the quality of clustering results.

6. The financial stock prediction method integrating clustering and ensemble learning according to claim 1, characterized in that: The S300 includes: S301, for each stock cluster, select multiple machine learning algorithms for training, including support vector machine algorithm and random forest algorithm; S302, using the data in the stock cluster to train each selected machine learning algorithm, and during the training process, using cross validation to evaluate the performance of the model and adjust the parameters; S303, integrating the output results of different machine learning algorithms to obtain the final prediction result.

7. A financial stock prediction method integrating clustering and ensemble learning according to claim 6, characterized in that: If the support vector machine algorithm is used to build the model in S301, then for each stock cluster obtained through the dynamic clustering adjustment step, the feature vector and corresponding category label of the samples in the cluster are extracted to form a training data set. According to the principle of SVM algorithm, for each stock cluster training data set, an SVM classifier is trained to obtain the classification model of each cluster; If the training data set is linearly separable, a linear SVM is used for processing, where the linear SVM is calculated as follows: f(x)=sign(w·x+b)(8) The constraint condition is: for all sample points (x i , yi), must satisfy y i (w·x i +b)≥1, the optimization goal is: and satisfy the constraints; If the training data set is nonlinearly separable, nonlinear SVM is used for processing, where The calculation formula of nonlinear SVM is: Among them, K(x,x i ) is the kernel function, α i is the Lagrange multiplier; The SVM classifiers of multiple stock clusters are integrated to form an integrated learning model to obtain the final stock prediction.

8. The financial stock prediction method integrating clustering and ensemble learning according to claim 6, characterized in that: The data in the stock cluster is used to train each selected machine learning algorithm. During the training process, cross-validation is used to evaluate the performance of the model and adjust the parameters, including: A preprocessed financial stock data set is obtained, and the data set is randomly divided into K mutually exclusive subsets; wherein each subset has an equal size; The current subset is used as a validation set, and the remaining K-1 subsets are used as training sets, the SVM model is trained using the training set, and the performance of the model is evaluated using the validation set to obtain relevant evaluation information; If the relevant evaluation information carries relevant information that the model performance is not ideal, a grid search parameter adjustment method is used to try different parameter combinations. For each parameter combination, the K-fold cross validation process is repeated to evaluate the model performance under the parameter combination, and the parameter combination with the best performance on the validation set is selected as the parameters of the final model; For each stock cluster, the determined optimal parameter combination is used to train the SVM model on the entire data set, and multiple sub-models are integrated according to the selected integration strategy to form an integrated learning model; The current subset is used as a validation set, and the remaining K-1 subsets are used as training sets. The training set is used to train the SVM model, and the validation set is used to evaluate the performance of the model to obtain relevant evaluation information, including: Iterate the model and record the performance indicators of the model on the validation set. After all K iterations are completed, calculate the average of the performance indicators to obtain relevant evaluation information about the performance estimate of the model on the entire dataset.

9. The financial stock prediction method integrating clustering and ensemble learning according to claim 1 is characterized in that , the S400 includes: S401, comparing the prediction results with the actual stock prices, calculating the prediction error, and evaluating the performance of the prediction model; S402, adjusting the parameters of the clustering algorithm and the ensemble learning model according to the evaluation results to optimize the prediction effect, and trying to use different machine learning algorithms or ensemble strategies to further improve the prediction accuracy; S403, when new data arrives later, it is used to update the integrated learning model in real time. By setting a threshold, when the quantity or quality of new data reaches a certain level, the retraining and updating of the model is triggered.

10. A financial stock prediction method integrating clustering and ensemble learning according to claim 9, characterized in that In S403, by setting a threshold, when the quantity or quality of new data reaches a certain level, the retraining and updating of the model is triggered, including: Monitor the arrival of new data in real time, including the quantity and quality of the data. When the quantity or quality of new data reaches the set threshold, trigger the model retraining and update process.

Citation Information

Cited By

  • Industrial rotation comprehensive analysis system based on data flow

    CN121072982A