Optimizing K-Nearest Neighbors with Particle Swarm Optimization for Improved Classification Accuracy

Authors

  • Ach. Dafid Universitas Trunojoyo Madura
  • Achmad Imam Sudianto Universitas Trunojoyo Madura
  • Rajermani Thinakaran INTI International University
  • Faikul Umam Universitas Trunojoyo Madura
  • Firmansyah Adiputra Universitas Trunojoyo Madura
  • Izzuddin Izzuddin King’s College London
  • Ribka Sitepu Debora Universitas Trunojoyo Madura

DOI:

https://doi.org/10.26555/jiteki.v11i2.30775

Keywords:

K-Nearest Neighbors, Particle Swarm Optimization, Sentiment Analysis, Madurese Batik, Web-based System

Abstract

This study aims to improve the performance of the K-Nearest Neighbors (KNN) algorithm in classifying public reviews of Batik Madura through optimizing the K value using the Particle Swarm Optimization (PSO) algorithm. Public reviews collected from the Google Maps platform are used as a dataset, with positive, negative, and neutral sentiment categories. Optimization of the K value is carried out to overcome the constraints of KNN performance, which is highly dependent on the K parameter, with PSO providing a more efficient approach than the grid search method. However, PSO also presents challenges such as sensitivity to parameter tuning and potential computational overhead. This study has succeeded in developing a web-based system using the Python Streamlit framework, which makes it easy for users to access sentiment analysis results. Testing shows that optimizing the K value with PSO increases the accuracy of KNN to 88.5% with an optimal K value of 19. However, this accuracy is not compared to other optimization techniques, leaving its relative advantage unverified. The results are expected to help Batik Madura entrepreneurs in evaluating public perception and guiding strategic innovations. Research outputs include a prototype, intellectual property registration, and journal publication, although the role of deep learning models is only briefly noted without further development.

Author Biographies

Achmad Imam Sudianto, Universitas Trunojoyo Madura

Department of Mechatronics Engineering, Jl. Raya Telang PO BOX 2 Kamal, Bangkalan 69162, Indonesia

Ribka Sitepu Debora , Universitas Trunojoyo Madura

Department of Information System, Jl. Raya Telang PO BOX 2 Kamal, Bangkalan 69162, Indonesia

References

[1] F. Ciptandi, “The Ability to Adapt jBatik Software Technology for Traditional Batik Craftsmen,” in 2020 6th International Conference on Interactive Digital Media (ICIDM), pp. 1–4, 2020, https://doi.org/10.1109/ICIDM51048.2020.9339671.

[2] R. G. Tiwari, A. K. Agarwal, V. Jain, and A. Kumar, “Batik Classification in Indonesia: Exploring its Significance on Tourism and Economy,” in International Conference on Sustaining Heritage: Innovative and Digital Approaches (ICSH), pp. 119–124, 2023, https://doi.org/10.1109/ICSH57060.2023.10482828.

[3] Y. Kustiyahningsih, D. R. Anamisa, J. Purnama, and E. Rahmanita, “An Integrated Approach for Mapping Batik SMEs during Covid-19,” in Fifth International Conference on Vocational Education and Electrical Engineering (ICVEE), pp. 47–52, 2022, https://doi.org/10.1109/ICVEE57061.2022.9930453.

[4] Y. Kustiyahningsih, J. Purnama, E. Rahmanita, and D. R. Anamisa, “Selection SMEs of Batik Bangkalan Using Fuzzy Interval Type-2 Method based on Group Support System,” in 3rd International Conference on Research and Academic Community Services (ICRACOS), pp. 191–196, 2021, https://doi.org/10.1109/ICRACOS53680.2021.9702091.

[5] V. Naveen, T. J. Nandhini, T. R. Kumar, A. Aggarwal, M. Brayyich, and F. Al-Taee, “An Innovative Method of Developing BI-LSTM and KNN Algorithms for Disintegrating Sentiments Through Reviews,” in 4th International Conference on Advance Computing and Innovative Technologies in Engineering (ICACITE), pp. 173–177, 2024, https://doi.org/10.1109/ICACITE60783.2024.10616887.

