# PISIoT: A Machine Learning and IoT-Based Smart Health Platform for Overweight and Obesity Control
## Materials and Methods
### PISIoT: Architecture and Functionality
#### 3.2.2 Data Analysis Layer  
This layer identifies critical variables and classifies patients according to their level of obesity through Weka API based on version 3.8 of Java, since this is the latest stable version and is open-source software that is easy to integrate with PISIoT and meets the required functionality parameters. In addition, to perform the BMI classification, identify critical variables, and generate medical recommendations, PISIoT uses the machine learning algorithm J48, which is an open-source implementation in Java of the C4.5 algorithm. This means that both C4.5 and J48 are classification algorithms used to generate decision trees. The classification algorithms are useful for the diagnosis of hepatitis [48], cancer of the biliary tract [49], and lung cancer [50]; support vector machines used for the prediction of cancer growth [51] and stage I ovarian cancer [52]; for the prediction of cardiac diseases [53] and classification of eye disease [54]; to differentiate malignant, benign, and advanced pulmonary nodules [55]; and in the classification of tumors in digital mammograms [56] and diagnosis of pancreatic cancer [57]. In addition, J48 was selected because it has been used to build predictive models in similar classification problems and has shown better performance than other algorithms. For instance, in [58], J48 produced meaningful and useful predictions with better performance (larger area under the curve) than other decision tree algorithms like random forest and CART (classification and regression tree) models. Moreover, in [59], a J48 decision tree was used to classify users into different categories, and experimental results showed that the J48 decision tree classifier has higher accuracy and a lower response time in determining the category of a user compared to other classification algorithms like REPTree, fuzzy C-means, and random tree. By contrast, PISIoT was developed and implemented modularly and generically, with a view to high performance, ease of implementation,and better extensibility of the application. Figure 2 presents the four classes developed for the machine learning module. 1. ClsModel.java serves primarily to generate the model from the training set. In addition, it contains two methods, one to receive the data set and another to generate the model based on the data set received. The class starts with an instance of the \"Instances\" type called \"train\". Likewise, the ClsModel constructor is sent, which, through the generateModel method, indicates the destination and the algorithm used. In addition, the searchAlgorithm method is invoked. 2. InstanceAlgorithm.java contains the selection of the algorithm to be used. The method search Algorithm receives the algorithm selection and the model path. 3. Clsalgorithms.java processes the data set, the model, and the incoming information to apply the corresponding algorithm, in addition to providing a timely response to the request. This class starts with a classifier of the \"Classifier\" type, train of the \"Instances\" type, and data object of the \"Instances\" type. In addition, it uses the applyInstance method to apply the changes made and designate the information to be analyzed. The ClsAlgorithms method also receives the model, the data set, and the algorithm to process the information and generate a response. 4. ClsInstanceWeka.java generates an instance based on incoming information; this class is responsible for selecting the set of parameters to be processed. The CreateInstance method uses the Instances object and the number of elements contained in the data set, ignoring the class label. To carry out the recommendations, the daily values and the weekly averages of each variable are considered. This makes it possible to establish the rules (maximum and minimum values allowed per variable) in the algorithm. Therefore, each day, the patient is classified based on BMI as normal, overweight, obese 1, obese 2 or obese 3.