Comparison of Random Forest and K-Nearest Neighbors (KNN) Algorithms in Detecting Credit Card Transaction Anomalies

Authors

  • Fitria Politeknik Negeri Banjarmasin
  • Emy Iryanie Politeknik Negeri Banjarmasin
  • Heldalina Politeknik Negeri Banjarmasin
  • Muhammad Syahid Pebriadi Politeknik Negeri Banjarmasin
  • Heru Kartika Candra Politeknik Negeri Banjarmasin

DOI:

https://doi.org/10.59890/ijir.v3i7.49

Keywords:

Random Forest, K-Nearest Neighbors (KNN), Machine Learning, Transaction Anomalies

Abstract

This study aims to compare two machine learning algorithms, namely Random Forest and K-Nearest Neighbors (KNN), in detecting anomalies in credit card transactions for fraud detection purposes. The dataset used consists of credit card transactions that include features such as the number of transactions, transaction types, sender and recipient balances. The results of the study show that Random Forest excels in terms of accuracy and ability to distinguish legitimate and fraudulent transactions compared to KNN. Although KNN has advantages in terms of speed and interpretability, the model's performance declines on large and unbalanced data. Instead, Random Forest can better address class imbalances and data complexity, resulting in more stable and more accurate models. Based on these findings, Random Forest is more recommended for use in credit card fraud detection applications, while KNN can be considered for simpler applications or smaller data. This research provides useful insights for the development of machine learning-based fraud detection systems in the financial sector

References

Alduailij M, Khan QW, Tahir M, Sardaraz M, Alduailij M, Malik F. Machine-Learning-Based DDoS Attack Detection Using Mutual Information and Random Forest Feature Importance Method. Symmetry (Basel). 2022;14(6):1095.

Credit_Card_Transactions [Internet]. [cited 2025 Jul 25]. Available from: https://www.kaggle.com/datasets/kelvinobiri/credit-card-transactions

Echkina E. Comparative Analysis of Two Methods for Detecting Anomalies Using the Example of Industrial Equipment Operation. J Phys Conf Ser. 2025;3027(1):12077.

Faraji Z. A Review of Machine Learning Applications for Credit Card Fraud Detection With a Case Study. Seisense J Manag. 2022;5(1):49–59.

Fitria F, Pebriadi MS. House Price Prediction Using the Random Forest Algorithm on the Rapidminer Application. Formosa J Sci Technol. 2025;4(2):727–38.

Gao C, Chen Y zhe, Chen Y, Wang Z, Xia H. An Improved K-Nn Anomaly Detection Framework Based on Locality Sensitive Hashing for Edge Computing Environment. Intell Data Anal. 2023;27(5):1267–85.

Guo L, Song R, Wu J, Xu Z, Zhao F. Integrating a Machine Learning-Driven Fraud Detection System Based on a Risk Management Framework. Appl Comput Eng. 2024;87(1):80–6.

Jaiswal I, Bharadwaj A, Kumari K, Agarwal N. Credit Card Deception Recognition Using Random Forest Machine Learning Algorithm. Eai Endorsed Trans Internet Things. 2024;10.

Lestari FP, Haekal M, Edison RE, Fauzy FR, Khotimah SN, Haryanto F. Epileptic Seizure Detection in EEGs by Using Random Tree Forest, Naïve Bayes and KNN Classification. J Phys Conf Ser. 2020;1505(1):12055..

Liu C. Enhancing Credit Card Fraud Detection on Imbalanced Datasets. Highlights Bus Econ Manag. 2023;21:765–73.

Pk R. Enhanced Credit Card Fraud Detection: A Novel Approach Integrating Bayesian Optimized Random Forest Classifier With Advanced Feature Analysis and Real-Time Data Adaptation. Int J Innov Eng Manag Res. 2023;537–61.

Prabowo AS, Kurniadi FI. Analisis Perbandingan Kinerja Algoritma Klasifikasi Dalam Mendeteksi Penyakit Jantung. J Siskom-Kb (Sistem Komput Dan Kecerdasan Buatan). 2023;7(1):56–61.

Priyadarshini A, Mishra S, Mishra DP, Salkuti SR, Mohanty R. Fraudulent Credit Card Transaction Detection Using Soft Computing Techniques. Indones J Electr Eng Comput Sci. 2021;23(3):1634.

Saeed VA, Abdulazeez AM. Credit Card Fraud Detection Using KNN, Random Forest and Logistic Regression Algorithms : A Comparative Analysis. Indones J Comput Sci. 2024;13(1).

Sailellah HRP. Telkom University. 2023 [cited 2023 Nov 3]. Internet of Things : Pengertian, Sejarah, Kelebihan dan Kekurangannya. Available from: https://it.telkomuniversity.ac.id/internet-of-things-pengertian-sejarah-kelebihan-dan-kekurangannya/

Shahid MA, Baig S, Jaisharma K. Comparison of Novel Optimized Random Forest Technique and Gradient Boosting for Credit Card Fraud Detection With Improved Precision. PNR. 2022;13(SO4).

Simbolon S. Recognizing Credit Card Fraud Transaction Using Spending Behavior-Based Transaction Features. Int J Emerg Trends Eng Res. 2020;8(8):4618–24.

Steven S, Negara ABP, Yulianti Y. Implementasi Algoritma K-Nearest Neighbor Untuk Mengklasifikasi Masa Studi Mahasiswa Informatika Universitas Tanjungpura. J Sist Dan Teknol Inf. 2022;10(3):319.

Wang B, Ying S, Yang Z. A Log-Based Anomaly Detection Method With Efficient Neighbor Searching and Automatic K Neighbor Selection. Sci Program. 2020;2020:1–17.

Zhang Y, Lü H, Lin HF, Qiao XC, Zheng H. The Optimized Anomaly Detection Models Based on an Approach of Dealing With Imbalanced Dataset for Credit Card Fraud Detection. Mob Inf Syst. 2022;2022:1–10.

Downloads

Published

2025-08-01

Issue

Section

Articles