[6] M. D. H. Jasy, S. Al Hasan, M. I. K. Sagor, A. Noman, and J. M. Ji, “A Performance Evaluation of Sentiment Classification Applying SVM, KNN, and Naive Bayes,” in International Conference on Computing, Networking, Telecommunications & Engineering Sciences Applications (CoNTESA), pp. 56–60, 2021, https://doi.org/10.1109/CoNTESA52813.2021.9657115.

[7] B. Mridula, A. H. Juliet, and N. Legapriyadharshini, “Deciphering Social Media Sentiment for Enhanced Analytical Accuracy: Leveraging Random Forest, KNN, and Naive Bayes,” in 10th International Conference on Communication and Signal Processing (ICCSP), pp. 1410–1415, 2024, https://doi.org/10.1109/ICCSP60870.2024.10543836.

[8] M]T. Akter, M. Begum, and R. Mustafa, “Bengali Sentiment Analysis of E-commerce Product Reviews using K-Nearest Neighbors,” in International Conference on Information and Communication Technology for Sustainable Development (ICICT4SD), pp. 40–44, 2021, https://doi.org/10.1109/ICICT4SD50815.2021.9396910.

[9] V. C. Pangestu, M. D. Purbolaksono, “Sentiment Analysis on Hotel Review in Bandung from Website Agoda Using KNN Algorithm,” in 1st International Conference on Software Engineering and Information Technology (ICoSEIT), pp. 267–272, 2022, https://doi.org/10.1109/ICoSEIT55604.2022.10030030.

[10] A. Sholihat, F. Bei, R. Ainaya, F. Sembiring, and A. Lattu, “Twitter Tweet: Sentiment Analysis on Illegal Investment using Naive Bayes Algorithm,” in IEEE 8th International Conference on Computing, Engineering and Design (ICCED), pp. 1–5, 2022, https://doi.org/10.1109/ICCED56140.2022.10010383.

[11] A. R. Lubis, S. Prayudani, M. Lubis, and O. Nugroho, “Sentiment Analysis on Online Learning During the Covid-19 Pandemic Based on Opinions on Twitter using KNN Method,” in 1st International Conference on Information System & Information Technology (ICISIT), pp. 106–111, 2022, https://doi.org/10.1109/ICISIT54091.2022.9872926.

[12] M. D. R. Irianto, M. D. Purbolaksono, and Bunyamin, “Sentiment Analysis of Livin’ by Mandiri Application Reviews Using Word2Vec Feature Extraction and KNN Method,” in International Conference on Data Science and Its Applications (ICoDSA), pp. 236–241, 2024, https://doi.org/10.1109/ICoDSA62899.2024.10651870.

[13] F. H. Rachman, Imamah, and B. S. Rintyarna, “Sentiment Analysis of Madura Tourism in New Normal Era using Text Blob and KNN with Hyperparameter Tuning,” in International Seminar on Machine Learning, Optimization, and Data Science (ISMODE), pp. 23–27, 2022, https://doi.org/10.1109/ISMODE53584.2022.9742894.

[14] S. Kaur, G. Sikka, and L. K. Awasthi, “Sentiment Analysis Approach Based on N-gram and KNN Classifier,” in 2018 First International Conference on Secure Cyber Computing and Communication (ICSCCC), pp. 1–4, 2018, https://doi.org/10.1109/ICSCCC.2018.8703350.

[15] M. Chanda and M. Biswas, “Plant disease identification and classification using Back-Propagation Neural Network with Particle Swarm Optimization,” in 3rd International Conference on Trends in Electronics and Informatics (ICOEI), pp. 1029–1036, 2019, https://doi.org/10.1109/ICOEI.2019.8862552.

[16] B. J. Sowmya, A. Kanavalli, D. Deeptashree, “Feature Selection for Classification on High- Dimensional Data Using Swarm Optimization Algorithms,” in 7th International Conference on Computation System and Information Technology for Sustainable Solutions (CSITSS), pp. 1–6, 2023, https://doi.org/10.1109/CSITSS60515.2023.10334228.

