Heart failure is a disease with an extraordinarily high incidence rate and mortality among cardiovascular diseases in the world. Previous experimental studies have found that the mortality rate of heart failure reaches 10% within 30 days and 50% within half a year. Therefore, effective prediction of patient mortality plays an undeniable role in the treatment of this disease. In recent years, the prediction and classification methods of machine learning have made great contributions to various fields in the world. Therefore, inspired by this, this paper will compare the accuracy of traditional linear regression and three machine learning methods for predicting mortality in patients with heart failure. The methods used in this paper include traditional logistic regression, k-nearest neighbor classification, random forest, and decision tree. To compare the accuracy of each method more effectively, the parameter changes in each method have been fully considered, including the selection of k value in the k-nearest neighbor classification, the number of variables used for growing trees in random forests, two pruning methods in decision tree, and the two model selection methods in logistic regression. Finally, the experiment result shows that the random forest has the highest accuracy.