Brain stroke is one of the diseases with a high mortality rate worldwide, and it is a great threat to the health of people around the world. In this paper, the data were firstly processed by SMOTE to avoid the problem of oversampling, and then mathematical models based on random forest algorithm, support vector machine and logistic regression were developed to predict the risk of stroke based on the existing data. When comparing the prediction results of each model, the prediction accuracy of the model based on the random forest algorithm was the highest (accuracy = 96.94%), while the prediction results of the support vector machine and logistic regression were slightly lower than those of the random forest (support vector machine accuracy = 76.40%; logistic regression accuracy = 94.51%). In terms of the ROC curve and recall of the data, the random forest model achieved an AUC value of 97.46%, proving its excellent prediction performance.