Introduction

Machine learning (ML) is one of the sub-branches of artificial intelligence (AI) that deals with the ways in which machines learn from experience [17, 18]. Over 415 million people were suffering from diabetes mellitus worldwide as of 2015, 8.3% being part of the adult population, with equal rates in both women and men. DM type 2 constitutes approximately 90% of the cases [18]. DM is estimated to have resulted in 1.5–5.0 million deaths each year in the period of 2012–2015 [14, 15, 19] and it doubles a person's risk of dying. The number of people with diabetes is expected to rise to 592 million by 2035 [15]. DM is one of the growing public health concerns in Nigeria. Four years ago, South Africa and Ethiopia had more cases of diabetes than Nigeria, but now Nigeria has the highest incidence of diabetes in the sub-Saharan Africa [18]. In this study, the diagnostic dataset of DM type 2 was collected from the Murtala Mohammed Hospital, Kano–Nigeria and used to develop the predictive supervised ML model based on logistic regression, support vector machine, K-nearest neighbor, random forest, naive Bayes, and gradient booting algorithms.

Related Work

Many works have been carried out using supervised ML to build predictive models in the health-care sector to complement and supplement the works of health workers in the course of diagnosing many diseases.

In the work of [10], COVID-19 prediction models that use supervised ML was developed. The model was developed based on liner regression (LR), support vector machine (SVM), least absolute shrinkage and selection (LASSO), and exponential smoothing (ES) algorithms. The study demonstrated the capability of the supervised ML algorithms to predict the number of upcoming COVID-19 patients that were affected. A supervised ML approach, which incorporated the generic algorithm and weighted K-nearest neighbor (WKNN) algorithms to predict and classify DM type 2 according to the presence or absence of coronary artery disease complications, was developed in the work of [20]. The supervised ML predictive model for acute ischemic stroke post intra-arterial therapy was developed in the work of [21]. The model showed a promising accuracy of the prediction and the study further proposed a robust learning model that can potentially optimize the selection process for medical treatment and endovascular activity in the management of acute strokes. In the work of [22], the predictive supervised ML model for the prediction of post-induction hypotension was developed. The result of the study showed that the success recorded in prediction post-induction hypotension demonstrates the ability of supervised ML models for predictive analytics in the field of anesthesiology. The predictive model for hospitalization due to heart disease was developed using supervised ML algorithms in the work of [23]. The dataset used for the development of the model was collected from an urban hospital in Boston and five models were developed using SVM, AdaBoost, LR, Naïve Bayes, and likelihood ratio test algorithms. A supervised ML model for rapid detection of heat rate fragmentation and cardiac arrhythmias was developed in the study of [24]. A random forest algorithm and a dataset of 300 instances of arrhythmic, non-arrhythmic coronary artery disease, and individuals without any medically significant cardiac conditions were used to develop a predictive model. The model was evaluated with 104 independent cases and proved to be very efficient. In the work of [25], supervised ML was used to generate a molecular signature that can classify metastatic hepatocellular carcinoma patients and identified genes that were relevant to metastatic and survival of the patients. In the work of [26], a review of supervised machine learning for population genetics was carried out and the review study found that there is a promising direction in the area. The study further found that supervised machine learning is an important and underutilized technique that has considerable potential for the evolutionary genomics. A supervised ML model for the identification of mosquitoes from the backscattered optical signal was developed in the study of [24]. The study showed that the optical sensor coupled with supervised ML can be a viable alternative means for monitoring the mosquito population. The predictive supervised ML approach for the estimation of the risk recurrence in early stages of oral tongue squamous cell carcinoma has been developed in the work of [27]. The result of the study showed the ability of supervised ML to predict locoregional recurrences. Supervised ML algorithms which include support vector machines, linear discriminant analysis, and K-nearest neighbor algorithms were used to identify dementia in the work of [28]. The result of the study showed that the algorithms are capable of predicting dementia.

Therefore, various related works so far reviewed in this section showed the potential ability of supervised ML algorithms to develop a model for the prediction of DM type 2.

