Flood risk prediction is a crucial step in disaster mitigation. This study optimizes the Extreme Gradient Boosting (XGBoost) algorithm using the Particle Swarm Optimization (PSO) method to improve prediction accuracy. The process includes data cleaning, normalization, and classification of risk levels into low, medium, and high. The XGBoost model is trained both before and after parameter optimization of n_estimators, max_depth, and learning_rate. Before optimization, the model achieved 93% accuracy but struggled to identify minority classes. After optimization with PSO, accuracy increased to 97%, with the recall for the low-risk class improving from 21% to 57%. The optimized model also demonstrated more stable performance compared to Support Vector Machine (SVM) and Random Forest. These findings indicate that the combination of XGBoost and PSO can provide more accurate and efficient flood risk predictions.