A football prediction method and system based on dynamic causal networks and random forests
By combining dynamic causal networks with random forests, this method solves the problem of characterizing nonlinear relationships and dynamic interactions in football matches, achieving high-precision, interpretable football match predictions with continuous learning and dynamic adaptation capabilities.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NANTONG UNIV
- Filing Date
- 2026-03-09
- Publication Date
- 2026-06-02
AI Technical Summary
Existing technologies are insufficient to effectively characterize the complex nonlinear relationships and dynamic interactions in football matches, lack the ability to dynamically adapt to match results, and have poor model interpretability, making it difficult to conduct differential analysis and accurate prediction.
This paper adopts a method combining dynamic causal networks and random forests. The dynamic causal network is constructed using the PCMCIplus algorithm, and a temporal feature system is built by combining football knowledge. The SMOTETomek algorithm is used to handle the class imbalance problem, and the random forest model is optimized by XGBoost. The interpretation and analysis are combined with SHAP value and global feature importance to achieve continuous learning and dynamic adaptation of the model.
It significantly enhances the ability to analyze differences in specific confrontation scenarios, improves prediction accuracy and model interpretability, ensures the ability to fit complex structured data and dynamic adaptability, and realizes an interpretable decision support tool.
Smart Images

Figure CN122132779A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the interdisciplinary field of artificial intelligence and sports science, and in particular to a football prediction method and system based on dynamic causal networks and random forests. Background Technology
[0002] Predicting football match results is a core topic in sports data analysis and business decision support, with significant practical applications in key areas such as risk management, tactical planning for professional clubs, and player evaluation. Traditional prediction methods primarily rely on expert experience or regression models based on simple statistical indicators. While these methods offer good interpretability, they struggle to effectively characterize the complex nonlinear relationships and dynamic interactions within football matches, resulting in limitations in prediction accuracy. Furthermore, they are ill-suited to the increasingly diverse and high-dimensional data characteristics of modern football events.
[0003] In recent years, with the increasing popularity of football data acquisition technology and the continuous expansion of data scale, machine learning-based prediction methods have become the mainstream research paradigm and technical path in this field. Some studies have significantly improved the model's fitting ability and generalization performance to structured data by constructing multiple decision trees and aggregating their prediction results. However, such methods still have limitations: although complex models represented by machine learning algorithms can improve prediction accuracy, they lack the ability to continuously adapt to the dynamic evolution of football matches, and the decision-making process is usually regarded as a "black box," with its internal logic difficult to explain, making it impossible to effectively analyze the key factors affecting the match results. In addition, the integration of contextual factors and prediction models is still superficial, making it difficult to conduct differential analysis and accurate prediction for different specific match scenarios. Summary of the Invention
[0004] In view of the shortcomings of the prior art, the purpose of this invention is to provide a football prediction method and system based on dynamic causal networks and random forests to solve one or more problems in the prior art.
[0005] To achieve the above objectives, the technical solution of the present invention is as follows:
[0006] A football prediction method based on dynamic causal networks and random forests, the method comprising the following steps:
[0007] S1. Data acquisition steps: Obtain raw data of football matches based on web crawling technology, process and store it in the system database;
[0008] S2. Data Preprocessing and Standardization: The original data in the database is processed sequentially for missing values, outlier removal, composite field splitting, and data standardization to build a continuously updated time-series data pool.
[0009] S3. Dynamic Feature Engineering and Causal Network Construction: Based on the PCMCIplus algorithm, dynamic causal networks are analyzed and constructed, and a temporal feature system is constructed by combining football knowledge.
[0010] S4. Dataset partitioning: Divide the time series data pool into training set, validation set and test set according to time order, and reserve an independent real-time prediction data source;
[0011] S5. Class Imbalance Handling: Based on the SMOTETomek hybrid sampling algorithm, temporal proximity constraints and style adversarial constraints are introduced to resample the training set;
[0012] S6. Improvement and training of the random forest model: Based on the dynamic hyperparameter optimization of the XGBoost regression model, and combined with the training and validation sets, an improved final random forest model is obtained.
[0013] S7. Multi-dimensional model evaluation steps: Evaluate the improved random forest model based on the test set and real-time prediction data source;
[0014] S8. Results Analysis and Application: Local prediction interpretations are obtained based on the global feature importance of random forest and SHAP value, and the key data indicators affecting the competition results are interpreted and analyzed by combining dynamic causal network cross-validation.
[0015] S9. System Evolution: Regularly and automatically iterate and update the feature system, model, and knowledge base to achieve continuous learning capabilities.
[0016] Furthermore, step S3, dynamic feature engineering and causal network construction, includes the following steps:
[0017] S31. Preliminary screening of technical indicators: Eliminating highly redundant features through correlation analysis;
[0018] S32. Constructing a dynamic causal network: Analyzing the dynamic causal relationship between technical indicators and competition results by introducing the PCMCIplus algorithm;
[0019] S33. Constructing temporal features: Based on the causal discovery results and football knowledge, the features include the team's recent performance characteristics and historical match style characteristics. The causal discovery results are determined through causal strength analysis. If there is a strong correlation, key features are extracted; if there is a weak correlation, invalid features are removed.
[0020] S34. Data Storage: Store the formed feature set and the corresponding causal network graph into the system model library.
[0021] Furthermore, step S5, the category imbalance handling, includes the following steps:
[0022] S51. Training set balancing: Balancing minority class samples for draws and away wins based on the SMOTETomek algorithm;
[0023] S52. Constraint optimization based on SMOTETomek algorithm: Time proximity constraint refers to real match data with similar time periods, and style confrontation constraint refers to the tactical styles of the two opposing sides. The tactical styles in the style confrontation constraint are obtained by unsupervised clustering of the team's historical technical statistics based on the K-Means clustering algorithm, including ball possession dominance, fast counter-attack and solid defense.
[0024] S53. Resampling and Data Storage: Save the historical competition samples referenced during the sampling process, the generated synthetic samples, and the sampling strategy parameters to the system sample library.
[0025] Furthermore, resampling includes the following steps:
[0026] The constrained optimized SMOTETomek algorithm selects nearest neighbors and generates minority class samples by linear interpolation.
[0027] Based on the Tomek Links undersampling method, Tomek Links pairs on the boundary are identified, and boundary samples of the majority class are removed;
[0028] Output a balanced dataset.
[0029] Furthermore, the improvement and training of the random forest model in step S6 includes the following steps:
[0030] S61. Initial hyperparameter settings: The random forest model in the sklearn learning library is used as the prediction model;
[0031] S62. Hyperparameter pre-screening: Output the reasonable range of values for random forest parameters through the trained XGBoost regression model;
[0032] S63. Confirm the optimal hyperparameter combination: Set grid candidate values within the pre-screened parameter value range and perform cross-validation based on a hierarchical sliding window;
[0033] S64. Random Forest Model Training: Training is performed using a dataset that combines preset class weights and the training set with the validation set.
[0034] S65. Data entry: Store the trained model, corresponding parameter configuration, verification records, and scene features into the system model library and establish a performance tracking archive.
[0035] The football prediction method based on dynamic causal networks and random forests as described in claim 5, wherein obtaining a reasonable range of values for random forest parameters during hyperparameter pre-screening includes the following steps:
[0036] Predicting continuous values of random forest parameters based on XGBoot;
[0037] Discretize and round the predicted continuous values;
[0038] Apply reasonable boundary constraints to the range of hyperparameter values of the processed random forest.
[0039] As described in claim 5, a football prediction method based on dynamic causal networks and random forests, wherein the hierarchical sliding window cross-validation method is evaluated by defining cross-validators that conform to preset logic, wherein the logic includes:
[0040] Seasonal: Divided by complete historical seasons;
[0041] Phase-based: Each season is divided into the first half and the second half based on a predetermined number of matches;
[0042] Rolling Level: Divided into windows based on a preset number of matches.
[0043] Furthermore, the improved random forest model evaluation in step S7 includes:
[0044] Basic predictive performance: evaluated based on evaluation metrics;
[0045] Time series stability: Evaluation based on the volatility and downward trend of performance indicators for each time window;
[0046] Concept drift: Monitoring based on ADWIN algorithm;
[0047] Risk sensitivity: assessed by calculating the recognition rate during off-peak hours;
[0048] Adaptation speed: Evaluated by calculating the rate of performance degradation predicted by the model and the convergence speed of parameter adjustments.
[0049] Furthermore, the system evolution in step S9 includes the following steps:
[0050] The system automatically starts iterative tasks periodically.
[0051] Collect new data and merge it with historical data;
[0052] Repeat steps S1 to S9 and compare the performance of the old and new models;
[0053] Determine if the new model is better. If so, update the model and knowledge base. Otherwise, retain the original model and only update the data version.
[0054] Record completed metadata and version;
[0055] The iteration is complete and we await the next cycle.
[0056] A prediction system, applied to the aforementioned football prediction method based on dynamic causal networks and random forests, the system comprising:
[0057] Memory, used to store executable instructions;
[0058] A processor is configured to execute executable instructions stored in the memory to implement the method described above.
[0059] Compared with the prior art, the beneficial technical effects of the present invention are as follows:
[0060] (i) The method of this invention constructs a dynamic causal network by introducing the PCMCIplus algorithm, quantifying the dynamic causal strength of various technical indicators on the match result at different times, effectively capturing the nonlinear and dynamic interactive influences of football matches over time, and breaking through the limitations of traditional methods that rely on static statistical indicators. On this basis, combined with the causal discovery results and the temporal feature system constructed from football knowledge, including the team's recent form and historical match style characteristics, it significantly improves the ability to analyze differences in specific match scenarios and overcomes the problem of shallow integration of contextual factors.
[0061] (II) The method of this invention employs an improved random forest model and uses an XGBoost regression model for dynamic hyperparameter optimization and hierarchical sliding window cross-validation. This enhances the model's ability to fit complex structured data while ensuring its adaptability to changes at different time scales. By introducing the SMOTOMAKE mixed sampling algorithm and combining temporal proximity constraints and style adversarial constraints, the method effectively addresses the class imbalance problem in football matches and ensures that the synthesized samples conform to the real match context, thus avoiding model overfitting.
[0062] (III) The method of this invention integrates the global feature importance of random forest with the local interpretation of SHAP value through result analysis and application, and cross-validates with dynamic causal network, transforming the model into an interpretable decision support tool, which can transform key data indicators into tactical language and decision suggestions.
[0063] (iv) The multi-dimensional evaluation and periodic automatic iteration mechanism of the present invention realizes continuous learning and dynamic adaptation capabilities through concept drift detection and performance comparison of new and old models, ensuring that the system can evolve with the evolution of football matches and has dynamic adaptive decision support. Attached Figure Description
[0064] Figure 1 The diagram illustrates the overall process of a football prediction method and system based on dynamic causal networks and random forests according to an embodiment of the present invention.
[0065] Figure 2This illustration shows a flowchart of dynamic feature engineering and causal network construction for a football prediction method and system based on dynamic causal networks and random forests, according to an embodiment of the present invention.
[0066] Figure 3 The diagram illustrates a flowchart of a football prediction method and system based on dynamic causal networks and random forests, according to an embodiment of the present invention, to handle class imbalance.
[0067] Figure 4 This diagram illustrates the process of improving and training a random forest model for a football prediction method and system based on dynamic causal networks and random forests, according to an embodiment of the present invention.
[0068] Figure 5 The diagram illustrates the system evolution of a football prediction method and system based on dynamic causal networks and random forests according to an embodiment of the present invention. Detailed Implementation
[0069] To make the objectives, technical solutions, and advantages of this invention clearer, the following detailed description of a football prediction method and system based on dynamic causal networks and random forests, in conjunction with the accompanying drawings and specific embodiments, is provided. The advantages and features of this invention will become clearer from the following description. It should be noted that the accompanying drawings are in a very simplified form and use non-precise proportions, used only to facilitate and clearly illustrate the purpose of the embodiments of this invention. Please refer to the accompanying drawings to make the objectives, features, and advantages of this invention more apparent and understandable. It should be understood that the structures, proportions, sizes, etc., depicted in the accompanying drawings are only for illustrative purposes to aid those skilled in the art and are not intended to limit the implementation conditions of this invention. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in proportions, or adjustments to the size, without affecting the effects and objectives achieved by this invention, should still fall within the scope of the technical content disclosed in this invention.
[0070] Please refer to the following: Figures 1 to 5 The football prediction method based on dynamic causal networks and random forests in this embodiment includes the following steps:
[0071] S1. Data Acquisition Steps: Obtain raw data of football matches based on web crawling technology, process it, and store it in the system database.
[0072] Raw data from historical matches of a specific league was obtained by web scraping from publicly available data platforms. This included match times, home and away team identifiers, final scores, and various technical statistics. Irrelevant content, such as advertising text, duplicate fields, and formatting errors, was simultaneously removed from the data. The cleaned, structured data was then stored in the system database by season and time series, providing a unified data interface for subsequent analysis. Specifically:
[0073] First, Python code was used to write the web scraping code. A Chromium browser instance was created using the DrissionPage tool, configured in non-headless mode, and the User-Agent was set to simulate an Edge browser visit. The initial team statistics page for a certain league on a website was accessed as the starting point for the scraping.
[0074] Then, using BeautifulSoup, I parsed the page source code, located the dropdown selection box with id="selectTeam", and extracted all... <option>Tags are used to obtain the ID and name of each team, in preparation for subsequent traversal and crawling.
[0075] Next, iterate through the unique identifiers of each team, concatenate the corresponding technical statistics page links, and access the pages using a browser. Then, use BeautifulSoup to parse the pages again, locate the table container with id="Tech_schedule", and extract all the match data rows.
[0076] Next, for each row of data, extract the text content of all cells and construct a list. Append the current team name as an identifier to the end of each row of data and store it in the total data list;
[0077] Finally, establish a connection to the MySQL database, check and create (if not already existing) the data tables for storage, ensuring that the table structure and data format are completely matched. Generate unique identifiers for all the crawled data based on the core fields of match time, home team, and away team, and compare them with existing records in the database. Filter out all new records that do not exist in the database, and then batch insert them into the corresponding tables in the database using transactions to complete the persistent storage of the data.
[0078] S2. Data Preprocessing and Standardization: The raw data in the database undergoes sequential processing including missing value handling, outlier removal, composite field splitting, and data standardization to construct a continuously updated time-series data pool. Preprocessing and standardization systematically improve data quality and achieve a unified representation of multi-source heterogeneous data. All numerical features are standardized to eliminate the influence of units, thus forming a high-quality basic dataset. Simultaneously, all rules, transformation functions, and their parameters applied during data processing are versioned and stored to ensure the reproducibility and traceability of the entire preprocessing workflow. Specifically:
[0079] S21. Use pandas to read data from the database, handle missing values, and delete team data with a large number of missing key indicators to improve data quality.
[0080] S22. Remove outliers using the IQR method, that is, delete extreme outlier records outside of (Q1-1.5×IQR, Q3+1.5×IQR) to avoid individual extreme competition results interfering with model training.
[0081] S23. Split composite fields into independent features, for example, splitting shots (shots on target) into number of shots and number of shots on target, to enrich feature dimensions and improve the information carrying capacity of the model.
[0082] S24. Apply the Z-score standardization method to all numerical features to eliminate the dimensional differences between different indicators, so that each feature can be compared and calculated on a uniform scale, effectively avoiding the problem of feature weight imbalance caused by differences in numerical range.
[0083] S25. All parameters and rules used in the entire preprocessing process are versioned and stored to ensure the consistency and reproducibility of the data processing process, forming a complete data processing log and updating it synchronously to the system metadata database, providing a traceability basis for subsequent model iterations.
[0084] S3. Dynamic Feature Engineering and Causal Network Construction: Based on the PCMCIplus algorithm, dynamic causal networks are analyzed and constructed to quantify the influence intensity and direction of various technical indicators on the results at different times, and a time-series feature system is constructed in combination with football knowledge.
[0085] S31. Preliminary Screening of Technical Indicators: Removing Highly Redundant Features through Correlation Analysis. Using pandas' `df.corr(method='pearson')`, the Pearson correlation coefficient between all features is calculated. By iterating through the matrix, highly redundant feature pairs with correlation coefficients exceeding a preset value are removed. By prioritizing the retention of features more relevant to the competition results, feature dimensionality is effectively reduced while ensuring information integrity, avoiding interference from multicollinearity in subsequent causal inferences.
[0086] S32. Constructing a Dynamic Causal Network: This section analyzes the dynamic causal relationship between technical indicators and match results by introducing the PCMCIplus algorithm. Using the PCMCIplus algorithm from the figureite library, a sliding time window is set to a certain number of matches, i.e., a complete season. The pcmci.run_pcmci() method is used to analyze the dynamic causal relationship between technical indicators and match results. By pre-setting a confidence threshold and the maximum time lag order in the PCMCIplus algorithm, a linear conditional independence test is employed. Within each sliding window, a causal network diagram and the corresponding causal strength coefficient matrix are output, providing a dynamic causal basis for subsequent feature construction.
[0087] S33. Constructing Temporal Features: Based on causal discovery results and football knowledge construction, this includes recent team performance features and historical match-up style features. Recent team performance features are calculated based on the team's technical indicators in several recent matches, such as the average possession rate and total goals scored in matches within a preset period. Historical match-up style features are calculated based on the historical head-to-head records between specific teams, such as the home team's win rate and the away team's average goals scored in historical encounters. Causal discovery results are determined through causal strength analysis. If a strong correlation is found, key features are extracted; if a weak correlation is found, invalid features are removed. A preset causal strength threshold is used to distinguish between strongly and weakly correlated features to improve the targeting and effectiveness of feature selection.
[0088] S34. Data Storage: Store the formed feature set and corresponding causal network graph into the system model library, and store them together into the MySQL feature knowledge base using pymysql. The feature table is named features_s1, and the causal graph is named causal_graph_s1.
[0089] S4. Dataset Partitioning: The time-series data pool is divided into training, validation, and test sets according to time sequence and using stratified sampling, with a dedicated real-time prediction data source reserved. The validation and test sets are completely isolated from the training set in the timeline to prevent future information leakage. Data from the current season is not included in the data partitioning during model development but is used as an independent real-time prediction data source for subsequent simulations of the model's performance in real-world applications. Specifically...
[0090] S41. Use pandas' df.sort_values('time') to sort all matches in chronological order and assign season labels according to match time to ensure the strict chronological order of training, validation and test sets and avoid future information from polluting historical training data.
[0091] S42. The earliest consecutive complete seasons are assigned as the training set, the subsequent complete seasons as the validation set, and the latest complete seasons as the test set, with a ratio of approximately 70%, 15%, and 15%. This time series partitioning strategy ensures that the model is trained on historical data, tuned on recent data, and evaluated on the latest data, maximizing the simulation of real prediction scenarios.
[0092] S43. For the current season, as the data source for simulating real-time prediction, it does not participate in the data division during the model development stage. It is used to evaluate the model's generalization ability and response speed in a real dynamic environment. This part of the data continues to accumulate after the system is deployed, providing a forward-looking verification basis for the model iteration in the next cycle.
[0093] S5. Class Imbalance Handling: Based on the SMOTETomek hybrid sampling algorithm, temporal proximity constraints and style adversarial constraints are introduced to resample the training set. The temporal proximity constraint ensures that the synthesized samples reference the distribution of real match data from similar time periods, while the style adversarial constraint groups samples according to predefined tactical style labels of both sides to ensure that the synthesized samples basically reflect the actual situation of matches during the corresponding period. Specifically:
[0094] S51. Training set balancing: Using the SMOTETomek algorithm in the imbalanced-learn library, with sampling_strategy='auto', the minority class samples (draw and away win) in the training set are balanced to ensure that the number of samples in each class is relatively balanced and to avoid the model's tendency to overly favor the majority class (home win) in its predictions.
[0095] S52. Constraint Optimization Based on the SMOTETomek Algorithm: The time proximity constraint references real match data from similar times, while the style adversarial constraint references the tactical styles of the opposing teams. The style adversarial constraint uses K-Means clustering to obtain tactical styles from historical team statistics in an unsupervised manner, including possession-based, fast counter-attacking, and defensively solid styles. This is achieved by adding a time proximity constraint to the traditional SMOTETomek hybrid sampling algorithm, pre-setting the n_neighbors value and limiting the nearest neighbor search range to within the same season. The style adversarial constraint is further optimized by pre-setting KMeans (n_clusters value) to cluster team tactical styles.
[0096] S53. Resampling and Data Storage: The historical competition samples referenced during the sampling process, the generated synthetic samples, and the sampling strategy parameters are saved to the MySQL sample database, named sampling_records_s1. This is for subsequent evaluation and tracking of the sampling effect, and also provides a high-quality data foundation for the subsequent training of the random forest model. The sampling process is as follows:
[0097] The constrained optimization of the SMOTETomek algorithm selects nearest neighbors by setting the cluster_labels parameter to prioritize finding nearest neighbors from historical matches with the same style combination. It then uses linear interpolation to generate minority class samples, ensuring the authenticity and rationality of the synthesized samples in the tactical style dimension and avoiding the generation of virtual samples that deviate significantly from the historical match styles.
[0098] Based on the Tomek Links undersampling method, Tomek Links pairs on the boundary are identified, and boundary samples of the majority class are removed, thereby purifying the class boundaries and improving the clarity of the classifier's decision boundaries.
[0099] Output a balanced dataset to provide high-quality training samples with balanced class distribution and clear boundaries for subsequent training of the random forest model.
[0100] S6. Improvement and Training of the Random Forest Model: Based on dynamic hyperparameter optimization of the XGBoost regression model, and combined with training on merged training and validation sets, an improved final random forest model is obtained. Specifically:
[0101] S61. Initial Hyperparameter Settings: The Random Forest model from the sklearn library is used as the prediction model. Key hyperparameters of the Random Forest include the number of decision trees, maximum decision tree depth, minimum number of split samples per node, and minimum number of samples per leaf node. Initial hyperparameters are set using sklearn's RandomForestClassifier as the core prediction model. Pre-setting values for n_estimators, max_depth, min_samples_split, min_samples_leaf, and random_state provides a benchmark for subsequent hyperparameter optimization, ensuring consistency and comparability of the model training starting point.
[0102] S62. Hyperparameter Pre-screening: The trained XGBoost regression model outputs a reasonable range of values for the random forest parameters. By collecting historical records of hyperparameter tuning with a preset number of iterations and their corresponding competition scenario features, comprehensive and balanced feature coverage is ensured. Training the XGBoost regression model requires pre-setting the values of `learning_rate`, `max_depth`, and `n_estimators`. For a new prediction task, the reasonable range of values for the random forest hyperparameters is output: First, continuous values of the random forest parameters are predicted based on XGBoot. Then, the predicted continuous values are discretized and rounded. In this embodiment, a reasonable boundary constraint is finally applied to the processed range of random forest hyperparameter values to determine the reasonable range. Setting the boundary constraint involves pre-setting the interval values of `n_estimators`, `max_depth`, `min_samples_split`, and `min_samples_leaf`. Hyperparameter pre-screening effectively reduces the search space for subsequent grid search, improves hyperparameter optimization efficiency, and avoids redundant calculations in invalid parameter intervals.
[0103] S63. Confirm the optimal hyperparameter combination: Set gridded candidate values (select a preset number of discrete candidate values for each parameter) within the pre-selected parameter value range, and adopt a hierarchical sliding window cross-validation strategy. The hierarchical sliding window cross-validation method evaluates the parameters by defining a cross-validator that conforms to preset logic, where the logic includes:
[0104] Seasonal: Divided by complete historical seasons;
[0105] Phase-based: Each season is divided into the first half and the second half based on a predetermined number of matches;
[0106] Rolling Level: Divided into windows based on a preset number of matches.
[0107] The cross-validation includes three validation layers with different time scales: season-level, stage-level, and rolling-level. These layers evaluate the model's adaptability to long-term trends, mid-term stage changes, and short-term fluctuations, respectively. A custom cross-validator (ThreeLayerTimeSeriesCV) conforming to the logic of these three layers is implemented, and GridSearchCV is used with scoring='f1' for evaluation to determine the optimal combination of hyperparameters.
[0108] S64. Random Forest Model Training: The model is trained using a dataset formed by merging the training and validation sets, with predefined class weights. The final random forest model is trained by using the obtained optimal parameters and set class weights, where the weight values are inversely proportional to the frequency of each class in the original data.
[0109] S65. Data Import: The trained model, corresponding parameter configurations, validation records, and scene features are stored in the system model library, and a performance tracking archive is created. The data is saved as `rf_model_s1.pkl` using `joblib.dump()`. The corresponding parameter configurations, validation records, and scene features are also stored in the MySQL model library, named `model_records`, and a performance tracking archive is created, recording the accuracy and F1 score for each prediction. This allows the system to automatically select the optimal model or trigger a retraining process based on new data.
[0110] S7. Multi-dimensional Model Evaluation Steps: Evaluate the improved random forest model based on the test set and real-time prediction data sources. Evaluation dimensions include: basic prediction performance, temporal stability, concept drift detection capability, and risk sensitivity, among which:
[0111] Basic predictive performance: evaluated based on metrics including accuracy, precision, recall, F1 score, and AUC-ROC value.
[0112] Time series stability: Measured by the predictive consistency index within the rolling time window, and evaluated based on the volatility and downward trend of the performance index of each time window.
[0113] Concept drift: Based on the ADWIN algorithm, continuously monitor the prediction error rate of the model on the latest data stream.
[0114] Risk sensitivity: The ability to identify low-probability but high-weight match results is assessed by calculating the recognition rate.
[0115] Adaptation speed: Evaluated by calculating the rate of performance degradation predicted by the model and the convergence speed of parameter adjustments.
[0116] Furthermore, the multi-dimensional model evaluation employs a rolling prediction mechanism, predicting the currently ongoing season data in real time to assess the model's generalization ability and adaptation speed when facing new match data. All evaluation results are stored in association with the corresponding test data version. If a performance degradation or concept drift is detected, the model update process is automatically initiated, achieving a closed-loop response between evaluation and retraining. Specifically:
[0117] S71. On an independent test set, calculate the accuracy (accuracy_score), precision (precision_score), recall (recall_score), F1 score (f1_score), and area under the AUC-ROC curve (roc_auc_score) using sklearn.metrics.
[0118] S72. In this embodiment, the test set is divided into several consecutive sub-windows in chronological order, the F1 score in each window is calculated, the variance is calculated by np.var(), the downward trend is analyzed by linear regression, and the robustness of the model performance over time is evaluated.
[0119] S73. After the model is deployed, the ADWIN algorithm in the river library is used to continuously monitor the prediction error rate of the model on the latest data stream by setting a delta value. When the error rate is detected to rise significantly and exceed the preset threshold, a model update alarm is triggered.
[0120] S74. Evaluate the model's ability to capture the results of unexpected matches, and calculate the unexpected event recognition rate = the number of correctly predicted unexpected matches / the total number of unexpected matches that actually occurred, where an unexpected match is defined as a match whose predicted probability before the match was lower than the preset value but which actually occurred.
[0121] S75. Based on the latest season data, perform continuous forward predictions, and retrain the model once by playing a certain number of matches. Calculate the model's predictive performance, i.e., the decay rate of the F1 score = (initial performance - final performance) / number of predicted matches, and the convergence rate of parameter adjustments, i.e., the number of adjustments required to reach optimal performance. Evaluate the model's generalization and adaptability.
[0122] S8. Results Analysis and Application: Local predictive interpretations are obtained based on the global feature importance and SHAP value of the random forest, and the key data indicators affecting the match results are interpreted and analyzed using dynamic causal network cross-validation. By analyzing the trained random forest model, feature importance ranking and decision paths are extracted and integrated with the local predictive interpretations calculated based on SHAP values. These are then compared and cross-validated with the dynamic causal network constructed in step S3. This transforms the key data indicators affecting the match results into understandable tactical language and decision-making suggestions, outputting a structured analysis report. Specifically:
[0123] S81. Extract the global feature importance of the random forest using rf_model.feature_importances_ and calculate the SHAP value to explain the impact of features on model prediction. Cross-validate this explanation with the dynamic causal network generated by the PCMCI+ algorithm to ensure that the feature importance ranking is consistent with the causal strength.
[0124] S82. The analysis results, including feature importance ranking, critical paths of causal networks, and model prediction explanations, are structured and stored in a MySQL knowledge base named analysis_results. This knowledge base supports SQL queries and debriefing, and provides feedback information for the next round of feature construction.
[0125] S9. System Evolution: Regularly and automatically iterate and update the feature system, model, and knowledge base to achieve continuous learning capabilities. Based on the data, features, models, and evaluation results from steps S1 to S8, the system regularly initiates an automated iteration process, achieving a closed-loop cycle from data updates, feature engineering reconstruction, model retraining to performance evaluation feedback. Each iteration is fully recorded and traceable, enabling the system to continuously learn and dynamically adapt to the evolution of football matches, thus forming an intelligent football analysis system with persistent learning capabilities. Specifically:
[0126] S91. The system automatically starts iterative tasks periodically.
[0127] S92. Collect new data and merge it with historical data. Execute the crawler program periodically to collect the latest match data and merge it with the old data.
[0128] S93. Repeat steps S1 to S9 and compare the performance of the new and old models. Compare the performance of the newly trained model and the old model over the most recent time windows.
[0129] S94. Determine whether the new model is better by testing the performance difference using a paired t-test. If the new model has a significantly higher F1 score, automatically update it as the model and knowledge base used for prediction. Otherwise, retain the original model and only update the data version.
[0130] S95. Record the completed metadata and version. Write the data of each iteration, including data version, model version, performance comparison results, update date, etc., into the MySQL system log table named system_evolution_logs using pymysql.
[0131] S96, Iteration complete, waiting for the next cycle.
[0132] The key variables in steps S1 to S9 are explained in Table 1:
[0133] Table 1
[0134]
[0135] The prediction system in this embodiment is applied to the football prediction method based on dynamic causal networks and random forests as described above. The system includes:
[0136] The memory is used to store executable instructions, including the installation files of the operating system, database management system and various algorithm libraries, as well as the collected raw competition data, preprocessed feature data, trained model files and system operation logs.
[0137] The processor is used to execute executable instructions stored in memory to implement the above methods, thereby completing the entire process of data acquisition, feature engineering, model training, prediction evaluation and system iteration in an automated manner.
[0138] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0139] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.< / option>
Claims
1. A football prediction method based on dynamic causal networks and random forests, characterized in that: The method includes the following steps: S1. Data acquisition steps: Obtain raw data of football matches based on web crawling technology, process and store it in the system database; S2. Data Preprocessing and Standardization: The original data in the database is processed sequentially for missing values, outlier removal, composite field splitting, and data standardization to build a continuously updated time-series data pool. S3. Dynamic Feature Engineering and Causal Network Construction: Based on the PCMCIplus algorithm, dynamic causal networks are analyzed and constructed, and a temporal feature system is constructed by combining football knowledge. S4. Dataset partitioning: Divide the time series data pool into training set, validation set and test set according to time order, and reserve an independent real-time prediction data source; S5. Class Imbalance Handling: Based on the SMOTETomek hybrid sampling algorithm, temporal proximity constraints and style adversarial constraints are introduced to resample the training set; S6. Improvement and training of the random forest model: Based on the dynamic hyperparameter optimization of the XGBoost regression model, and combined with the training and validation sets, an improved final random forest model is obtained. S7. Multi-dimensional model evaluation steps: Evaluate the improved random forest model based on the test set and real-time prediction data source; S8. Results Analysis and Application: Local prediction interpretations are obtained based on the global feature importance of random forest and SHAP value, and the key data indicators affecting the competition results are interpreted and analyzed by combining dynamic causal network cross-validation. S9. System Evolution: Regularly and automatically iterate and update the feature system, model, and knowledge base to achieve continuous learning capabilities.
2. The football prediction method based on dynamic causal networks and random forests as described in claim 1, characterized in that: Step S3, Dynamic Feature Engineering and Causal Network Construction, includes the following steps: S31. Preliminary screening of technical indicators: Eliminating highly redundant features through correlation analysis; S32. Constructing a dynamic causal network: Analyzing the dynamic causal relationship between technical indicators and competition results by introducing the PCMCIplus algorithm; S33. Constructing temporal features: Based on the causal discovery results and football knowledge, the features include the team's recent performance characteristics and historical match style characteristics. The causal discovery results are determined through causal strength analysis. If there is a strong correlation, key features are extracted; if there is a weak correlation, invalid features are removed. S34. Data Storage: Store the formed feature set and the corresponding causal network graph into the system model library.
3. The football prediction method based on dynamic causal networks and random forests as described in claim 1, characterized in that: Step S5, class imbalance handling, includes the following steps: S51. Training set balancing: Balancing minority class samples for draws and away wins based on the SMOTETomek algorithm; S52. Constraint optimization based on SMOTETomek algorithm: Time proximity constraint refers to real match data with similar time periods, and style confrontation constraint refers to the tactical styles of the two opposing sides. The tactical styles in the style confrontation constraint are obtained by unsupervised clustering of the team's historical technical statistics based on the K-Means clustering algorithm, including ball possession dominance, fast counter-attack and solid defense. S53. Resampling and Data Storage: Save the historical competition samples referenced during the sampling process, the generated synthetic samples, and the sampling strategy parameters to the system sample library.
4. The football prediction method based on dynamic causal networks and random forests as described in claim 3, characterized in that: Resampling includes the following steps: The constrained optimized SMOTETomek algorithm selects nearest neighbors and generates minority class samples by linear interpolation. Based on the Tomek Links undersampling method, Tomek Links pairs on the boundary are identified, and boundary samples of the majority class are removed; Output a balanced dataset.
5. The football prediction method based on dynamic causal networks and random forests as described in claim 1, characterized in that: Step S6, Improving and Training the Random Forest Model, includes the following steps: S61. Initial hyperparameter settings: The random forest model in the sklearn learning library is used as the prediction model; S62. Hyperparameter pre-screening: Output the reasonable range of values for random forest parameters through the trained XGBoost regression model; S63. Confirm the optimal hyperparameter combination: Set grid candidate values within the pre-screened parameter value range and perform cross-validation based on a hierarchical sliding window; S64. Random Forest Model Training: Training is performed using a dataset that combines preset class weights and the training set with the validation set. S65. Data entry: Store the trained model, corresponding parameter configuration, verification records, and scene features into the system model library and establish a performance tracking archive.
6. The football prediction method based on dynamic causal networks and random forests as described in claim 5, characterized in that: In the hyperparameter pre-screening process, obtaining a reasonable range of values for random forest parameters includes the following steps: Predicting continuous values of random forest parameters based on XGBoot; Discretize and round the predicted continuous values; Apply reasonable boundary constraints to the range of hyperparameter values of the processed random forest.
7. The football prediction method based on dynamic causal networks and random forests as described in claim 5, characterized in that: The hierarchical sliding window cross-validation method evaluates cross-validators by defining cross-validators that conform to preset logic, wherein the logic includes: Seasonal: Divided by complete historical seasons; Phase-based: Each season is divided into the first half and the second half based on a predetermined number of matches; Rolling Level: Divided into windows based on a preset number of matches.
8. The football prediction method based on dynamic causal networks and random forests as described in claim 1, characterized in that, The improved random forest model evaluation in step S7 includes: Basic predictive performance: evaluated based on evaluation metrics; Time series stability: Evaluation based on the volatility and downward trend of performance indicators for each time window; Concept drift: Monitoring based on ADWIN algorithm; Risk sensitivity: assessed by calculating the recognition rate during off-peak hours; Adaptation speed: Evaluated by calculating the rate of performance degradation predicted by the model and the convergence speed of parameter adjustments.
9. The football prediction method based on dynamic causal networks and random forests as described in claim 1, characterized in that: The system evolution in step S9 includes the following steps: The system automatically starts iterative tasks periodically. Collect new data and merge it with historical data; Repeat steps S1 to S9 and compare the performance of the old and new models; Determine if the new model is better. If so, update the model and knowledge base. Otherwise, retain the original model and only update the data version. Record completed metadata and version; The iteration is complete and we await the next cycle.
10. A prediction system, said system being applied to a football prediction method based on dynamic causal networks and random forests as described in any one of claims 1 to 9, characterized in that: The system includes: Memory, used to store executable instructions; A processor for executing executable instructions stored in the memory to implement the method according to any one of claims 1 to 9.