Magnesium potassium phosphate cement (MKPC) is a kind of Mg-chemically bonded phosphate ceramic commonly used for rapidly repairing dilapidated structures. In this study, a compressive strength dataset of MKPC was constructed, and four advanced machine learning (ML) algorithms (XGBoost, RF, GBDT and ANN) were selected to establish a high-precision compressive strength prediction model of MKPC. The SHAP and PDP methods are also used for interpretability analysis of ML-MKPC models. The XGBoost model has good generalizability and reliability while achieving high prediction accuracy. The RF and GBDT models performed similarly to the XGBoost model on the training set but performed poorly on the testing set. The ANN model is poorly trained on both the training and testing sets, with a risk of underfitting. The R2 of the XGBoost model at the different compressive strength stages still reaches above 0.80, indicating that it not only captures the complex relationships of the overall dataset well but also effectively predicts the staged strength dataset. Feature importance analysis revealed that the curing age (T), water-to-binder ratio (W/B), mineral admixtures-to-binder ratio (MA/B) and phosphate-to-magnesium ratio (P/M) are the principal variables affecting the compressive strength of MKPC. The partial interpretation shows that the optimum value range is determined when W/B is 0.10–0.18, MA/B is 0–0.20, P/M is 0.40–1.0, and R/M is 0–0.12. The composition of mineral admixtures with high-Ca, high-Si and low-Al systems seems to be more conducive to participating in the hydration reaction of MKPC. The ML-MKPC compressive strength prediction model developed in this study can provide theoretical support for the subsequent composition design and performance optimization of MKPC.