Materials and Methods

Dataset

The diagnostic dataset for the DM type 2 patients was collected from the Murtala Mohammed Specialist Hospital, Kano State, in Nigeria. The dataset has nine attributes, including age, family history, glucose, cholesterol (CHOL), blood pressure (BP), HDL (high density lipoprotein), triglyceride, BMI (body mass index), and the diagnosis result. The dataset has 383 instances. Table 1 shows the description of units and ranges of risk attributes of the dataset.

Table 1 Description of units and ranges of the dataset attributes

Supervised Machine Learning Algorithms

Support Vector Machine

The support vector machine (SVM) is an elegant, powerful, and one of the most widely used supervised ML algorithms. SVM is used for both the regression and classification machine learning task problems due to its capability to non-linearly predict separable patterns by projecting the original feature into a hyperplane (higher-dimensional space) [27]. SVM is a non-parametric algorithm that recalls the training dataset for storing them all [28]. The SVM algorithm solves regression problems using linear functions, while in the case of non-linear regression problems, it maps the set of the input vector (a) to an n-dimensional space called a feature space (b) [13]. However, for multivariate training data (an) it is expressed in an N number of observations (bn), as a set of observed responses. The linear function can be shown as:

$$f \left( x \right) = x^{\iota } \beta + b.$$
(1)

The objective is to make it as flat as possible: \(f \left( x \right)\) with \(\beta^{\iota } \beta\) as minimal norm values, and as such the problem fits in the minimization function;

$$J\left( \beta \right) = \frac{1}{2} \beta^{\iota } \beta .$$
(2)

Therefore with a special condition of the values of all the residual not more than ε, as in the equation below:

$$\forall_{n} :\left| {y_{n} - \left( {x_{n}^{\iota } \beta + b} \right)} \right| \le \varepsilon .$$
(3)

K-Nearest Neighbor

K-nearest neighbor is one of the simplest supervised ML algorithms that relies on the hypothesis “things that look alike” [28, 29]. The algorithm is a non-parametric and supervised classifier used for the regression and classification tasks [15]. In both tasks, the input features consists of K closest training examples or the dataset in the feature space, while the algorithm relies on labeled data for the learning process to produce appropriate outputs for unlabeled input features. The idea behind the KNN algorithm is that if a sample has k most similar neighbors in the feature space, m13ost of the samples belong to a certain category, then the sample also belongs to this category [4, 30, 31]. The voting method is generally used in the classification task, that is, the category label that appears frequently in the k sample is selected as the prediction result, while in the case of the regression task, the average method is used where the real value output labels of the k sample are used as the prediction result [5, 31].

Random Forest

The random decision tree algorithm was proposed in 1995 by bell LABS Ho, which was advocated by aggregating many classifiers to improve the prediction accuracy. The idea behind the algorithm is to combine multiple decision tree classifiers, such as bagging and random space, to make predictions and get the final result by decision-making votes [4, 30]. Figure 2 shows the principle of filling the random forest.

Fig. 2
figure 2

Principle of filling random forest. The bootstrap resampling technique is firstly used where multiple samples are randomly selected from the original training dataset x to generate a new training dataset [32]. Then, multiple decision trees are built to form the random forest which then finally averages the output of each decision tree to determine the final filling result y [33].

Naive Bayes

Naïve Bayes is also a supervised ML algorithm based on the Bayes theorem. It learns by estimating the prior probability of each class using a training dataset [2]. The Bayes theorem is in the Eq. (4) below:

$$P \, \left( {A\left| B \right.} \right) = \frac{{P\left( {B\left| A \right.} \right)P\left( A \right)}}{P\left( B \right)}.$$
(4)

Gradient Boosting Algorithm

The gradient boosting algorithm combines a set of weaker learners to construct one strong learner. Unlike the bagging learning algorithm, where the models are made independently, gradient boosting makes its models sequentially by iteration to minimize the error of models learned earlier [34]. The gradient boosting algorithm learns a predictive model by combining M additive tree models (T0, T1, …, Tn) to predict the results as shown in the equation below:

