Publishing Journal • Journal of Science and Social Research (JSSR)

PENERAPAN ALGORITMA K-NEAREST NEIGHBOR (KNN) DALAM KLASIFIKASI TREN HARGA EMAS BERBASIS WEB

DOI: 10.54314/jssr.v9i5.7314 Published: 01 October 2026 Views: 1
Authors & Researchers
R
Rahmat, Rahmat Universitas Asahan1
S
Siregar, Helmi Fauzi Universitas Asahan2

Abstract

Abstract: Gold is widely used as a store of value and a safe-haven investment, yet its daily price fluctuations make it difficult for investors and the public to determine the direction of price movement. This study applies the K-Nearest Neighbor (KNN) algorithm to classify gold price trends into three classes (Up, Down, and Stable) based on the monthly percentage change in the average gold price. The data are public historical gold prices from January 2022 to August 2026, in which each month consists of four period values that are processed into the highest, lowest, and average price. The percentage change in the average price relative to the previous month is used as the single numerical feature; it is labeled with a ±1% threshold and normalized using Min-Max Normalization. The data are split chronologically into 47 training data (February 2022–December 2025) and 8 testing data (January–August 2026). Classification is carried out by calculating the Euclidean Distance and applying majority voting among K = 5 nearest neighbors. The model is implemented in a web-based application built with PHP and MySQL. Testing on the eight test data yields an accuracy of 100%, with precision, recall, and F1-score of 100% for every class. However, the small test set and the imbalanced class distribution (only four Down training records and one Stable test record) indicate that the result needs further validation on longer data periods. Keywords: K-Nearest Neighbor, classification, gold price, trend, data mining.   Abstrak: Emas banyak digunakan sebagai penyimpan nilai dan investasi aman (safe haven), namun harganya yang berubah setiap hari menyulitkan investor dan masyarakat dalam menentukan arah pergerakan harga. Penelitian ini menerapkan algoritma K-Nearest Neighbor (KNN) untuk mengklasifikasikan tren harga emas ke dalam tiga kelas (Naik, Turun, dan Stabil) berdasarkan persentase perubahan harga rata-rata bulanan. Data yang digunakan adalah data historis harga emas dari sumber publik periode Januari 2022–Agustus 2026, yang setiap bulannya terdiri atas empat nilai Periode dan diolah menjadi Harga Tertinggi, Harga Terendah, dan Harga Rata-rata. Persentase perubahan harga rata-rata terhadap bulan sebelumnya digunakan sebagai fitur numerik tunggal, diberi label dengan ambang batas ±1%, dan dinormalisasi menggunakan Min-Max Normalization. Data dibagi berdasarkan urutan waktu menjadi 47 data latih (Februari 2022–Desember 2025) dan 8 data uji (Januari–Agustus 2026). Klasifikasi dilakukan dengan menghitung Euclidean Distance dan voting mayoritas dari K = 5 tetangga terdekat. Model diimplementasikan ke dalam aplikasi berbasis web yang dibangun menggunakan PHP dan MySQL. Pengujian terhadap delapan data uji menghasilkan akurasi 100%, dengan precision, recall, dan F1-score 100% pada setiap kelas. Namun, jumlah data uji yang kecil dan distribusi kelas yang tidak seimbang (data latih kelas Turun hanya empat dan data uji kelas Stabil hanya satu) menunjukkan bahwa hasil ini perlu divalidasi pada periode data yang lebih panjang. Kata kunci: K-Nearest Neighbor, klasifikasi, harga emas, tren, data mining.

Indexing Journal

Journal of Science and Social Research (JSSR) Cover

Journal of Science and Social Research (JSSR)

ISSN: 2615 –4307 Publisher: GORETAN PENA