Earthquake prediction is crucial for risk mitigation, particularly in taking appropriate preventive measures in the face of disasters. The magnitude of an earthquake is influenced by various factors, including location, depth, and the history of seismic activity in a region. This study aims to develop an accurate earthquake magnitude prediction model by integrating clustering and ensemble learning techniques. Earthquake catalog data from BMKG Indonesia is processed and clustered using the DBSCAN algorithm based on geographical location. The prediction model is constructed using Random Forest and XGBoost, then integrated through stacking ensemble learning techniques. Evaluation results indicate that the stacking model delivers the best performance, with the lowest Mean Squared Error (MSE) of 0.108 and the highest R-squared (R²) of 0.892, compared to individual models. This accuracy improvement is attributed to stacking’s ability to combine the predictive strengths of Random Forest and XGBoost. The study demonstrates that integrating clustering and ensemble learning can enhance earthquake magnitude prediction models. However, further research is needed to explore more comprehensive data and features and to test model generalization in other regions.