$$f\left( x \right) = \mathop \sum \limits_{m = 0}^{m} f_{m} \left( x \right).$$
(5)

The ensemble model can be optimized by reducing the expected generalization error L as shown in the equation below:

$$L = \mathop \sum \limits_{i}^{n} \left( {y_{i} - \hat{y}_{i} } \right)2.$$
(6)

Logic Regression

The logic regression ML algorithm is an adaptive regression technique which constructs predicators as a Boolean combination of binary covariates [35]. The algorithm is used for a classification task with the aim of finding out a single Boolean expression that predicts a binary outcome. In the case of a regression task, many Boolean expressions can be investigated and simultaneously embedded into a liner regression model [36].

Evaluation Metrics

In this study, we used two evaluation techniques to determine the performance of each developed predictive learning model based on various supervised ML algorithms. These techniques include the following:

Accuracy is used to evaluate the supervised ML predictive models. The accuracy has the following definition:

$${\text{Accuracy}} = \frac{{\text{Number of correct predictions}}}{{\text{Total number of predictions }}}.$$
(7)

For binary predictive models, accuracy can be calculated in terms of positive and negative as follows:

$${\text{Accuracy }} = \frac{{{\text{tp}} + {\text{tn}}}}{{{\text{tp}} + {\text{tn}} + {\text{fn}} + {\text{fp}}}},$$
(8)

where tp is the true positive, tn is the true negative, and fp is the false positive, while fn is the false negative.

The receiver operating characteristic curve (ROC) is used to determine the diagnostic or predictive ability of the ML model as its discrimination threshold is varied. The curve is created by plotting the rate of true positive against the rate of false positive at various threshold settings. Figure 3 shows a typical ROC curve.

Fig. 3
figure 3

Typical ROC curve

Predictive Supervised Machine Learning Models

In this study, the predictive supervised ML model for diabetes type 2 was developed using a diagnostic dataset for DM type 2 patients. The dataset was collected at the Murtala Mohammed General Hospital Kano State in Nigeria and was used to develop predictive learning models. Table 2 shows the sample of the dataset. Figure 4 shows the work flow and how the models were developed.

Table 2 Sample of the dataset
Fig. 4
figure 4

Workflow of the predictive models

The dataset collected was preprocessed and prepared into a comma-separated values file (CSV) format. CSV uses a comma to separate values, where each line of the file is a data record called data instance. Each data instance consists of one or more fields called columns, separated by a comma. A field separator using commas is the source of the name of the CSV file format. The dataset has 363 instances (records) without a missing value. The dataset has two demographic attributes, which include age and family history, as well as clinical attributes including BP, glucose, CHOL, triglycerides, HDL, BMI, and the diagnostic result of the doctor which can be either positive or negative. Table 3 shows the data type of the dataset attribute.

Table 3 Data type of the dataset attributes

The Python programming language is used for the development of the learning predictive models. The Python programming language is an open source language and generally one of the most powerful and well-known dynamic programming languages used for development of predictive learning models and other data analysis tasks. In this study, the Python programming language has been used to develop the predictive supervised ML models for DM type 2 with a diagnostic dataset for DM type 2 patients. Figure 5 shows the description of the values of each attribute of the dataset, which includes the number of non-null observations, mean, standard deviation, the minimum value, 25% values, 50% values, 75% values, and the maximum value for each variable of the dataset.

Fig. 5
figure 5

Description of the values of the dataset attributes

In this study, the correlation coefficient analysis of the dataset attributes was also carried out. The correlation coefficient r is used to measure or determine the strength and direction of the linear relationship between two features or variables of the dataset on a scatterplot [37]. Figure 6 shows the scatterplot correlation coefficient of the attributes of the dataset, while Fig. 7 shows the correlation matrix which depicts the correlation coefficients between sets of variables.

Fig. 6
figure 6

Scatterplot correlation coefficient of the dataset attributes

