Hydrogen energy system risk factor identification and accident severity prediction method fusing XGBoost-SHAP and LSTM
By integrating XGBoost-SHAP and LSTM, a hydrogen energy system risk factor identification and accident severity prediction model is constructed, which solves the subjectivity and inexplicability of traditional evaluation methods, and realizes accurate attribution and dynamic prediction of risk factors, and supports the safety management of hydrogen energy systems.
Patent Information
- Application Number
- CN202510744666.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-02
AI Technical Summary
Traditional hydrogen energy system risk assessment methods rely on qualitative analysis and expert experience, lack systematic quantification, and cannot capture the dynamic coupling relationship in hydrogen energy systems, resulting in high subjectivity of risk assessment and unexplainable prediction results.
A method that integrates XGBoost-SHAP and LSTM is used to construct a risk factor importance evaluation model through the XGBoost algorithm, and combined with SHAP interpretability analysis, quantify the marginal contribution of accident severity, and use LSTM to establish a hydrogen accident risk severity prediction model to capture the timing dependence of risk factors.
It realizes accurate attribution and priority ranking of risk factors of hydrogen energy system, provides interpretable quantitative basis, reduces subjective bias, improves the accuracy and interpretability of risk prediction, and supports data-driven security management strategies.
Smart Images

Figure CN120579820A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of hydrogen energy safety technology and relates to a method for identifying risk factors of hydrogen energy systems and predicting accident severity by integrating XGBoost-SHAP and LSTM. Background Art
[0002] Predicting accident severity is crucial to preventing major accidents and ensuring the sustainable development of the hydrogen energy industry.
[0003] Traditional hydrogen energy system risk assessment methods primarily rely on qualitative analysis, expert experience, and simplified models. These methods often face limitations when dealing with the complex, nonlinear interactions between various risk factors. For example, manual risk identification based on historical data and expert judgment lacks systematic quantification, resulting in subjective and inaccurate risk assessments. Furthermore, traditional models typically consider risk factors independently, failing to capture the dynamic coupling relationships common in real-world hydrogen energy systems.
[0004] In recent years, machine learning techniques have shown great potential in risk assessment of complex engineering systems. Long short-term memory (LSTM) networks, with their ability to process continuous data, have been applied to predict equipment failures and safety risks in several industrial sectors. However, existing LSTM-based risk prediction methods for hydrogen energy systems have limitations. They often neglect the interpretability of prediction results, making it difficult for safety managers to understand the root causes of risks and take targeted preventive measures.
[0005] XGBoost (eXtreme Gradient Boosting) is a powerful ensemble learning algorithm that has been widely used for classification and regression tasks due to its high efficiency and accuracy. When combined with SHAP (SHapley Additive exPlanations), XGBoost can provide a detailed explanation of the contribution of each input feature to the prediction result. However, the application of the XGBoost-SHAP combination to quantifying risk factors in hydrogen energy systems remains largely unexplored.
[0006] Furthermore, while some studies have attempted to analyze hydrogen energy system risks using feature selection algorithms or time series prediction models, there is a significant gap in research that integrates risk factor identification and dynamic risk prediction into a comprehensive and interpretable framework. This lack of an integrated approach hinders the development of effective safety management strategies for hydrogen energy systems, which require accurate risk identification and reliable accident severity prediction. Summary of the Invention
[0007] In view of this, the purpose of the present invention is to provide a method for identifying risk factors and predicting accident severity in hydrogen energy systems by integrating XGBoost-SHAP and LSTM. A hydrogen energy accident cause dataset containing seven categories of core risk factors is established, and interpretable quantitative analysis is achieved through XGBoost-SHAP to solve the problem of strong subjectivity of traditional qualitative analysis.
[0008] In order to achieve the above object, the present invention provides the following technical solutions:
[0009] A method for identifying risk factors and predicting accident severity in hydrogen energy systems by integrating XGBoost-SHAP and LSTM, comprising:
[0010] S1. Obtain a hydrogen energy accident report dataset and annotate several hydrogen energy accident causal factors and hydrogen energy accident consequence levels, thereby establishing a hydrogen energy accident risk identification dataset;
[0011] S2. Use the XGBoost algorithm to build a risk factor importance assessment model, introduce the SHAP interpretability analysis method to quantify its marginal contribution to the severity of the accident, and generate a ranking of the key factor feature importance;
[0012] S3. Establish an LSTM hydrogen energy accident risk severity prediction model, input the filtered core risk factor time series data, capture the time series dependency of risk factors through hidden layer neurons, and achieve a rolling prediction of the hydrogen energy system risk level;
[0013] S4. Determine whether the predicted risk level of the hydrogen energy system exceeds the threshold. If so, trigger a graded warning and output a key causal factor explanation report.
[0014] Furthermore, in step S1, the manually labeled hydrogen energy accident causal factors include human factors, system design factors, material / manufacturing factors, installation factors, work factors, management factors, and environmental factors; the hydrogen energy accident consequence levels include accident false alarm, mild, moderate, moderate, and catastrophic accidents;
[0015] In the established hydrogen energy accident risk identification dataset, a binary representation method is used to label the causal factors of hydrogen energy accidents. If a hydrogen energy accident is directly or indirectly caused by a certain causal factor, the corresponding causal factor is assigned a value of 1, otherwise it is assigned a value of 0.
[0016] A time series multi-classification label is constructed based on the potential harmfulness and actual damage degree of hydrogen energy accidents, where the false alarm class is coded as 0, the minor accident is coded as 1, the moderate accident is coded as 2, the severe accident is coded as 3, and the catastrophic accident is coded as 4.
[0017] Furthermore, in step S2, in the established risk factor importance assessment model, a risk factor importance assessment model is built based on the XGBoost library, which uses the XGBoost classifier XGBClassifier to perform classification operations, so as to classify the risk factors of the hydrogen energy system and determine the categories to which different risk factors belong;
[0018] Initialize the objective function to the multi-classification logarithmic loss function:
[0019] Where l(·) is the logarithmic loss, y i represents the true label of the i-th sample, represents the predicted label of the i-th sample, n represents the number of samples participating in model training; K represents the number of trees in the model, f k represents the k-th tree model, Ω(·) is the regularization term used to control the complexity of the number, where:
[0020]
[0021] In the formula, γ represents the penalty coefficient of the number of leaf nodes, which is used to control the complexity of the model and avoid overfitting; λ represents the weight attenuation coefficient, which is used to control the complexity of the model; T represents the number of leaf nodes in the tree, w j represents the weight of the jth leaf node;
[0022] Then, the initial search space settings of learning rate, maximum tree depth, subsampling rate, and column sampling ratio are set, and the optimal parameter combination is determined through multi-fold cross validation;
[0023] Model training is performed based on the optimal hyperparameter combination, using a forward step-by-step algorithm for iterative optimization:
[0024]
[0025] Where η is the learning rate, f t (·) is the output of the t-th tree, x i represents the i-th training sample, i.e., a sample data containing the characteristics of various risk factors, based on which the model iteratively updates the predicted value; Indicates the predicted value of the i-th sample at the t-th iteration, It represents the predicted value of the i-th sample at the t-1th iteration.
[0026] Furthermore, XGBoost-SHAP fusion calculation analysis is used, and the process includes:
[0027] First, calculate the SHAP value of each risk factor:
[0028]
[0029] Among them, φ0 represents the benchmark value of the risk factor importance assessment model, that is, the predicted mean of all samples; φ j (·) is the contribution of a certain feature j to the prediction, and n is the number of risk factors;
[0030] Then, the average absolute SHAP value of each risk factor is calculated and normalized to obtain the relative importance of each key risk factor:
[0031]
[0032] Among them, φ i,j represents the SHAP value of the j-th risk factor in the i-th sample, and m is the number of risk factors.
[0033] Finally, the core risk factors are screened and the factors with a preset proportion of importance ranking are selected as core risk factors and used as input for the subsequent hydrogen energy risk severity prediction model.
[0034] Furthermore, in step S3, the established LSTM hydrogen energy accident risk severity prediction model includes an input layer, a hidden layer, an attention layer and an output layer, wherein the input layer receives pre-processed time series data whose dimensions are consistent with the number of core risk factors after screening; the hidden layer sets a number of LSTM units, and each LSTM unit includes a number of neurons; the attention layer calculates an attention weight vector that matches the time step based on the output of the hidden layer, highlights the key time step, and makes the model pay more attention to information important for risk severity prediction; the output layer uses the Softmax function to process the results after processing by the attention layer, and converts the output into the probability distribution of each risk level to achieve multi-classification prediction.
[0035] Furthermore, the training process for the LSTM hydrogen energy accident risk severity prediction model is as follows:
[0036] Data preprocessing: Clean the collected historical accident record data of the hydrogen energy system to remove outliers and missing values; divide the processed data into training sets and test sets according to the preset ratio;
[0037] Optimizer and learning rate settings: Use the Adam optimizer to initialize the learning rate; use the exponential decay strategy to screen the learning rate according to the preset number of rounds. The specific formula is: Among them, lr init is the initial learning rate, decay is the decay coefficient, eproh is the current training round, and step is the preset decay interval round;
[0038] Loss function and regularization: Cross entropy loss is used as the loss function, and its formula is: Where N is the number of samples, C is the number of categories, and y ij is the true label of sample i belonging to category j, whose value is 0 or 1, p ij is the probability that the model predicts that sample i belongs to category j; at the same time, an L2 regularization term is added to the loss function. λ is the regularization coefficient, w is the weight parameter of the model to prevent the model from overfitting;
[0039] Parameter update during training: In each training batch, the training data is input into the LSTM model, and the model output is calculated through forward propagation. The loss value is calculated based on the output and the true label. Then, the gradient of the loss value with respect to the parameters of each layer of the model, including weights and biases, is calculated through the backpropagation algorithm. The Adam optimizer updates the model parameters based on the calculated gradient and the set learning rate. The specific update formula is:
[0040] m t =β1m t-1 +(1-β1)g t
[0041]
[0042] where m t and v t are the estimates of the first and second order moments, g t is the current gradient, β1 and β2 are the hyperparameters of the Adam optimizer, t is the number of iterations, η is the learning rate, and ∈ is a small constant to prevent division by zero;
[0043] Early stopping mechanism: Set up an early stopping mechanism to calculate the loss value on the validation set after each training round. Record the historical loss value of the validation set. When the loss value on the validation set stops decreasing after several consecutive rounds, stop training and save the model parameters at this time to prevent model overfitting.
[0044] Model evaluation: After training, the final model is evaluated using the test set, and metrics such as mean square error and mean absolute error are calculated to measure the performance of the model.
[0045] Furthermore, when predicting the severity of hydrogen energy system risks, the operation process of the LSTM hydrogen energy accident risk severity prediction model is as follows:
[0046] (1) Input data preparation: The pre-processed accident data related to hydrogen energy system risks is used as input. The data comes from existing accident-related information, including accident risk factors and accident severity;
[0047] (2) Hidden state initialization: Initialize the hidden state, which includes the cell state c0 and the hidden layer state h0. It is usually initialized to an all-zero vector or set a suitable initial value based on experience;
[0048] (3) Cyclic unit calculation: For each time step t in the input sequence, the LSTM model performs calculations through its core cyclic unit structure; this structure mainly includes the input gate i t , forget gate f t , output gate o t and memory unit c t :
[0049] ① Input gate: i t =σ(W xi x t +W hi h t-1 +b i ), where σ is the Sigmoid activation function, W xi x t 、W hi h t-1 is the weight matrix, x t is the input of the current time step, h t-1 is the hidden layer state at the previous time step, b i is the bias term;
[0050] ②Forget gate: f t =σ(W xf x t +W hf h t-1 +b f ), which determines the information to be discarded from the memory cell;
[0051] ③Memory unit update: Get the candidate memory cell value; then Where ⊙ represents element multiplication, which realizes the update of memory unit;
[0052] ④Output gate: o t =σ(W xo x t +W ho h t-1 +b o ), determines the content of the memory unit output for calculating the hidden layer state, the hidden layer state h t =o t ⊙tanh(c t );
[0053] (4) Multi-layer processing and output: The hidden layer state h after processing by multi-layer LSTM units T, T is the last time step of the input sequence, input to the fully connected layer, the weight matrix of the fully connected layer is W f , bias is b f , then the fully connected layer output, z=W f h T +b f ; Then, the output is converted into the probability distribution of each risk level through the Softmax activation function to obtain the final prediction result:
[0054]
[0055] K is the accident risk level.
[0056] Furthermore, when the predicted severity level of the consequences of a hydrogen energy accident reaches or exceeds level 2, a blue warning is triggered; when it reaches or exceeds level 3, an orange warning is triggered; when it reaches or exceeds level 4, a red warning is triggered; at the same time, the key causal factors leading to the risk and their corresponding SHAP value explanations are output synchronously.
[0057] The beneficial effects of the present invention are:
[0058] In response to the problem of strong subjectivity in traditional hydrogen energy accident analysis, the present invention constructs a causal data set covering seven categories of core risk factors, including equipment failure, operational errors, environmental factors, management defects, design defects, third-party damage and force majeure, covering the potential risk sources of the entire life cycle of hydrogen energy. In order to solve the problem of quantifying risk attribution, a hybrid model based on XGBoost-SHAP is proposed: XGBoost fits the nonlinear relationship between risk factors and accident probability through gradient boosting trees, and the SHAP framework quantifies the marginal contribution of each factor. The SHAP value reveals the "local explanatory power" (such as the contribution of a specific failure mode to the accident) and "global importance" (such as the weight of management defects in the overall accident) of risk factors by calculating the average marginal contribution of features in all possible combinations, thereby achieving accurate attribution and priority sorting of risk factors. This method significantly reduces the subjective bias of traditional qualitative analysis and provides an explainable quantitative basis for risk management.
[0059] This paper addresses the temporal dependencies of hydrogen energy system risks and proposes a dynamic prediction model based on a long short-term memory (LSTM) network. LSTM mitigates the vanishing gradient problem through a gating mechanism, enabling long-term temporal dependency modeling. It inputs multi-dimensional time series data and outputs a probability distribution of future risk levels. Compared to traditional time series models, LSTM has significant advantages in processing nonlinear and non-stationary signals and can capture the cumulative effects of risk. By introducing an attention mechanism, the model can dynamically focus on key time windows, further improving prediction accuracy.
[0060] The hydrogen energy system risk factor identification and accident severity prediction method of the present invention provides data-driven decision support for risk classification management of hydrogen energy systems, and has important practical significance for optimizing hydrogen energy safety management strategies.
[0061] Other advantages, objects, and features of the present invention will be described in part in the following description and, in part, will be apparent to those skilled in the art upon examination of the following or may be learned from practice of the present invention. The objects and other advantages of the present invention may be realized and obtained through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention will be described in detail below with reference to the accompanying drawings, in which:
[0063] Figure 1 The present invention provides a hydrogen energy system risk factor identification and accident severity prediction method integrating XGBoost-SHAP and LSTM;
[0064] Figure 2 A diagram showing the importance ranking of key factors and features under a preferred embodiment;
[0065] Figure 3 2 is a training and validation loss curve for the LSTM model in a preferred embodiment;
[0066] Figure 4 This is a flowchart of the operation of an LSTM model for predicting the severity of hydrogen energy system risks under a preferred embodiment. DETAILED DESCRIPTION
[0067] The following describes the embodiments of the present invention by means of specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and the following embodiments and features in the embodiments can be combined with each other without conflict.
[0068] Among them, the accompanying drawings are only for illustrative purposes and represent only schematic diagrams rather than actual pictures, and should not be understood as limiting the present invention. In order to better illustrate the embodiments of the present invention, some parts of the accompanying drawings may be omitted, enlarged or reduced, and do not represent the dimensions of actual products. For those skilled in the art, it is understandable that some well-known structures and their descriptions may be omitted in the accompanying drawings.
[0069] The same or similar numbers in the drawings of the embodiments of the present invention correspond to the same or similar parts; in the description of the present invention, it should be understood that if there are terms such as "upper", "lower", "left", "right", "front", "back", etc. indicating directions or positional relationships, they are based on the directions or positional relationships shown in the drawings. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific direction, be constructed and operate in a specific direction. Therefore, the terms describing the positional relationship in the drawings are only used for illustrative purposes and cannot be understood as limiting the present invention. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to specific circumstances.
[0070] See also Figures 1 to 4 , which is a method for identifying risk factors and predicting accident severity in hydrogen energy systems by integrating XGBoost-SHAP and LSTM.
[0071] like Figure 1 As shown in the figure, the present invention proposes a method for identifying risk factors of hydrogen energy systems and predicting accident severity by integrating XGBoost-SHAP and LSTM. The specific process includes:
[0072] SS1. Obtain a hydrogen energy accident report dataset and annotate several hydrogen energy accident causal factors and hydrogen energy accident consequence levels, thereby establishing a hydrogen energy accident risk identification dataset;
[0073] S2. Use the XGBoost algorithm to build a risk factor importance assessment model, introduce the SHAP interpretability analysis method to quantify its marginal contribution to the severity of the accident, and generate a ranking of the key factor feature importance;
[0074] S3. Establish an LSTM hydrogen energy accident risk severity prediction model, input the filtered core risk factor time series data, capture the time series dependency of risk factors through hidden layer neurons, and achieve a rolling prediction of the hydrogen energy system risk level;
[0075] S4. Determine whether the predicted risk level of the hydrogen energy system exceeds the threshold. If so, trigger a graded warning and output a key causal factor explanation report.
[0076] In step S1 of this embodiment, as shown in Table 1, the seven hydrogen energy accident risk factors are human factors, system design factors, material / manufacturing factors, installation factors, work factors, management factors and environmental factors.
[0077] Table 1
[0078]
[0079]
[0080] More specifically, the consequences of hydrogen energy accidents are divided into five categories: false alarm, minor, moderate, severe and catastrophic accidents.
[0081] More specifically, the hydrogen energy accident risk identification dataset contains no less than 500 hydrogen energy accident samples. The input uses a binary representation method (0 / 1) to label the accident causative factors, covering seven major risk factors: human factors, system design errors, material / manufacturing errors, installation errors, job factors, management factors, and environmental factors. If the hydrogen energy accident is directly or indirectly caused by a specific factor, the corresponding feature is assigned a value of 1, otherwise it is 0; its output constructs a time-series multi-classification label system based on the potential harmfulness and actual degree of damage of the consequences of the hydrogen energy accident. The specific coding rules are accident false alarm → 0; mild → 1; moderate → 2; severe → 3; catastrophic accident → 4.
[0082] In step S2 of this embodiment, the XGBoost model training uses Python's Scikit-learn and XGBoost libraries to build a risk factor importance assessment model. The specific steps are as follows:
[0083] (1) Data preprocessing: The accident consequence level (0-4) is used as the classification label to construct the training set (80%) and the test set (20%);
[0084] (2) Model initialization and parameter optimization: Use XGBoost’s classifier XGBClassifier and initialize the objective function to a multi-classification logarithmic loss function: Where l(·) is the logarithmic loss, y i represents the true label of the i-th sample, represents the predicted label of the i-th sample, n represents the number of samples participating in model training; K represents the number of trees in the model, f k represents the k-th tree model, Ω(·) is the regularization term used to control the complexity of the number, where:
[0085]
[0086] In the formula, γ represents the penalty coefficient of the number of leaf nodes, which is used to control the complexity of the model and avoid overfitting; λ represents the weight attenuation coefficient, which is used to control the complexity of the model; T represents the number of leaf nodes in the tree, w j represents the weight of the jth leaf node;
[0087] The search space was set to: learning rate [0.05, 0.1, 0.15], maximum tree depth [6, 7, 8], subsampling rate [0.7, 0.8, 0.9], and column sampling ratio [0.7, 0.8, 0.9]. After 5-fold cross-validation, the optimal hyperparameter combination was determined to be: learning rate 0.1, maximum tree depth 7, subsampling 0.8, column sampling ratio 0.8, tree depth 6-8, and subsampling rate 0.7-0.9;
[0088] (3) Model training and prediction: The model is trained based on the optimal parameters (maximum tree depth = 7, subsampling rate = 0.8), and the forward step-by-step algorithm is used for iterative optimization: Where η is the learning rate, f t (·) is the output of the t-th tree, x i represents the i-th training sample, i.e., a sample data containing the characteristics of various risk factors, based on which the model iteratively updates the predicted value; Indicates the predicted value of the i-th sample at the t-th iteration, It represents the predicted value of the i-th sample at the t-1th iteration.
[0089] The SHAP interpretability analysis method in step S2 refers to the use of XGBoost-SHAP fusion calculation analysis. The specific steps are as follows:
[0090] (1) TreeSHAP algorithm accelerates calculation: through the formula Calculate the SHAP value of each risk factor, φ0 represents the benchmark value of the risk factor importance assessment model, that is, the predicted mean of all samples; φ j (·) is the contribution of a certain feature j to the prediction, n is the number of risk factors, which is 7 in this example;
[0091] (2) Global importance assessment: Calculate the average absolute SHAP value of each risk factor and normalize it to obtain the relative importance of each key risk factor: Where m is the number of risk factors, which is 7 here.
[0092] Then, based on the hydrogen energy accident risk identification dataset, the XGBoost-SHAP algorithm was used to calculate the importance ranking of risk factor features, such as Figure 2 As shown, management factors had the highest average SHAP value of 0.2955, accounting for 34.7%. This indicates that issues such as inadequate safety regulations, poor supervision, and incomplete emergency response plans significantly impacted the severity of hydrogen energy accidents. Human factors were second, with an average SHAP value of 0.2568, accounting for 30.2%. Human errors, such as improper operating procedures and lack of safety awareness, were also key factors influencing the severity of accidents.
[0093] In comparison, the average SHAP value for material / manufacturing factors was 0.0854, accounting for 10.0%; the average SHAP value for system factors was 0.0820, accounting for 9.6%; the average SHAP value for installation factors was 0.0741, accounting for 8.7%; the average SHAP value for work factors was 0.0304, accounting for 3.6%; and the average SHAP value for environmental factors was 0.0266, accounting for 3.1%. These relatively low SHAP values indicate that while these factors play a role in hydrogen accidents, their impact on accident severity is smaller than that of management and human factors.
[0094] In step S3 of this embodiment, the dimension of the input layer of the LSTM model is consistent with the number of core risk factors after screening, the hidden layer is set to 2-3 layers of LSTM units (128-256 neurons per layer), the output dimension of the attention layer matches the time step, and the output layer uses the Softmax function to achieve multi-classification prediction, aiming to predict the severity of hydrogen energy accidents (such as mild, moderate, severe or catastrophic). The Adam optimizer is selected, the initial learning rate is set to 0.001, and an exponential decay strategy is adopted. The learning rate decays to the original 0.9 every 10 epochs. The loss function uses cross entropy loss, and the L2 regularization term (regularization coefficient 0.001) is added to prevent overfitting. An early stopping mechanism is set, and training is stopped when the loss value on the validation set no longer decreases for 5 consecutive epochs. Each training cycle contains 50 epochs. The accuracy and loss value curves of the training set and validation set are monitored in real time during training, such as Figure 3 shown.
[0095] Figure 3 The following are the training and validation loss curves for the LSTM model under a preferred embodiment. It can be seen that the LSTM model exhibits good convergence characteristics during training. As the number of training iterations increases, both the training loss and validation loss show a steady downward trend. When the number of training iterations reaches 112, the validation loss of the model remains stable.
[0096] Figure 4 The following is a flowchart of the operation of an LSTM model for predicting the severity of hydrogen energy system risks under a preferred embodiment. When predicting the severity of hydrogen energy system risks, the operation process of the LSTM model is as follows:
[0097] (1) Input data preparation: The pre-processed accident data related to hydrogen energy system risks is used as input. The data comes from existing accident-related information, including accident risk factors, accident severity, etc.
[0098] (2) Hidden state initialization: Initialize the hidden state, which includes the cell state c0 and the hidden layer state h0. It is usually initialized to an all-zero vector or set a suitable initial value based on experience;
[0099] (3) Cyclic unit calculation: For each time step t in the input sequence, the LSTM model performs calculations through its core cyclic unit structure; this structure mainly includes the input gate i t , forget gate f t , output gate o t and memory unit c t :
[0100] ① Input gate: i t =σ(W xi x t +W hi h t-1 +b i ), where σ is the Sigmoid activation function, W xi x t 、W hi h t-1 is the weight matrix, x t is the input of the current time step, h t-1 is the hidden layer state at the previous time step, b i is the bias term;
[0101] ②Forget gate: f t =σ(W xf x t +W hf h t-1 +b f ), which determines which information to discard from the memory unit;
[0102] ③Memory unit update: Get the candidate memory cell value; then Where ⊙ represents element multiplication, which realizes the update of memory unit;
[0103] ④Output gate: o t =σ(W xo x t +W ho h t-1 +b o ), determine which parts of the memory unit will be output to calculate the hidden layer state, the hidden layer state h t =o t ⊙tanh(c t );
[0104] (4) Multi-layer processing and output: The hidden layer state h after processing by multi-layer LSTM units T(T is the last time step of the input sequence), input to the fully connected layer, the weight matrix of the fully connected layer is W f , bias is b f , then the fully connected layer output, z=W f h T +b f . Then through the Softmax activation function K is the accident risk level. The output is converted into the probability distribution of each risk level to obtain the final prediction result, which provides a basis for risk assessment and decision-making of the hydrogen energy system.
[0105] In step S4 of this embodiment, the smaller the values of MAE, MSE, RMSE and other indicators are, the better the prediction performance of the model is. The calculation method is: It measures the average of the squares of the errors between the predicted values and the true values, reflecting the overall scale of the model’s prediction errors; By calculating the average of the absolute values of the errors between the predicted values and the true values, it can more intuitively reflect the average degree of deviation between the predicted values and the true values; It is the square root of MSE, which amplifies the error based on MSE, making the larger error occupy a more important position in the evaluation and highlighting the performance of the model when dealing with larger errors. k represents the kth real data in the test set, represents the k-th prediction result, is the average value of the real data, and R represents the amount of data.
[0106] The hydrogen energy accident risk identification dataset was split into training and validation sets in an 8:2 ratio, and an LSTM model was used for training and prediction. Table 2 shows the performance of the LSTM model in the hydrogen energy system risk level prediction task compared with other models such as XGBoost and Random Forest. The LSTM model demonstrated the best performance across all evaluation metrics, validating its effectiveness in predicting hydrogen energy system risk severity.
[0107] Table 2
[0108] Model MAE MSE RMSE LSTM 0.7748 1.5894 1.2607 XGBoost 0.8676 1.7550 1.3248 RandomForest 0.8610 1.7351 1.3172
[0109] In step S4 of this embodiment, the early warning mechanism employed specifically sets three levels of warning thresholds. When the predicted severity of the consequences of a hydrogen accident reaches or exceeds level 2, a blue warning is triggered; when it reaches or exceeds level 3, an orange warning is triggered; and when it reaches or exceeds level 4, a red warning is triggered. Simultaneously, the system outputs the key risk-causing factors and their corresponding SHAP value explanations, allowing safety managers to clearly understand the source of the risk.
[0110] Taking the accident event in Table 3 as an example, when the input data indicates errors in human factors, system design factors, installation factors, operational factors, and management factors, but no errors in material / manufacturing factors or environmental factors, the LSTM model predicts a consequence level of 4 for this hydrogen energy accident, triggering a red alert. Analysis reveals that the key contributing factors are management factors, human factors, and system design factors, with SHAP values of 0.35, 0.29, and 0.18, respectively. This indicates that management factors had the greatest impact on the accident risk, likely due to poor implementation of safety regulations and a lack of supervision. Human factors were second, perhaps due to operator misconduct and a lack of safety awareness. System design factors also contributed to the risk to a certain extent, potentially involving flaws in the rationality and safety of the system design. Experimental results clearly demonstrate that the LSTM model performs well in predicting the severity of hydrogen energy system accidents, providing safety managers with reliable and targeted risk warnings. This characteristic further highlights the unique value and broad application potential of this invention in the field of hydrogen energy safety engineering.
[0111] Table 3
[0112]
[0113]
[0114] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not limiting. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solutions, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for identifying risk factors and predicting accident severity in hydrogen energy systems by integrating XGBoost-SHAP and LSTM, characterized by: The method comprises: S1. Obtain a hydrogen energy accident report dataset and annotate several hydrogen energy accident causal factors and hydrogen energy accident consequence levels, thereby establishing a hydrogen energy accident risk identification dataset; S2. Use the XGBoost algorithm to build a risk factor importance assessment model, introduce the SHAP interpretability analysis method to quantify its marginal contribution to the severity of the accident, and generate a ranking of the key factor feature importance; S3. Establish an LSTM hydrogen energy accident risk severity prediction model, input the filtered core risk factor time series data, capture the time series dependency of risk factors through hidden layer neurons, and achieve a rolling prediction of the hydrogen energy system risk level; S4. Determine whether the predicted risk level of the hydrogen energy system exceeds the threshold. If so, trigger a graded warning and output a key causal factor explanation report.
2. The method for identifying risk factors and predicting accident severity of hydrogen energy systems by integrating XGBoost-SHAP and LSTM according to claim 1 is characterized in that: In step S1, the manually labeled causal factors of hydrogen energy accidents include human factors, system design factors, material / manufacturing factors, installation factors, work factors, management factors, and environmental factors; the consequence levels of hydrogen energy accidents include false alarms, mild, moderate, severe, and catastrophic accidents; In the established hydrogen energy accident risk identification dataset, a binary representation method is used to label the causal factors of hydrogen energy accidents. If a hydrogen energy accident is directly or indirectly caused by a certain causal factor, the corresponding causal factor is assigned a value of 1, otherwise it is assigned a value of 0. A time series multi-classification label is constructed based on the potential harmfulness and actual damage degree of hydrogen energy accidents, where the false alarm class is coded as 0, the minor accident is coded as 1, the moderate accident is coded as 2, the severe accident is coded as 3, and the catastrophic accident is coded as 4.
3. The method for identifying risk factors and predicting accident severity of hydrogen energy systems by integrating XGBoost-SHAP and LSTM according to claim 2 is characterized by: In step S2, in the established risk factor importance assessment model, a risk factor importance assessment model is built based on the XGBoost library, which uses the XGBoost classifier XGBClassifier to perform classification operations to classify the risk factors of the hydrogen energy system and determine the categories to which different risk factors belong; Initialize the objective function to the multi-classification logarithmic loss function: Where l(·) is the logarithmic loss, y i represents the true label of the i-th sample, represents the predicted label of the i-th sample, n represents the number of samples participating in model training; K represents the number of trees in the model, f k represents the k-th tree model, Ω(·) is the regularization term used to control the complexity of the number, where: In the formula, γ represents the penalty coefficient of the number of leaf nodes, which is used to control the complexity of the model and avoid overfitting; λ represents the weight attenuation coefficient, which is used to control the complexity of the model; T represents the number of leaf nodes in the tree, w j represents the weight of the jth leaf node; Then, the initial search space settings of learning rate, maximum tree depth, subsampling rate, and column sampling ratio are set, and the optimal parameter combination is determined through multi-fold cross validation; Model training is performed based on the optimal hyperparameter combination, using a forward step-by-step algorithm for iterative optimization: Where η is the learning rate, f t (·) is the output of the t-th tree, x i represents the i-th training sample, i.e., a sample data containing the characteristics of various risk factors, based on which the model iteratively updates the predicted value; Indicates the predicted value of the i-th sample at the t-th iteration, It represents the predicted value of the i-th sample at the t-1th iteration.
4. The method for identifying risk factors and predicting accident severity of hydrogen energy systems by integrating XGBoost-SHAP and LSTM according to claim 3 is characterized by: XGBoost-SHAP fusion calculation analysis is used, and the process includes: First, calculate the SHAP value of each risk factor: Among them, φ0 represents the benchmark value of the risk factor importance assessment model, that is, the predicted mean of all samples; φ j (·) is the contribution of a certain feature j to the prediction, and n is the number of risk factors; Then, the average absolute SHAP value of each risk factor is calculated and normalized to obtain the relative importance of each key risk factor: Among them, φ i,j represents the SHAP value of the j-th risk factor in the i-th sample, and m is the number of risk factors. Finally, the core risk factors are screened and the factors with a preset proportion of importance ranking are selected as core risk factors and used as input for the subsequent hydrogen energy risk severity prediction model.
5. The method for identifying risk factors and predicting accident severity of hydrogen energy systems by integrating XGBoost-SHAP and LSTM according to claim 4 is characterized in that: In step S3, the established LSTM hydrogen energy accident risk severity prediction model includes an input layer, a hidden layer, an attention layer and an output layer, wherein the input layer receives pre-processed time series data whose dimensions are consistent with the number of core risk factors after screening; the hidden layer sets up several LSTM units, each LSTM unit includes several neurons; the attention layer calculates the attention weight vector matching the time step based on the output of the hidden layer, highlights the key time step, and makes the model pay more attention to the information important for predicting the severity of the risk; the output layer uses the Softmax function to process the results after the attention layer, and converts the output into the probability distribution of each risk level to achieve multi-classification prediction.
6. The method for identifying risk factors and predicting accident severity of hydrogen energy systems by integrating XGBoost-SHAP and LSTM according to claim 5 is characterized in that: The training process for the LSTM hydrogen energy accident risk severity prediction model is as follows: Data preprocessing: Clean the collected historical accident record data of the hydrogen energy system to remove outliers and missing values; divide the processed data into training sets and test sets according to the preset ratio; Optimizer and learning rate settings: Use the Adam optimizer to initialize the learning rate; use the exponential decay strategy to screen the learning rate according to the preset number of rounds. The specific formula is: Among them, lr init is the initial learning rate, decay is the decay coefficient, eproh is the current training round, and step is the preset decay interval round; Loss function and regularization: Cross entropy loss is used as the loss function, and its formula is: Where N is the number of samples, C is the number of categories, and y ij is the true label of sample i belonging to category j, whose value is 0 or 1, p ij is the probability that the model predicts that sample i belongs to category j; at the same time, an L2 regularization term is added to the loss function. λ is the regularization coefficient, w is the weight parameter of the model to prevent the model from overfitting; Parameter update during training: In each training batch, the training data is input into the LSTM model, and the model output is calculated through forward propagation. The loss value is calculated based on the output and the true label. Then, the gradient of the loss value with respect to the parameters of each layer of the model, including weights and biases, is calculated through the backpropagation algorithm. The Adam optimizer updates the model parameters based on the calculated gradient and the set learning rate. The specific update formula is: m t =β1m t-1 +(1-β1)g t where m t and v t are the estimates of the first and second order moments, g t is the current gradient, β1 and β2 are the hyperparameters of the Adam optimizer, t is the number of iterations, η is the learning rate, and ∈ is a small constant to prevent division by zero; Early stopping mechanism: Set up an early stopping mechanism to calculate the loss value on the validation set after each training round. Record the historical loss value of the validation set. When the loss value on the validation set stops decreasing after several consecutive rounds, stop training and save the model parameters at this time to prevent model overfitting. Model evaluation: After training, the final model is evaluated using the test set, and metrics such as mean square error and mean absolute error are calculated to measure the performance of the model.
7. The method for identifying risk factors and predicting accident severity of hydrogen energy systems by integrating XGBoost-SHAP and LSTM according to claim 6 is characterized by: When predicting the severity of hydrogen energy system risks, the LSTM hydrogen energy accident risk severity prediction model operates as follows: (1) Input data preparation: The pre-processed accident data related to hydrogen energy system risks is used as input. The data comes from existing accident-related information, including accident risk factors and accident severity; (2) Hidden state initialization: Initialize the hidden state, which includes the cell state c0 and the hidden layer state h0. It is usually initialized to an all-zero vector or set a suitable initial value based on experience; (3) Cyclic unit calculation: For each time step t in the input sequence, the LSTM model performs calculations through its core cyclic unit structure; this structure mainly includes the input gate i t , forget gate f t , output gate o t and memory unit c t : ① Input gate: i t =σ(W xi x t +W hi h t-1 +b i ), where σ is the Sigmoid activation function, W xi x t 、W hi h t-1 is the weight matrix, x t is the input of the current time step, h t-1 is the hidden layer state at the previous time step, b i is the bias term; ②Forget gate: f t =σ(W xf x t +W hf h t-1 +b f ), which determines the information to be discarded from the memory cell; ③Memory unit update: Get the candidate memory cell value; then Where ⊙ represents element multiplication, which realizes the update of memory unit; ④Output gate: o t =σ(W xo x t +W ho h t-1 +b o ), determines the content of the memory unit output for calculating the hidden layer state, the hidden layer state h t =o t ⊙tanh(c t ); (4) Multi-layer processing and output: The hidden layer state h after processing by multi-layer LSTM units T , T is the last time step of the input sequence, input to the fully connected layer, the weight matrix of the fully connected layer is W f , bias is b f , then the fully connected layer output, z=W f h T +b f ; Then, the output is converted into the probability distribution of each risk level through the Softmax activation function to obtain the final prediction result: K is the accident risk level.
8. The method for identifying risk factors and predicting accident severity of hydrogen energy systems by integrating XGBoost-SHAP and LSTM according to claim 7 is characterized in that: When the predicted severity level of the consequences of a hydrogen energy accident reaches or exceeds level 2, a blue warning is triggered; when it reaches or exceeds level 3, an orange warning is triggered; when it reaches or exceeds level 4, a red warning is triggered; at the same time, the key causal factors leading to the risk and their corresponding SHAP value explanations are output synchronously.
Citation Information
Cited By
Cascae data management method and device, equipment and storage medium
CN120763488A
Wind power multi-scale decomposition prediction method
CN121189545A
Forest ecological quality grading method based on statistical ecological double-constraint threshold
CN122087580A