Folder: CHDC File: IDS.py 1. Chinese:’BEPCD模型的可解释性分析’ English:Interpretability analysis of the BEPCD model 2. Chinese:’使用SHAP进行特征重要性分析和模型决策解释’ English:Feature importance analysis and model decision explanation using SHAP 3. Chinese:’创建保存结果的目录’ English:Create directories to save results 4. Chinese:’已创建输出目录’ English:Output directories created 5. Chinese:’载入数据’ English:Load data 6. Chinese:’载入数据集并进行预处理’ English:Load dataset and preprocess 7. Chinese:’正在载入数据...’ English:Loading data... 8. Chinese:’载入或训练模型’ English:Load or train models 9. Chinese:’载入已保存的模型或训练新模型’ English:Load saved models or train new models 10. Chinese:’正在载入已训练的模型...’ English:Loading trained models... 11. Chinese:’正在训练模型...’ English:Training models... 12. Chinese:’SHAP特征重要性分析’ English:SHAP feature importance analysis 13. Chinese:’使用SHAP分析模型的特征重要性’ English:Analyze model feature importance using SHAP 14. Chinese:’正在分析{model_name}模型的特征重要性...’ English:Analyzing feature importance of {model_name} model... 15. Chinese:’模型的整体特征重要性’ English:Overall feature importance of the model 16. Chinese:’模型的特征影响详图’ English:Detailed feature impact plot of the model 17. Chinese:’模型对{class_name}类别的特征重要性’ English:Feature importance of the model for {class_name} class 18. Chinese:’与SHAP值的依赖关系’ English:Dependence with SHAP value 19. Chinese:’比较不同模型的特征重要性’ English:Compare feature importance of different models 20. Chinese:’比较Blending和Stacking模型的特征重要性...’ English:Comparing feature importance of Blending and Stacking models... 21. Chinese:’特征’ English:Feature 22. Chinese:’Blending重要性’ English:Blending importance 23. Chinese:’Stacking重要性’ English:Stacking importance 24. Chinese:’差异’ English:Difference 25. Chinese:’Blending模型的前10个重要特征’ English:Top 10 important features of the Blending model 26. Chinese:’Stacking模型的前10个重要特征’ English:Top 10 important features of the Stacking model 27. Chinese:’SHAP值重要性’ English:SHAP value importance 28. Chinese:’对{class_name}类别的特征重要性比较’ English:Feature importance comparison for {class_name} class 29. Chinese:’样本数量’ English:Number of samples 30. Chinese:’分析BEPCD模型的决策过程’ English:Analyze the decision process of the BEPCD model 31. Chinese:’分析BEPCD决策过程...’ English:Analyzing BEPCD decision process... 32. Chinese:’模型一致’ English:Models agree 33. Chinese:’Blending模型更有信心 ({b_prob:.2f} > {s_prob:.2f})’ English:Blending model is more confident ({b_prob:.2f} > {s_prob:.2f}) 34. Chinese:’Stacking模型更有信心 ({s_prob:.2f} > {b_prob:.2f})’ English:Stacking model is more confident ({s_prob:.2f} > {b_prob:.2f}) 35. Chinese:’实际标签’ English:Actual label 36. Chinese:’Blending预测’ English:Blending prediction 37. Chinese:’Stacking预测’ English:Stacking prediction 38. Chinese:’BEPCD预测’ English:BEPCD prediction 39. Chinese:’决策原因’ English:Reason for decision 40. Chinese:’BEPCD决策原因分布’ English:Distribution of BEPCD decision reasons 41. Chinese:’预测正确’ English:Prediction correct 42. Chinese:’不同决策原因的准确率’ English:Accuracy for different decision reasons 43. Chinese:’准确率’ English:Accuracy 44. Chinese:’类别的决策原因分布’ English:Distribution of decision reasons for the class 45. Chinese:’样本数’ English:Number of samples 46. Chinese:’正确预测’ English:Correct predictions 47. Chinese:’决策原因分布’ English:Distribution of decision reasons 48. Chinese:’类别的决策原因分布’ English:Distribution of decision reasons for {name} class 49. Chinese:’生成特征重要性和决策分析的综合报告’ English:Generate a comprehensive report of feature importance and decision analysis 50. Chinese:’生成分析报告...’ English:Generating analysis report... 51. Chinese:’BEPCD模型可解释性分析报告’ English:BEPCD Model Interpretability Analysis Report 52. Chinese:’特征重要性分析’ English:Feature Importance Analysis 53. Chinese:’整体特征重要性’ English:Overall Feature Importance 54. Chinese:’下表显示了Blending和Stacking模型的前10个最重要特征:’ English:The table below shows the top 10 most important features of the Blending and Stacking models: 55. Chinese:’模型特征重要性差异’ English:Differences in model feature importance 56. Chinese:’以下特征在Blending和Stacking模型之间表现出最大差异:’ English:The following features show the greatest differences between the Blending and Stacking models: 57. Chinese:’各攻击类型特征依赖’ English:Feature dependencies for each attack type 58. Chinese:’正常流量主要由CAN ID和数据字段的一致性模式特征区分。’ English:Normal traffic is mainly distinguished by the consistency pattern features of CAN ID and data fields. 59. Chinese:’DOS攻击主要依赖于CAN ID和数据字段值的异常检测,特别是短时间内大量相同CAN ID的出现。’ English:DOS attacks mainly rely on anomaly detection of CAN ID and data field values, especially the appearance of a large number of identical CAN IDs in a short period. 60. Chinese:’Fuzzing攻击对DataOne-DataFour的依赖性最高,这些字段的随机性是检测的关键。’ English:Fuzzing attacks rely most on DataOne-DataFour, and the randomness of these fields is key to detection. 61. Chinese:’重放攻击严重依赖时间特征和连续消息之间的关系,Before和Back特征对检测尤为重要。’ English:Replay attacks heavily rely on time features and the relationship between consecutive messages; Before and Back features are especially important for detection. 62. Chinese:’欺骗攻击主要通过CAN ID的组合和异常数据值检测,表现为合法但内容异常的消息。’ English:Spoofing attacks are mainly detected by combinations of CAN IDs and abnormal data values, appearing as legitimate but content-abnormal messages. 63. Chinese:’BEPCD决策过程分析’ English:BEPCD Decision Process Analysis 64. Chinese:’决策原因分布’ English:Distribution of decision reasons 65. Chinese:’BEPCD模型在做决策时的依据分布:’ English:The basis distribution when the BEPCD model makes decisions: 66. Chinese:’各类别的性能和决策特点’ English:Performance and decision characteristics of each class 67. Chinese:’主要决策依据:’ English:Main decision basis: 68. Chinese:’结论和建议’ English:Conclusions and Recommendations 69. Chinese:’主要发现’ English:Main Findings 70. Chinese:’改进建议’ English:Improvement Suggestions 71. Chinese:’CAN ID和DLC是区分正常和异常流量的最关键特征’ English:CAN ID and DLC are the most critical features for distinguishing normal and abnormal traffic 72. Chinese:’DataOne和DataTwo对检测特定类型的攻击(特别是Fuzzing和Spoofing)至关重要’ English:DataOne and DataTwo are crucial for detecting specific types of attacks (especially Fuzzing and Spoofing) 73. Chinese:’时间相关特征(Before和Back)在检测重放攻击方面表现出较高的重要性,但当前模型对这类攻击检测率仍有待提高’ English:Time-related features (Before and Back) show high importance in detecting replay attacks, but the current model's detection rate for such attacks still needs improvement 74. Chinese:’Blending模型更多依赖于CAN ID和单个数据字段,而Stacking模型对时间相关特征和连续消息之间的关系更敏感’ English:The Blending model relies more on CAN ID and individual data fields, while the Stacking model is more sensitive to time-related features and relationships between consecutive messages 75. Chinese:’这些差异解释了为什么BEPCD通过结合这些模型可以提高性能’ English:These differences explain why BEPCD can improve performance by combining these models 76. Chinese:’对重放攻击的检测可以通过增强时间特征工程得到改善,考虑添加更多时间序列特征’ English:Detection of replay attacks can be improved by enhancing time feature engineering and considering adding more time series features 77. Chinese:’考虑增加特征,如消息频率分析和顺序模式分析,以提高对各类攻击的检测能力’ English:Consider adding features such as message frequency analysis and sequential pattern analysis to improve detection capability for various attacks 78. Chinese:’针对低重放攻击检测率,可以考虑在BEPCD中加入专门针对时间序列异常的模型’ English:For low replay attack detection rates, consider adding models specifically for time series anomalies in BEPCD 79. Chinese:’优化模型选择机制,根据输入特征的特点智能选择最适合的模型进行预测’ English:Optimize the model selection mechanism to intelligently choose the most suitable model for prediction based on the characteristics of input features 80. Chinese:’增加对边缘案例的分析,特别是那些Blending和Stacking模型预测不一致的情况’ English:Increase the analysis of edge cases, especially those where Blending and Stacking model predictions are inconsistent 81. Chinese:’分析完成!所有结果已保存到./shap_results和./figures目录’ English:Analysis complete! All results have been saved to ./shap_results and ./figures directories Folder: CHDC File: BEPCD_analysis.py 1. Chinese:’BEPCD模型性能分析脚本’ English:BEPCD model performance analysis script 2. Chinese:’用于评估BEPCD模型的MAC值(模型平均复杂度)、单条数据识别时间和参数量’ English:Used to evaluate the MAC value (Model Average Complexity), single data recognition time, and parameter count of the BEPCD model 3. Chinese:’定义流式处理对象,用于逐一读取数据(模拟实时流分析)’ English:Define a streaming processing object for reading data one by one (simulate real-time stream analysis) 4. Chinese:’迭代处理pandas DataFrame/Series数据’ English:Iterate over pandas DataFrame/Series data 5. Chinese:’参数:’ English:Parameters: 6. Chinese:’特征数据’ English:Feature data 7. Chinese:’标签数据 (可选)’ English:Label data (optional) 8. Chinese:’返回:’ English:Returns: 9. Chinese:’逐行迭代X和y的生成器’ English:Generator for iterating X and y row by row 10. Chinese:’模拟BEPCD函数,用于性能分析’ English:Simulated BEPCD function for performance analysis 11. Chinese:’BEPCD模型预测函数’ English:BEPCD model prediction function 12. Chinese:’测试特征数据’ English:Test feature data 13. Chinese:’测试标签数据’ English:Test label data 14. Chinese:’Blending模型’ English:Blending model 15. Chinese:’Stacking模型’ English:Stacking model 16. Chinese:’每个类别的最佳模型列表’ English:Best model list for each class 17. Chinese:’真实标签列表’ English:True label list 18. Chinese:’预测标签列表’ English:Predicted label list 19. Chinese:’如果没有提供model参数,则构建一个默认的’ English:If the model parameter is not provided, build a default one 20. Chinese:’假定所有类别都是用blending_clf’ English:Assume all classes use blending_clf 21. Chinese:’对每个测试样本进行预测’ English:Predict for each test sample 22. Chinese:’BEPCD决策逻辑’ English:BEPCD decision logic 23. Chinese:’检查每个预测模型预测的类别是否由对应的模型作为最佳模型’ English:Check whether the predicted class of each model is the best model for that class 24. Chinese:’使用具有更高置信度的模型的预测’ English:Use the prediction of the model with higher confidence 25. Chinese:’加载保存的模型’ English:Load saved models 26. Chinese:’模型保存的目录路径’ English:Directory path where models are saved 27. Chinese:’尝试从文件加载模型’ English:Try to load models from file 28. Chinese:’成功加载模型文件’ English:Model files loaded successfully 29. Chinese:’如果模型文件不存在,则返回None’ English:If model files do not exist, return None 30. Chinese:’模型文件不存在或无法加载’ English:Model files do not exist or cannot be loaded 31. Chinese:’加载测试数据集’ English:Load test dataset 32. Chinese:’数据集路径’ English:Dataset path 33. Chinese:’测试特征数据’ English:Test feature data 34. Chinese:’测试标签数据’ English:Test label data 35. Chinese:’尝试从CSV文件加载数据’ English:Try to load data from CSV file 36. Chinese:’分离特征和标签’ English:Separate features and labels 37. Chinese:’除最后一列外的所有列作为特征’ English:All columns except the last as features 38. Chinese:’最后一列作为标签’ English:The last column as label 39. Chinese:’模拟测试集分割’ English:Simulate test set split 40. Chinese:’成功加载数据: {len(X_test)}行, {X_test.shape[1]}列’ English:Data loaded successfully: {len(X_test)} rows, {X_test.shape[1]} columns 41. Chinese:’加载数据失败: {str(e)}’ English:Failed to load data: {str(e)} 42. Chinese:’计算模型参数量’ English:Calculate model parameter count 43. Chinese:’机器学习模型对象’ English:Machine learning model object 44. Chinese:’参数总数’ English:Total parameter count 45. Chinese:’对于投票分类器,计算每个基模型的参数’ English:For voting classifiers, calculate parameters for each base model 46. Chinese:’随机森林’ English:Random forest 47. Chinese:’每个节点需要特征索引、阈值和子节点指针’ English:Each node requires feature index, threshold, and child node pointers 48. Chinese:’这是一个估计值’ English:This is an estimated value 49. Chinese:’默认返回特征数乘以一个系数’ English:By default, return feature count times a coefficient 50. Chinese:’计算模型的MAC值(模型平均复杂度)’ English:Calculate the MAC value (Model Average Complexity) of the model 51. Chinese:’输入特征数据’ English:Input feature data 52. Chinese:’MAC值’ English:MAC value 53. Chinese:’对于VotingClassifier’ English:For VotingClassifier 54. Chinese:’为每个基模型计算操作’ English:Calculate operations for each base model 55. Chinese:’每棵树需要评估所有特征’ English:Each tree needs to evaluate all features 56. Chinese:’其他模型的默认估计’ English:Default estimate for other models 57. Chinese:’分析BEPCD模型性能’ English:Analyze BEPCD model performance 58. Chinese:’性能分析结果字典’ English:Performance analysis result dictionary 59. Chinese:’用于分析的样本数量’ English:Number of samples for analysis 60. Chinese:’性能分析结果字典’ English:Performance analysis result dictionary 61. Chinese:’对X_test进行采样’ English:Sample X_test 62. Chinese:’1. 计算模型MAC值...’ English:1. Calculating model MAC value... 63. Chinese:’额外的决策复杂度’ English:Additional decision complexity 64. Chinese:’2. 计算模型参数量...’ English:2. Calculating model parameter count... 65. Chinese:’3. 计算单条数据处理时间...’ English:3. Calculating single data processing time... 66. Chinese:’测量BEPCD单条数据处理时间’ English:Measure BEPCD single data processing time 67. Chinese:’BEPCD预测过程’ English:BEPCD prediction process 68. Chinese:’简化版决策逻辑’ English:Simplified decision logic 69. Chinese:’转换为毫秒’ English:Convert to milliseconds 70. Chinese:’计算处理时间统计’ English:Calculate processing time statistics 71. Chinese:’4. 计算模型准确性...’ English:4. Calculating model accuracy... 72. Chinese:’性能分析结果字典’ English:Performance analysis result dictionary 73. Chinese:’可视化分析结果’ English:Visualize analysis results 74. Chinese:’参数: ‘ English:Parameters: 75. Chinese:’性能分析结果字典’ English:Performance analysis result dictionary 76. Chinese:’MAC值比较’ English:MAC value comparison 77. Chinese:’参数量比较’ English:Parameter count comparison 78. Chinese:’处理时间分布’ English:Processing time distribution 79. Chinese:’准确性指标’ English:Accuracy metrics 80. Chinese:’打印结果摘要’ English:Print result summary 81. Chinese:’打印结果摘要’ English:Print result summary 82. Chinese:’参数: ‘ English:Parameters: 83. Chinese:’性能分析结果字典’ English:Performance analysis result dictionary 84. Chinese:’BEPCD模型性能分析摘要’ English:BEPCD Model Performance Analysis Summary 85. Chinese:’1. MAC值分析 (模型平均复杂度)’ English:1. MAC Value Analysis (Model Average Complexity) 86. Chinese:’Blending模型 MAC值: {results['mac_value']['blending']:,} 操作’ English:Blending model MAC value: {results['mac_value']['blending']:,} operations 87. Chinese:’Stacking模型 MAC值: {results['mac_value']['stacking']:,} 操作’ English:Stacking model MAC value: {results['mac_value']['stacking']:,} operations 88. Chinese:’BEPCD模型 总MAC值: {results['mac_value']['bepcd']:,} 操作’ English:BEPCD model total MAC value: {results['mac_value']['bepcd']:,} operations 89. Chinese:’2. 模型参数量分析’ English:2. Model Parameter Count Analysis 90. Chinese:’Blending模型参数量: {results['parameters_count']['blending']:,} 参数’ English:Blending model parameter count: {results['parameters_count']['blending']:,} parameters 91. Chinese:’Stacking模型参数量: {results['parameters_count']['stacking']:,} 参数’ English:Stacking model parameter count: {results['parameters_count']['stacking']:,} parameters 92. Chinese:’BEPCD模型总参数量: {results['parameters_count']['bepcd']:,} 参数’ English:BEPCD model total parameter count: {results['parameters_count']['bepcd']:,} parameters 93. Chinese:’3. 单条数据处理时间分析’ English:3. Single Data Processing Time Analysis 94. Chinese:’平均处理时间: {results['processing_time']['average_ms']:.3f} 毫秒/样本’ English:Average processing time: {results['processing_time']['average_ms']:.3f} ms/sample 95. Chinese:’处理时间标准差: {results['processing_time']['std_ms']:.3f} 毫秒’ English:Processing time standard deviation: {results['processing_time']['std_ms']:.3f} ms 96. Chinese:’最小处理时间: {results['processing_time']['min_ms']:.3f} 毫秒’ English:Minimum processing time: {results['processing_time']['min_ms']:.3f} ms 97. Chinese:’最大处理时间: {results['processing_time']['max_ms']:.3f} 毫秒’ English:Maximum processing time: {results['processing_time']['max_ms']:.3f} ms 98. Chinese:’95%分位处理时间: {results['processing_time']['p95_ms']:.3f} 毫秒’ English:95th percentile processing time: {results['processing_time']['p95_ms']:.3f} ms 99. Chinese:’4. 模型准确性指标’ English:4. Model Accuracy Metrics 100. Chinese:’准确率: {results['accuracy']['accuracy']:.4f}’ English:Accuracy: {results['accuracy']['accuracy']:.4f} 101. Chinese:’精确率: {results['accuracy']['precision']:.4f}’ English:Precision: {results['accuracy']['precision']:.4f} 102. Chinese:’召回率: {results['accuracy']['recall']:.4f}’ English:Recall: {results['accuracy']['recall']:.4f} 103. Chinese:’F1分数: {results['accuracy']['f1']:.4f}’ English:F1 score: {results['accuracy']['f1']:.4f} 104. Chinese:’5. 性能总结’ English:5. Performance Summary 105. Chinese:’BEPCD理论处理速度: {samples_per_second:.2f} 样本/秒’ English:BEPCD theoretical processing speed: {samples_per_second:.2f} samples/second 106. Chinese:’处理1000条数据估计需要: {1000/samples_per_second:.2f} 秒’ English:Estimated time to process 1000 samples: {1000/samples_per_second:.2f} seconds 107. Chinese:’计算效率: {mac_per_time/1e9:.4f} GOPS (10亿操作/秒)’ English:Computation efficiency: {mac_per_time/1e9:.4f} GOPS (billion operations/second) 108. Chinese:’主函数’ English:Main function 109. Chinese:’BEPCD模型性能分析’ English:BEPCD Model Performance Analysis 110. Chinese:’1. 加载模型...’ English:1. Loading models... 111. Chinese:’如果模型加载失败,尝试创建模型’ English:If model loading fails, try to create models 112. Chinese:’模型加载失败,尝试创建模型...’ English:Model loading failed, trying to create models... 113. Chinese:’此处需要添加模型创建代码’ English:Model creation code needs to be added here 114. Chinese:’此脚本需要预先训练好的模型。请先运行IDS.ipynb训练模型并保存。’ English:This script requires pre-trained models. Please run IDS.ipynb to train and save the models first. 115. Chinese:’2. 加载测试数据...’ English:2. Loading test data... 116. Chinese:’数据加载失败,退出程序。’ English:Data loading failed, exiting program. 117. Chinese:’3. 分析BEPCD模型性能...’ English:3. Analyzing BEPCD model performance... 118. Chinese:’4. 打印结果摘要’ English:4. Printing result summary 119. Chinese:’5. 生成可视化结果...’ English:5. Generating visualization results... 120. Chinese:’6. 保存分析结果...’ English:6. Saving analysis results... 121. Chinese:’将numpy数组转换为列表以便JSON序列化’ English:Convert numpy arrays to lists for JSON serialization 122. Chinese:’分析完成!结果已保存到 'bepcd_performance_results.json' 和 'bepcd_performance_analysis.png'‘ English:Analysis complete! Results have been saved to 'bepcd_performance_results.json' and 'bepcd_performance_analysis.png' Folder: CHDC File: IDS. .ipynb Chinese:类别 English: CLASS Folder: Other model Test File: Ex.ipynb 1. Chinese:’# 使用训练好的模型对测试数据集X_test进行预测,得到预测结果y_pred。’ English:Use the trained model to predict the test dataset X_test and get the prediction result y_pred. 2. Chinese:’# 打印分类报告,其中包括每个类别的精确率、召回率、F1分数和支持度。’ English:Print the classification report, including precision, recall, F1 score, and support for each class. 3. Chinese:’# 对测试集进行预测并输出模型性能指标’ English:Predict on the test set and output model performance metrics. 4. Chinese:’# 计算并保存F1分数’ English:Calculate and save the F1 score. 5. Chinese:’# 计算真实标签y_test和预测标签y_pred之间的混淆矩阵。’ English:Calculate the confusion matrix between the true labels y_test and predicted labels y_pred. 6. Chinese:’# 绘制混淆矩阵’ English:Plot the confusion matrix.