[17] E. Ileberi and Y. Sun, “Machine Learning-Assisted Cervical Cancer Prediction Using Particle Swarm Optimization for Improved Feature Selection and Prediction,” IEEE Access, vol. 12, pp. 152684–152695, 2024, https://doi.org/10.1109/ACCESS.2024.3469869.

[18] A. Nader, H. Abdelhamid, and M. Ridha, “A Quantum‐Behaved Particle‐Swarm‐Optimization‐Based KNN Classifier for Improving WSN Lifetime,” in Sensor Data Analysis and Management: The Role of Deep Learning, pp. 117–129, 2021, https://doi.org/10.1002/9781119682806.ch7.

[19] V. P. Maurya, P. Kumar, and S. Halder, “Optimisation and Classification of EMG signal using PSO-ANN,” in Devices for Integrated Circuit (DevIC), pp. 191–195, 2019, https://doi.org/10.1109/DEVIC.2019.8783882.

[20] D. Kartini, M. I. Mazdadi, I. Budiman, F. Indriani, and R. Hidayat, “Binary PSO-GWO for Feature Selection in Binary Classification Using K-Nearest Neighbor,” in Eighth International Conference on Informatics and Computing (ICIC), pp. 1–6, 2023, https://doi.org/10.1109/ICIC60109.2023.10382061.

[21] W. Sinhashthita and K. Jearanaitanakij, “Improving KNN Algorithm Based on Weighted Attributes by Pearson Correlation Coefficient and PSO Fine Tuning,” in 5th International Conference on Information Technology (InCIT), pp. 27–32, 2020, https://doi.org/10.1109/InCIT50588.2020.9310938.

[22] D. Abidin et al., “Instability Live Signal of Access Points in Indoor Positioning Using Particle Swarm Optimization and K-Nearest Neighbor (PSO-KNN),” in International Conference on Informatics, Multimedia, Cyber and Information System (ICIMCIS), pp. 7–10, 2019, https://doi.org/10.1109/ICIMCIS48181.2019.8985193.

[23] Y. Xue, T. Tang, and A. X. Liu, “Large-Scale Feedforward Neural Network Optimization by a Self-Adaptive Strategy and Parameter Based Particle Swarm Optimization,” IEEE Access, vol. 7, pp. 52473–52483, 2019, https://doi.org/10.1109/ACCESS.2019.2911530.

[24] A. Anchalia, A. Kakati, A. Patil, B. N. Bhavana, A. Paudel, and S. Chaudhari, “Integration of Swarm Intelligence with KNN for Optimal Nearest Neighbors Value Prediction,” in 2023 IEEE International Conference on Electronics, Computing and Communication Technologies (CONECCT), pp. 1–6, 2023, https://doi.org/10.1109/CONECCT57959.2023.10234790.

[25] T. A. Khan, K. Zain-Ul-Abideen, and S. H. Ling, “A Modified Particle Swarm Optimization Algorithm Used for Feature Selection of UCI Biomedical Data Sets,” in 60th International Scientific Conference on Information Technology and Management Science of Riga Technical University (ITMS), pp. 1–4, 2019, https://doi.org/10.1109/ITMS47855.2019.8940760.

[26] J. Liu, Y. Tang, and S. Li, “Improved Competitive Swarm Optimization Algorithms for Feature Selection,” in 2International Conference on High Performance Big Data and Intelligent Systems (HPBD&IS), pp. 91–96, 2019, https://doi.org/10.1109/HPBDIS.2019.8735496.

[27] E.-S. M. El-Kenawy, M. M. Eid, A. A. Abdelhamid, A. Ibrahim, A. E. Takieldeen, and S. H. A. Elkhalik, “Hybrid Particle Swarm and Gray Wolf optimization for Prediction of Appliances in Low-Energy Houses,” in International Telecommunications Conference (ITC-Egypt), pp. 1–5, 2022, https://doi.org/10.1109/ITC-Egypt55520.2022.9855690.

