The 2024 Regional Head Election Law (UU Pilkada) has become an important issue widely discussed in Indonesia, especially on the social media platform X. Various public comments related to this issue contain positive, negative, and neutral sentiments, reflecting public perceptions. This study aims to analyze the sentiment of public comments on the 2024 UU Pilkada using two machine learning methods: Naïve Bayes and K-Nearest Neighbor (K-NN). The dataset consists of 3864 comments divided into three sentiment classes: 1477 negative comments, 1385 neutral comments, and 1002 positive comments, all of which have undergone text preprocessing. Evaluation was conducted using k-fold cross-validation (k=10). The test results show that the Naïve Bayes method achieves the highest accuracy of 63.47%, while K-NN reaches 56.73%. The precision for negative sentiment is 56.84%, meaning that about 43% of the comments predicted as negative by the model are actually not negative. The recall for negative sentiment is 45.45%, indicating that the model only captures less than half of the actual negative comments. For neutral sentiment, the precision of 60.71% and recall of 66.23% suggest that the model performs fairly well in recognizing neutral comments, although there is still a 39.29% error. For positive sentiment, the precision of 55.55% and recall of 57.63% indicate errors in classifying positive comments. Overall, while the model can correctly classify a portion of the data, there is potential to improve accuracy for both the negative and positive classes.