This study aims to optimize the implementation of the K-Nearest Neighbors (K-NN) algorithm for medical image classification by focusing on selecting the optimal KKK parameter and applying dimensionality reduction techniques to improve accuracy and efficiency. The data used was sourced from public medical image repositories such as The Cancer Imaging Archive (TCIA) and Medical Image Analysis datasets, covering various diseases, including brain tumors, lung cancer, and kidney lesions. The research process involves data collection, data preprocessing, dimensionality reduction using Principal Component Analysis (PCA), applying the K-NN algorithm with Euclidean, Minkowski, and Cosine distance metrics, and performance evaluation using accuracy, precision, recall, and F1-score. Experimental results demonstrate that K=5with the Euclidean distance metric provides the best performance, achieving an accuracy of 90%. Additionally, PCA effectively reduces computational time by 30% without significantly compromising accuracy. This study proves that K-NN is an effective method for medical image classification. However, further research is needed to integrate K-NN with deep learning models to enhance performance and feature extraction capabilities.