[28] M. Punjabi and G. L. Prajapati, “Enhancing Performance of Lazy Learner by Means of Binary Particle Swarm Optimization,” in IEEE International Conference on Technology, Research, and Innovation for Betterment of Society (TRIBES), pp. 1–6, 2021, https://doi.org/10.1109/TRIBES52498.2021.9751675.

[29] O. D. Dsouza, G. Shilpa, and G. Irusapparajan, “Optimized energy management for hybrid renewable energy sources with Hybrid Energy Storage: An SMO-KNN approach,” J Energy Storage, vol. 96, p. 112152, 2024, https://doi.org/10.1016/j.est.2024.112152.

[30] J. Jiang, J. Wu, J. Luo, X. Meng, L. Qian, and K. Li, “KATSA: KNN Ameliorated Tree Seed Algorithm for complex optimization problems,” Expert Syst Appl, vol. 280, p. 127465, 2025, https://doi.org/10.1016/j.eswa.2025.127465.

[31] A. A. Aburomman and M. Bin Ibne Reaz, “A novel SVM-kNN-PSO ensemble method for intrusion detection system,” Appl Soft Comput, vol. 38, pp. 360–372, 2016, https://doi.org/10.1016/j.asoc.2015.10.011.

[32] J. Wang, F. Shi, P. Wan, M. Chen, and F. Jiang, “An Improved Particle Swarm Optimization Indoor Positioning Method Based on the Weighted Adaptive KNN Algorithm,” in IEEE/CIC International Conference on Communications in China (ICCC), pp. 1–5, 2023, https://doi.org/10.1109/ICCC57788.2023.10233671.

[33] W. Li, T. Jian, Y. Wang, and X. Ma, “Research on Virtual Machine Load Balancing Based on Improved Particle Swarm Optimization,” in IEEE Symposium Series on Computational Intelligence (SSCI), pp. 2846–2852, 2019, https://doi.org/10.1109/SSCI44817.2019.9002730.

[34] S. Xiong and Q. Gong, “KNN Text Classification Algorithm Based on Chaotic Particle Swarm Optimization,” in 3rd International Conference on Intelligent Communications and Computing (ICC), pp. 350–353, 2023, https://doi.org/10.1109/ICC59986.2023.10421154.

[35] Y. Song, Y. Gu, R. Zhang, and G. Yu, “BrePartition: Optimized High-Dimensional kNN Search with Bregman Distances (Extended Abstract),” in IEEE 39th International Conference on Data Engineering (ICDE), pp. 3883–3884, 2023, https://doi.org/10.1109/ICDE55515.2023.00368.

[36] Y. K. Kumarahadi, E. Apriliyanto, D. Yulianto, and Kusrini, “Decision Support System For Determining The Provision Of Single Tuition Relief Using KNN and SAW Methods,” in 8th International Conference on Cyber and IT Service Management (CITSM), pp. 1–6, 2020, https://doi.org/10.1109/CITSM50537.2020.9268886.

[37] M. C. S. Geeth, M. K. S. Varma, G. Bhagya Sri, R. Mythili, S. J. Naser, and E. Hassan, “Identification Emoticon Meaning using Facial Expression via Inception V3 as Well as KNN Methods,” in 4th International Conference on Advance Computing and Innovative Technologies in Engineering (ICACITE), pp. 418–421, 2024, https://doi.org/10.1109/ICACITE60783.2024.10616678.

[38] Y. Manzali, K. A. Barry, and M. El Far, “An improved KNN algorithm based on ensemble methods and correlation,” in 2023 7th IEEE Congress on Information Science and Technology (CiSt), pp. 64–70, 2023, https://doi.org/10.1109/CiSt56084.2023.10409922.

[39] H. Xing and R. Zhang, “Gait recognition for exoskeleton robots based on improved KNN-DAGSVM fusion algorithm,” in 37th Youth Academic Annual Conference of Chinese Association of Automation (YAC), pp. 364–369, 2022, https://doi.org/10.1109/YAC57282.2022.10023588.

[40] A. Palacios P. and Y. Suzuki, “An Immune Algorithm that Uses a Master Cell for Component Selection for the kNN Method,” in Global Medical Engineering Physics Exchanges/ Pan American Health Care Exchanges (GMEPE/PAHCE), pp. 1–4, 2019, https://doi.org/10.1109/GMEPE-PAHCE.2019.8717318.

