Stunting is a condition of stunted physical growth in children due to chronic nutritional deficiencies with serious impacts on health and psychological aspects. The impacts include decreased self-esteem, learning difficulties, impaired concentration, critical thinking problems, and lower economic contributions as adults. This study aims to optimize the XGBoost classification model using the Grid Search and Random Search methods, thereby improving the accuracy of detecting stunting and obtaining an accurate and efficient diagnosis. Seeing the danger and alarming prevalence rate of stunting, signaling the urgency of handling this problem for the welfare of future generations, an automatic classification model is needed to avoid subjectivity and potential errors in the manual decision-making process. XGBoost needs optimization because it has parameters that require adjustment to maximize accuracy. Comparison of two optimization models is important to understand the advantages and disadvantages of each because they have different approaches in finding the best combination. The study used 10,000 data from Krobokan Health Center with attributes of gender, age, birth weight, birth height, weight at measurement, height at measurement, and category. The largest increase in accuracy was obtained by the Grid Search model with an increase in XGBoost accuracy of 5.81% from 83.28% to 89.09%. The Random Search model increased the accuracy by 5.43%, reaching an accuracy of 88.71%. The choice of both models depends on time and resource preferences. Random Search provides higher time efficiency than Grid Search. This research can contribute to identifying children at risk of stunting so that intervention actions can be carried out more efficiently.