Cardiotoxicity is a severe side effect for colorectal cancer (CRC) patients undergoing fluoropyrimidine-based chemotherapy. To develop and compare machine learning algorithms to predict cardiotoxicity risk among nationally representative CRC patients receiving fluoropyrimidine, CRC Patients with at least one claim of fluoropyrimidine after their cancer diagnosis were included. The outcome was the 30-day cardiotoxicity from the first day of starting fluoropyrimidine. The machine learning models including extreme gradient boosting (XGBoost), random forest (RF), and logistic regression (LR) were developed using 2006–2011 SEER-Medicare data, and model performances were evaluated using 2012–2014 data. Precision, F1 score, and area under the receiver operating characteristics curve (AUC) were measured to evaluate model performances. Feature importance plots were obtained to quantify the predictor importance. Among 36,030 CRC patients, 18.74% of them developed cardiotoxicity within 30 days since the first fluoropyrimidine. The XGBoost approach had better prediction performance with higher precision (0.619) and F1 score (0.406) in predicting the 30-day cardiotoxicity, compared to the RF (precision, 0.607 and F1 score, 0.395) and LR (precision, 0.610 and F1 score, 0.398). According to the DeLong’s test for AUC difference, the XGBoost significantly outperformed the RF and LR (XGBoost, 0.816 vs. RF, 0.804, P < 0.001; XGBoost vs. LR, 0.812, P = 0.003, respectively). Feature importance plots identified pre-existing cardiac conditions, surgery, older age as top significant risk factors for cardiotoxicity events among CRC patients after receiving fluoropyrimidine. In summary, the developed machine learning models can accurately predict the occurrence of 30-day cardiotoxicity among CRC patients receiving fluoropyrimidine-based chemotherapy.