[41] J. Ma, J. Li, and W. Wang, “Application of Wavelet Entropy and KNN in Motor Fault Diagnosis,” in 4th International Conference on Communications, Information System and Computer Engineering (CISCE), pp. 221–226, 2022, https://doi.org/10.1109/CISCE55963.2022.9851059.

[42] D. Bajpai and L. He, “Evaluating KNN Performance on WESAD Dataset,” in 12th International Conference on Computational Intelligence and Communication Networks (CICN), pp. 60–62, 2020, https://doi.org/10.1109/CICN49253.2020.9242568.

[43] S. T. Mrudula et al., “Internet of things and optimized knn based intelligent transportation system for traffic flow prediction in smart cities,” Measurement: Sensors, vol. 35, p. 101297, 2024, https://doi.org/10.1016/j.measen.2024.101297.

[44] M. Zhu et al., “Prediction of constitutive model for basalt fiber reinforced concrete based on PSO-KNN,” Heliyon, vol. 10, no. 11, p. e32240, 2024, https://doi.org/https://doi.org/10.1016/j.heliyon.2024.e32240.

[45] M. D. R. Irianto, M. D. Purbolaksono, and Bunyamin, “Sentiment Analysis of Livin’ by Mandiri Application Reviews Using Word2Vec Feature Extraction and KNN Method,” in International Conference on Data Science and Its Applications (ICoDSA), pp. 236–241, 2024, https://doi.org/10.1109/ICoDSA62899.2024.10651870.

[46] C. Sitawarin and D. Wagner, “Minimum-Norm Adversarial Examples on KNN and KNN based Models,” in IEEE Security and Privacy Workshops (SPW), pp. 34–40, 2020, https://doi.org/10.1109/SPW50608.2020.00023.

[47] C. Liang, L. Zhang, Z. Wan, D. Li, D. Li, and W. Li, “An improved kNN method based on Spearman’s rank correlation for handling medical missing values,” in International Conference on Machine Learning and Knowledge Engineering (MLKE), pp. 139–142, 2022, https://doi.org/10.1109/MLKE55170.2022.00033.

[48] Q. Yunneng, “A new stock price prediction model based on improved KNN,” in 7th International Conference on Information Science and Control Engineering (ICISCE), pp. 77–80, 2020, https://doi.org/10.1109/ICISCE50968.2020.00026.

[49] R. K. Barwal and N. Raheja, “A Classification System for Breast Cancer Prediction using SVOF-KNN method,” in International Conference on Augmented Intelligence and Sustainable Systems (ICAISS), pp. 765–770, 2022, https://doi.org/10.1109/ICAISS55157.2022.10010736.

[50] S. Briouza, H. Gritli, N. Khraief, S. Belghith, and D. Singh, “EMG Signal Classification for Human Hand Rehabilitation via Two Machine Learning Techniques: kNN and SVM,” in 5th International Conference on Advanced Systems and Emergent Technologies (IC_ASET), pp. 412–417, 2022, https://doi.org/10.1109/IC_ASET53395.2022.9765856.

[51] M. Kaur, C. Thacker, L. Goswami, T. TR, I. S. Abdulrahman, and A. S. Raj, “Alzheimer’s Disease Detection using Weighted KNN Classifier in Comparison with Medium KNN Classifier with Improved Accuracy,” in 3rd International Conference on Advance Computing and Innovative Technologies in Engineering (ICACITE), pp. 715–718, 2023, https://doi.org/10.1109/ICACITE57410.2023.10183208.

[52] C. Irawan, E. N. Ardyastiti, D. R. I. M. Setiadi, E. H. Rachmawanto, and C. A. Sari, “A Survey: Effect of the Number of GLCM Features on Classification Accuracy of Lasem Batik Images using K-Nearest Neighbor,” in International Seminar on Research of Information Technology and Intelligent Systems (ISRITI), pp. 33–38, 2018, https://doi.org/10.1109/ISRITI.2018.8864443.

