Research on a Mixed Gas Detection Method Based on KNN-SVM
SUN Chao1, HU Run-ze1, WU Zhong-xu2, LIU Nian-song2, DING Jian-jun1*
1. College of Intelligent Manufacturing, Jianghan University,Wuhan 430056, China
2. State Key Laboratory of Precision Blasting, Jianghan University,Wuhan 430056, China
摘要: 当今混合气体检测的研究中,针对多组分气体数据进行分类预测的数学算法百花齐放,如何快速且准确的检测出气体的成分和浓度逐渐成为当今研究的热门。然而在一些研究中,气体数据特征难以捕捉和判断,泛化能力不足,对气体数据进行分类预测的精度和效率表现较差。为此,针对一些数据偏差和泛化误差无界的问题,提出了一种K最近邻-支持向量机(KNN-SVM)算法,对一些难以作出分类的模糊气体数据进行二次分类,采用KNN和SVM两种算法共同抉择,更加全面的捕捉数据特征,根据实验确定各自算法的权重比从而提高判别气体类别的准确率,两种算法的集成也能提高算法的效率,对于不同种类的气体也能有良好的适应性的稳定性。该实验气体组分由12 mg·L-1的C2H2、NO2、SF6,10 mg·L-1的NO2、SF6和5 mg·L-1的C2H2(背景气体皆为N2)以及两瓶纯N2的气瓶组成;通过互相混合和与N2配比制备出实验设定的气体浓度。实验过程通过单一气体的检测可分别对三种气体获得60组训练集,并通过这60组数据可进行线性拟合得到每种气体的拟合线,得到气体浓度与气体吸收峰值的关系,通过实验检测得到的三种气体拟合线,其中C2H2拟合线的调整后R2为0.991,NO2拟合线的调整后R2为0.981,SF6拟合线的调整后R2为0.987,可得气体检测的准确性。再通过互相混合进行检测可分别获得40组训练集,采用KNN-SVM算法对混合气体进行分类和预测,后通过拟合线即可反演出混合气体中每种气体的浓度。将该算法与传统SVM算法进行各种分类指标对比均可显示出该算法的有效性和优越性。实验结果表明,KNN-SVM算法在气体分类预测方面表现出卓越的性能,准确率高达99.167%, AUC(area under curve)值达99.375%。这一算法不仅提高了气体检测的准确性,还增强了泛化能力可适应多样化的气体组分,为实时气体检测系统提供了有力支持。
关键词:光声光谱;气体检测;KNN-SVM;分类预测
Abstract:In the current research on mixed gas detection, various mathematical algorithms for classifying and predicting data of multiple gas components have emerged. Rapid and accurate gas composition and concentration detection has gradually become a hot topic. However, in some studies, the features of gas data are difficult to capture and judge, and the classification and prediction of gas data exhibit poor accuracy and efficiency due to data bias and unbounded generalization errors. In response to challenges like data bias and unbounded generalization errors, this paper proposes a KNN-SVM algorithm. This algorithm performs secondary classification on ambiguous gas data that is challenging to classify. It combines K-nearest neighbors and Support Vector Machine algorithms to make more comprehensive data feature assessments. The algorithm determines the weights of each algorithm based on experiments, thereby improving the accuracy of discriminating gas categories. The integration of the two algorithms also enhances the efficiency of the overall algorithm, providing stable adaptability to different types of gases. The experimental gas composition consists of cylinders containing C2H2, NO2,and SF6 at concentrations of 12 mg·L-1, NO2, SF6 at 10 mg·L-1, and C2H2 at 5 mg·L-1(all diluted with N2 as a background gas), as well as two bottles of pure N2. The experiment involves mixing these gases and adjusting their ratios to set the required gas concentrations for detection. By detecting individual gases,60 sets of training data are obtained for each of the three gases. Linear fitting of these 60 data sets yields fitted lines for each gas, establishing the relationship between gas concentration and absorption peak. The accuracy of gas detection is confirmed through the adjusted R-squared values for the fitted lines: 0.991 for C2H2,0.981 for NO2, and 0.987 for SF6. Subsequently, 40 sets of training data are obtained by detecting mixed gases. The KNN-SVM algorithm is then applied to classify and predict mixed gases, and the concentrations of each gas in the mixed gas are inferred from the fitted lines. Comparisons with traditional SVM algorithms using various classification metrics demonstrate the effectiveness and superiority of the proposed algorithm. Experimental results indicate that the KNN-SVM algorithm exhibits outstanding performance in gas classification and prediction,achieving an accuracy of 99.167% and an Area Under the Curve index of 99.375%. This algorithm enhances the accuracy of gas detection and improves generalization capabilities to adapt to diverse gas compositions,providing robust support for real-time gas detection systems.
Key words:Photoacoustic spectroscopy; Gas detection; KNN-SVM; Classification prediction
孙 超,胡润泽,吴中旭,刘年松,丁建军. 基于KNN-SVM的混合气体检测方法研究[J]. 光谱学与光谱分析, 2025, 45(01): 117-124.
SUN Chao, HU Run-ze, WU Zhong-xu, LIU Nian-song, DING Jian-jun. Research on a Mixed Gas Detection Method Based on KNN-SVM. SPECTROSCOPY AND SPECTRAL ANALYSIS, 2025, 45(01): 117-124.
[1] Bayrakli I. Applied Optics, 2018, 57(15): 4039.
[2] Suchánek J, Janda P, Dostál M, et al. Microchemical Journal, 2019, 144: 203.
[3] SHAO Xiao-peng, ZHANG Le, LIU Li-xian, et al(邵晓鹏, 张 乐, 刘丽娴,等). Journal of Data Acquisition & Processing(数据采集与处理), 2021, 36(5): 850.
[4] Liu Y H, Qiao S D, Fang C, et al. Opto-Electronic Advances,2024,7:230230.
[5] Fang C, Liang T T, Qiao S D, et al. Optics Letters, 2024,49:770.
[6] Elefante A, Giglio M, Sampaolo A, et al. Analytical Chemistry, 2019, 91(20): 12866.
[7] Weigl S, Wittmann E, Rück T, et al. Sensors and Actuators B: Chemical, 2021, 328: 129001.
[8] Ma Y F, Liang T T, Qiao S D, et al. Ultrafast Science, 2023,3: 0024.
[9] DU Hong-fei, XIE Guang-zhong(杜鸿飞, 谢光忠). Electronic Components & Materials(电子元件与材料), 2019, 38(12): 69.
[10] QIAN Xin-ming, HUANG Jie, YUAN Meng-qi(钱新明, 黄 捷, 袁梦琦). Journal of Safety and Environment(安全与环境学报), 2020, 20(4): 1241.
[11] LI Peng, CHANG Si-jie, YANG Jia-kang(李 鹏, 常思婕, 杨佳康). Modern Electronics Technique(现代电子技术), 2022, 45(13): 104.
[12] DUAN Xiao-li, WANG Ming-quan(段小丽, 王明泉). Spectroscopy and Spectral Analysis(光谱学与光谱分析), 2019, 39(9): 2883.
[13] YANG Chao, ZHANG Ping-ping, WANG Guo-qiang, et al(杨 朝, 张平平, 汪国强,等). Journal of Natural Science of Heilongjiang University(黑龙江大学自然科学学报), 2022, 39(3): 345.
[14] Xia W, Song T, Yan Z, et al. A Method for Recognition of Mixed Gas Composition Based on PCA and KNN. 2021 19th International Conference on Optical Communications and Networks (ICOCN), Qufu, China, 2021, doi: 10.1109/ICOCN53177.2021.9563663.
[15] QIAO Feng-juan, GUO Hong-li, LI Wei, et al(乔风娟, 郭红利, 李 伟,等). Journal of Qilu University of Technology(齐鲁工业大学学报), 2018, 32(5): 39.
[16] LIU Yu-kang, ZHANG Zheng-yang, CHEN Lin-lin, et al(刘雨康, 张正阳, 陈琳琳,等). Computer Engineering and Applications(计算机工程与应用), 2015, 51(24): 126.
[17] LIU Shao-yu, ZHOU Jie, LI Bi-cheng, et al(刘绍毓, 周 杰, 李弼程,等). Journal of Data Acquisition & Processing(数据采集与处理), 2015, 30(1): 202.