One of the leading causes of death nowadays is heart disease, so more has to be done to avoid it, such as by making prediction models work better. Among the machine learning algorithms is K-Nearest Neighbor (K-NN) is among the best methods for predicting heart disease based on several risk factors, including smoking, high blood pressure, diabetes, age, and so on. To get accurate values and attribute selection features, we tested them with K-NN, and to improve the results of our research predictions, we combined them using the Particle Swarm Optimization (PSO) algorithm. The results are very interesting after we do the calculations, the algorithm that uses PSO-based K-NN gets a higher weight compared to using only the K-NN algorithm. The predicted value of the weight resulting from the PSO-based K-NN is 97.67%. while the results only use K-NN of 64.92%. The advantages of PSO can also select attributes that can affect it, namely age, diabetes, and ejection fraction. So gathering information through data mining. The PSO-Based K-NN method, which is the primary machine learning technique used in this computation, yields the greatest results in terms of accuracy for heart disease when applied to the data assets. Using the K-NN - PSO algorithm can provide promising results for predicting symptoms that cause heart disease with very good accuracy. PSO is Used to choose features and optimize k values on the K-NN dataset, after which the accuracy is output on the K-NN.