Fig. 7
figure 7

The correlation matrix of the dataset attributes

In the correlation coefficient analysis, the value r is always a finite number between − 1 to + 1. As for the regression analysis, the correlation coefficient is used for modeling the association between the dependent variable and the independent variable. Table 4 shows the r value and the correlation coefficient status between the dependent variables and independent variables of the dataset used in this study.

Table 4 r value and correlation coefficient

The predictive supervised ML models for DM type 2 based on logistic regression, support vector machine, K-nearest neighbor, random forest, naive Bayes, and gradient booting algorithms were developed. The algorithms were directly applied on the dataset with the help of Python programming and its built-in libraries to develop the models. The accuracy and ROC performance evaluation of the predictive supervised ML models for DM type 2 was carried out. Table 5 shows the result of the performance evaluation of the models.

Table 5 Performance evaluation result of the model

Results and Discussion

In this study, predictive learning models for DM type 2 based on logistic regression, support vector machine, K-nearest neighbor, random forest, naive Bayes, and gradient booting algorithms were developed. The performance evaluation in terms of accuracy and receiver operating characteristic curve (ROC) of each developed model was determined. In terms of accuracy, the random forest predictive learning-based model happened to be the best model with an accuracy of 88.76%, followed by the gradient booting-based model with an accuracy of 86.76%, the support vector machine-based model with an accuracy of 85.29%, the K-nearest neighbor-based model with an accuracy of 82.35%, the logistic regression-based model with an accuracy of 80.88%, and lastly the naive Bayes-based model with an accuracy of 77.94%. However, in terms of the receiver operating characteristic curve, the random forest and gradient booting happened to be the best predictive models with an 86.28% predictive ability, respectively, followed by the support vector machine-based predictive model with 84.74%, the K-nearest neighbor-based predictive model with 81.94%, the logistic regression-based predictive model with 80.73%, and the naive Bayes-based predictive model with 77.73%. Figure 8 shows the results of the performance evaluation in terms of accuracy and ROC in each predictive model. Figure 9 shows the visualization of the random tree predictive model, which happened to be the best models in terms of accuracy and one of the best in terms of ROC.

Fig. 8
figure 8

Performance evaluation result of the predictive models

Fig. 9
figure 9

Visualization of the random tree predictive model

The predictive model in the figure shows that the glucose dataset attribute appeared to be the first splitting attribute and that the attribute is the most important for the diagnosis of DM type 2 in patients. This also corroborates the strong positive correlational coefficient relationship found between glucose attributes against the diagnosis result attribute of the dataset in the correlation coefficient analysis carried out earlier in the study. A set of rules that can be used for the diagnosis and prediction of DM type 2 can be extracted from the figure, which shows the visualization of the random tree predictive model. Below are the samples of the rules extracted from the predictive learning model:

  1. (i)

    If the glucose level of the patient is greater than 125 mg/dL and his/her blood pressure is between 129 and 225 mmHg, then the patient is diabetic.

  2. (ii)

    If the glucose level of the patient is less or equal to 125 mg/dL, his/her HDL is less than 53 mg/dL and his/her triglyceride is greater than 45 mg/dL, then the patient is diabetic.

  3. (iii)

    If the glucose level of the patient is less or equal to 125 mg/dL, his/her HDL is less than 53 mg/dL and his/her triglyceride is less than 45 mg/dL, and his blood pressure is less than 247 mmHg, then the patient is not diabetic.

Conclusion

In the present study, predictive learning models for DM type 2 based on logistic regression, support vector machine, K-nearest neighbor, random forest, naive Bayes, and gradient booting algorithms were developed. However, the random forest predictive learning-based model was found to be the best model among the developed models with 88.76% in terms of accuracy, while in terms of the receiver operating characteristic curve, random forest and gradient booting appeared to be the best predictive learning models with 86.28%, respectively. The model will help health workers and medical personnel when diagnosing and predicting DM type 2 among those patients suspected to have diabetes mellitus.