Comparison of K-Nearest Neighbors and Naive Bayes Classifier Algorithms in Sentiment Analysis of 2024 Election in Twitter (X)
DOI:
https://doi.org/10.30871/jaic.v9i3.9593Keywords:
Sentiment analysis, K-Nearest Neighbor (KNN), Naive Bayes, 2024 Election, Twitter (X)Abstract
This study compares the performance of the K-Nearest Neighbors (K-NN) and Naive Bayes Classifier (NBC) algorithms in sentiment analysis of the 2024 Regional Election (Pilkada) based on Indonesian local data sourced from platform X. A total of 1,187 tweets were collected through crawling, followed by extensive preprocessing and manual sentiment labeling by a professional linguist to ensure data validity and reliability. The study highlights NBC's superior accuracy (81.05%) compared to K-NN (75.26%), largely due to the characteristics of short-text social media data that align with NBC's independence assumptions. Key terms identified through TF-IDF analysis include “pilkada”, “2024”, and “damai” in positive sentiment, while “mahkamah konstitusi” and “kalah” dominated negative sentiment. The results imply that although public discourse largely supports the election process, critical sentiments toward election dispute issues persist. These findings offer practical implications for election authorities, policymakers, and digital campaign strategists, particularly in optimizing public communication strategies, early detection of potential conflicts, and designing public opinion monitoring systems based on real-time sentiment analysis. By leveraging high-quality labeled local data, this study makes a significant contribution to modeling public opinion dynamics in Indonesia during political events.
Downloads
References
[1] Y. Cahyana, “Analisis Sentiment Pembelajaran Tatap Muka Terbatas (Ptmt) Selama Pandemik Covid-19 Menggunakan Algoritma Naïve Bayes,” 2023, Doi: Https://Doi.Org/10.33322/Petir.V16i2.1964.
[2] A. M. Siregar, “Analisis Sentimen Pindah Ibu Kota Negara (Ikn) Baru Pada Twitter Menggunakan Algoritma Naive Bayes Dan Support Vector Machine (Svm),” Faktor Exacta, Vol. 16, No. 3, 2023, Doi: Http://Dx.Doi.Org/10.30998/Faktorexacta.V16i3.16703
[3] M. R. Pratama, A. Fauzi, D. Wahiddin, And A. R. Pratama, “Analisis Sentimen Kebijakan Pembelian Gas 3 Kg Dengan Ktp Menggunakan Naïve Bayes,” Jutisi: Jurnal Ilmiah Teknik Informatika Dan Sistem Informasi, Vol. 13, No. 2, Pp. 1338–1351, 2024, Doi: Http://Dx.Doi.Org/10.35889/Jutisi.V13i2.2168.
[4] R. F. R. Pohan, D. E. Ratnawati, And I. Arwani, “Implementasi Algoritma Support Vector Machine Dan Model Bag-Of-Words Dalam Analisis Sentimen Mengenai Pilkada 2020 Pada Pengguna Twitter,” Jurnal Pengembangan Teknologi Informasi Dan Ilmu Komputer, Vol. 6, No. 10, Pp. 4924–4931, 2022.
[5] H. Budiati, K. J. D. Lase, And V. C. Mendrofa, “Analisis Calon Bupati Sleman Pada Pilkada 2024 Dengan Menggunakan Natural Language Processing Dan Fuzzy Logic,” Jurnal Informatika Dan Rekayasa Elektronik, Vol. 7, No. 2, Pp. 334–342, 2024, Doi: Https://Doi.Org/10.36595/Jire.V7i2.1307.
[6] L. S. Windanu, A. S. Wiguna, And A. E. Budianto, “Optimasi Metode K-Nearest Neighbor Berbasis Particle Swarm Optimization Untuk Analisis Sentimen Pemilihan Presiden Indonesia Tahun 2024-2029,” Jati (Jurnal Mahasiswa Teknik Informatika), Vol. 8, No. 1, Pp. 35–42, 2024, Doi: Https://Doi.Org/10.36040/Jati.V8i1.6874.
[7] M. F. Haikal, J. Indra, And R. Rahmat, “Analisis Sentimen Bakal Calon Presiden Indonesia 2024 Dengan Algoritma Naïve Bayes,” Jutisi: Jurnal Ilmiah Teknik Informatika Dan Sistem Informasi, Vol. 13, No. 1, Pp. 43–51, 2024, Doi: Http://Dx.Doi.Org/10.35889/Jutisi.V13i1.1598.
[8] G. N. V. Kurniawan And N. R. Feta, “Perbandingan Akurasi Algoritma Naïve Bayes Dan Support Vector Machine Dalam Analisis Sentimen Pengguna Twitter Terhadap Aplikasi Sirekap,” Fountain Of Informatics Journal, Vol. 9, No. 2, Pp. 65–71, 2024, Doi: Https://Dx.Doi.Org/10.21111/Fij.V9i2.12717.
[9] R. Noviana And I. Rasal, “Penerapan Algoritma Naive Bayes Dan Svm Untuk Analisis Sentimen Boy Band Bts Pada Media Sosial Twitter,” Jurnal Teknik Dan Science, Vol. 2, No. 2, Pp. 51–60, 2023, Doi: Https://Doi.Org/10.56127/Jts.V2i2.791.
[10] S. Wahyu, “Perbandingan Model Algoritma Klasifikasi Pada Analisis Sentimen Opini Masyarakat Terhadap Layanan Kereta Cepat Jakarta Bandung (The Whoosh),” Proceeding Konik (Konferensi Nasional Ilmu Komputer), Vol. 6, Pp. 218–225, 2023.
[11] A. Agustian And F. Nurapriani, “Analisis Sentimen, Text Mining Penerapan Analisis Sentimen Dan Naive Bayes Terhadap Opini Penggunaan Kendaraan Listrik Di Twitter,” Jurnal Tika, Vol. 7, No. 3, Pp. 243–249, 2022, Doi: Https://Doi.Org/10.51179/Tika.V7i3.1550.
[12] Y. Khoiruddin, A. Fauzi, And A. M. Siregar, “Analisis Sentimen Gojek Indonesia Pada Twitter Menggunakan Algoritme Naïve Bayes Dan Support Vector Machine,” Progresif: Jurnal Ilmiah Komputer, Vol. 19, No. 1, Pp. 391–400, 2023.
[13] N. A. Nevrada And M. A. Syaputra, “Sentiment Analysis Of Telegram App Reviews On Google Play Store Using The Support Vector Machine (Svm) Algorithm,” Journal Of Applied Informatics And Computing, Vol. 9, No. 1, Pp. 96–105, 2025.
[14] Y. R. Nasution, S. Suhardi, And I. H. Satrio, “Penerapan Algoritma Klasifikasi Naïve Bayes Untuk Analisis Sentimen Tentang Pemilu 2024,” Elkom: Jurnal Elektronika Dan Komputer, Vol. 17, No. 2, Pp. 495–502, 2024, Doi: Https://Doi.Org/10.51903/Elkom.V17i2.2053.
[15] A. R. Gunawan And R. F. A. Aziza, “Sentiment Analysis Using Lstm Algorithm Regarding Grab Application Services In Indonesia,” Journal Of Applied Informatics And Computing, Vol. 9, No. 2, Pp. 322–332, 2025, Doi: Https://Doi.Org/10.30871/Jaic.V9i2.8696.
[16] J. Setyanto And T. B. Sasongko, “Sentiment Analysis Of Sirekap Application Users Using The Support Vector Machine Algorithm,” Journal Of Applied Informatics And Computing, Vol. 8, No. 1, Pp. 71–76, 2024, Doi: Https://Doi.Org/10.30871/Jaic.V8i1.7772.
[17] A. A. Muttaqin, S. Alam, And M. A. Komara, “Analisis Sentimen Isu Kecurangan Pemilu 2024 Berdasarkan Opini Pada Media Sosial Twitter Menggunakan Metode Crisp-Dm Dengan Algoritma Naïve Bayes Classifier,” Jati (Jurnal Mahasiswa Teknik Informatika), Vol. 8, No. 5, Pp. 8764–8772, 2024, Doi: Analisissentimenisukecuranganpemilu2024berdasarkanopinipadamediasosialtwittermenggunakanmetodecrisp-Dmdenganalgoritmanaïvebayesclassifier.
[18] M. Fadil, “Perbandingan Metode K-Nearest Neighbors Dan Naïvebayes Classification Dalam Klasifikasi Sentimen Masyarakat Terhadap Pemilu Presiden Tahun 2024,” Nov. 2024, Doi: Http://Dx.Doi.Org/10.35889/Jutisi.V13i3.2068.
[19] A. K. Subagyo, H. S. H. Syahputra, Z. F. Khoiri, And S. Sukmadiningtyas, “Analisis Sentimen Masyarakat Terhadap Pelantikan Kabinet Merah Putih Pada Media Sosial,” In Proceedings Of The National Conference On Electrical Engineering, Informatics, Industrial Technology, And Creative Media, 2024, Pp. 1080–1089.
[20] T. P. R. Sanjaya, A. Fauzi, And A. F. N. Masruriyah, “Analisis Sentimen Ulasan Pada E-Commerce Shopee Menggunakan Algoritma Naive Bayes Dan Support Vector Machine,” Infotech: Jurnal Informatika & Teknologi, Vol. 4, No. 1, Pp. 16–26, 2023,Doi:Https://Doi.Org/10.37373/Infotech.V4i1.422.
Downloads
Published
How to Cite
Issue
Section
License
Copyright (c) 2025 Lola Enjelia, Yana Cahyana, Rahmat, Deden Wahiddin

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Authors who publish with this journal agree to the following terms:
- Authors retain copyright and grant the journal right of first publication with the work simultaneously licensed under a Creative Commons Attribution License (Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) ) that allows others to share the work with an acknowledgement of the work's authorship and initial publication in this journal.
- Authors are able to enter into separate, additional contractual arrangements for the non-exclusive distribution of the journal's published version of the work (e.g., post it to an institutional repository or publish it in a book), with an acknowledgement of its initial publication in this journal.
- Authors are permitted and encouraged to post their work online (e.g., in institutional repositories or on their website) prior to and during the submission process, as it can lead to productive exchanges, as well as earlier and greater citation of published work (See The Effect of Open Access).