With the development of artificial intelligence, the application of machine learning has played a key role in medicine, finance, retail, tourism, etc. This article scientifically assesses the application of machine learning in medical diagnostic functions to determine the risk of heart disease in patients by building effective machine learning models derived by using classification methods to select the key symptoms and living factors. 2020 heart disease datasets were applied and 19 indicators in the datasets have been evaluated to predict whether a patient has a risk of having heart disease. To make a more accurate correlation between these indicators and heart disease, the indicators are developed by feature transformation, normalization, and feature selection after cleaning raw datasets. The linear regression and random forest classification algorithms were applied and tested. The result shows that the test of random forest model with oversampling revision has a higher accuracy of 91.00%.