[53] A. E. Minarno, Y. Azhar, F. D. Setiawan Sumadi, and Y. Munarko, “A Robust Batik Image Classification using Multi Texton Co-Occurrence Descriptor and Support Vector Machine,” in 3rd International Conference on Intelligent Autonomous Systems (ICoIAS), pp. 51–55, 2020, https://doi.org/10.1109/ICoIAS49312.2020.9081833.

[54] C. Irawan, A. Winarno, H. Kusumodestoni, A. Sucipto, T. Tamrin, and M. Doheir, “A Combination of Statistical Extraction and Texture Features Based on KNN for Batik Classification,” in International Seminar on Application for Technology of Information and Communication (iSemantic), pp. 113–117, 2021, https://doi.org/10.1109/iSemantic52711.2021.9573214.

[55] P. Zhang, X. Zhou, S. Liu, and Z. Dou, “Water Quality Prediction Based on CEEMDAN-LSTM-LINREG Model,” in 2023 12th International Conference of Information and Communication Technology (ICTech), pp. 602–608, 2023, https://doi.org/10.1109/ICTech58362.2023.00116.

[56] F. Lu et al., “Ultra-Short-Term Prediction of EV Aggregator’s Demond Response Flexibility Using ARIMA, Gaussian-ARIMA, LSTM and Gaussian-LSTM,” in 3rd International Academic Exchange Conference on Science and Technology Innovation (IAECST), pp. 1775–1781, 2021, https://doi.org/10.1109/IAECST54258.2021.9695933.

[57] F. Qian and X. Chen, “Stock Prediction Based on LSTM under Different Stability,” in IEEE 4th International Conference on Cloud Computing and Big Data Analysis (ICCCBDA), pp. 483–486, 2019, https://doi.org/10.1109/ICCCBDA.2019.8725709.

[58] Y. Zhang and S. Zhang, “Research on Blast Furnace Gas Flow Prediction Method Based on LSTM,” in 4th International Conference on Control and Robotics (ICCR), pp. 1–5, 2022, https://doi.org/10.1109/ICCR55715.2022.10053912.

[59] X. Wang and Y. Zhang, “Multi-Step-Ahead Time Series Prediction Method with Stacking LSTM Neural Network,” in 2020 3rd International Conference on Artificial Intelligence and Big Data (ICAIBD), pp. 51–55, 2020, https://doi.org/10.1109/ICAIBD49809.2020.9137492.

[60] A. Sinha, B. Rout, S. Mohanty, S. R. Mishra, H. Mohapatra, and S. Dey, “Exploring Sentiments in the Russia-Ukraine Conflict: A Comparative Analysis of KNN, Decision Tree and Logistic Regression Machine Learning Classifiers,” Procedia Comput Sci, vol. 235, pp. 1068–1076, 2024, https://doi.org/https://doi.org/10.1016/j.procs.2024.04.101.

[61] J. Deng, P. Zhao, Z. Wu, and Y. Wang, “Optimized performance of self-driven piezoelectric sensors through KNN/Nb2CTx synergistic effect,” Ceram Int, vol. 50, no. 17, pp. 31154–31163, 2024, https://doi.org/10.1016/j.ceramint.2024.05.421.

[62] Y. Liu, J. Fan, X. Qi, B. Shen, R. Zhang, and K. Yao, “Adaptive ferroelectric states in KNN-based piezoceramics: Unveiling the mechanism of enhancing piezoelectric properties through multiple phase boundary engineering,” Nano Energy, vol. 128, p. 109972, 2024, https://doi.org/10.1016/j.nanoen.2024.109972.

Downloads

Published

2025-05-04

How to Cite

[1]
A. Dafid, “Optimizing K-Nearest Neighbors with Particle Swarm Optimization for Improved Classification Accuracy”, J. Ilm. Tek. Elektro Komput. Dan Inform, vol. 11, no. 2, pp. 238–250, May 2025.

Issue

Section

Articles

Similar Articles

1 2 3 4 5 6 7 > >> 

You may also start an advanced similarity search for this article.