# AI-Based Prediction of Myocardial Infarction Risk as an Element of Preventive Medicine
## 2 Materials and Methods
### Modelling Results  
To tune the logistic regression model we used the GridSerachCV method. This method tests every single possible combination of hyperparameters and saves the best. During the experiment, we only tuned 2 hyperparameters: \"C\" and \"solver\".  
The tuning process returned the following values:  
{'C': 0.23357214690901212,'solver': 'liblinear'}  
The evaluation of the model, with those parameters, was 0.8852459016393442.  
To tune the KNN method, we tried different values of n_neighbours. The train scores exhibited the following values:  
1.0,  
0.8099173553719008,  
0.77272727272727,  
0.743801652892562,  
0.7603305785123967,  
0.7520661157024794,  
0.743801652892562,  
0.7231404958677686,  
Figure 7: Correlation matrix.  
0.71900826446281,  
0.6942148760330579,  
0.7272727272727273,  
0.6983471074380165,  
0.6900826446280992,  
0.6942148760330579,  
0.6859504132231405,  
0.6735537190082644,  
0.6859504132231405,  
0.6652892561983471,  
0.6818181818181818,  
0.6694214876033058.  
The training accuracy score shows how the model fits and generalises to the training data. If, after training, we obtain a model that fits the data well with a large variance then this results in over-fitting and consequently a worse testing accuracy score. This is because the model is skewed to fit the training data and generalises very poorly. The 75.41% score we achieved is good and was sufficient for most predictive applications as it allowed us to identify with high probability those individuals who should be subjected to further, more accurate diagnostics without having to test all individuals. The strategies adopted here can vary further, e.g., if the model is to be further optimised later then the testing accuracy score should not be higher than the training accuracy score, as the model would be too matched to the test dataset. Our approach at this stage focused on two factors: accuracy and low computational cost. Hence looking at the graph, n_neighbours = 11 seemed best (Figure 8). With higher values of n_neighbours the computational costs increased, but the accuracy did not improve.  
To tune the random forest classifier model, we used RandomizedSearchCV method. This method searches over a grid of hyperparameters performing n_iter combinations and saves the best. During the experiment only 4 hyperparameters were tuned: \"n_estimators\", \"max_depth\", \"min_simples_split\" and \"min_simples_leaf\". RandomizedSearchCV tried 20 different combinations of hyperparameters from rf_grid and saved the best ones. The evaluation of the model with these parameters was 0.8688524590163934. The evaluation of the LinearSVC model was 0.8688524590163934. During the experiment we did not make any tuning on this model. All these algorithms were supported by the Scikit-Learn library for classification problems. We compared the results from the different models and logistic regression performed best (Figure 9).  
Figure 8: Training accuracy scores and testing accuracy scores for the KNN model.  
The logistic regression model was very good achieving an AUC = 0.92 (a perfect model would achieve an AUC = 1.0) (Figure 10).  
The confusion matrix compares where the model, based on logistic regression, made the right predictions and where it made wrong predictions (Figure 11).  
Using the logistic regression model we achieved the following classification report (Table 2).  
Figure 11: Confusion matrix.  
Figure 9: Models comparison: Logistic regression model exhibited the highest accuracy.