Some patients with postoperative atrial fibrillation (POAF) after non-cardiac surgery need treatment, and a predictive model for these patients is clinically useful. Here, we developed a predictive model for POAF in non-cardiac surgery based on machine learning techniques. In a total of 201,864 patients who underwent non-cardiac surgery between January 2011 and June 2019 at our institution, 5,725 (2.8%) were treated for POAF. We used machine learning with an extreme gradient boosting algorithm to evaluate the effects of variables on POAF. Using the top five variables from this algorithm, we generated a predictive model for POAF and conducted an external validation. The top five variables selected for the POAF model were age, lung operation, operation duration, history of coronary artery disease, and hypertension. The optimal threshold of probability in this model was estimated to be 0.1, and the area under the receiver operating characteristic (AUROC) curve was 0.80 with a 95% confidence interval of 0.78–0.81. Accuracy of the model using the estimated threshold was 0.95, with sensitivity and specificity values of 0.28 and 0.97, respectively. In an external validation, the AUROC was 0.80 (0.78–0.81). The working predictive model for POAF requiring treatment in non-cardiac surgery based on machine learning techniques is provided online (https://sjshin.shinyapps.io/afib_predictor_0913/). The model needs further verification among other populations.