## 3 Proposed System
### ML for Devices Classification  
As stated before, sensor devices identification is performed by means of a ML approach that exploits multiple PHY-parameters of their unique propagation channel. In particular, we resort here to a non-parametric classification approach, so not depending on information from a certain sort of distribution that is difficult to achieve in dynamic environments. Moreover, this method is suitable for a low-cost/low-consumption WSN. In particular, two different algorithms are investigated. First, a CART algorithm is used [37]. This is a supervised ML algorithm that generates a decision tree in order to solve a classification or a regression problem. Because of their readability and simplicity, decision trees are among the most popular machine learning methods. In particular, the CART algorithm is well suited in the case of high-dimensional data; it contains the criteria for choosing the best attribute for the data splitting and assigning a class to the leaf. Then input data are classified based on their attributes through logical _\"if-then\"_ statements. More in detail, during the _training phase_, the CART algorithm builds the decision tree using a dataset containing samples of signals received by the \(N\) sensor nodes. Figure 3: Confusion matrix. assume that data are characterized by \(K\) attributes \(\mathcal{A}=a_{1},\cdots,a_{K}\), and let us consider the Shannon's entropy of a dataset \(\mathcal{D}\), that is  
\[\mathbf{H}(\mathcal{D})=-\sum_{n=1}^{N}p_{n}\log_{2}p_{n} \tag{4}\]  
where \(p_{n}=|\mathcal{D}(n)|/|\mathcal{D}|\) is the ratio between the number of elements of \(\mathcal{D}\) belonging to the \(n\)-th class, \(\mathcal{D}(n)\), and the total number of elements in \(\mathcal{D}\) (i.e., the operator \(|\cdot|\) represents the cardinality of the set). To build the decision tree, the CART algorithm at each step performs the split of a dataset \(\mathcal{D}\) in two disjoint datasets \(\mathcal{D}_{1/2}\), using the _information gain_ as the metric to select the best attribute for the splitting. The _information gain_ of the splitting of the dataset \(\mathcal{D}\) based on the attribute \(a_{i}\), \(I_{gain}(\mathcal{D},a_{i})\) is defined as the difference between the entropy value of the original dataset, \(H(\mathcal{D})\) and the sum of the entropy of the two subsets generated by performing the split based on the attribute \(a_{i}\) with \(i=1\cdots,K\) as  
\[I_{gain}(\mathcal{D},a_{i})=H(\mathcal{D})-R(\mathcal{D},a_{i}) \tag{5}\]  
where \(R(\mathcal{D},a_{i})=H(\mathcal{D}_{1}(a_{i}))+H(\mathcal{D}_{2}(a_{i}))\) and \(H(\mathcal{D}_{1/2}(a_{i})\) is the entropy of the dataset \(\mathcal{D}_{1/2}\) obtained using the attribute \(a_{i}\). Hence, the best attribute \(\hat{a}\) for performing the split is selected as  
\[\hat{a}=\max_{a_{1},\cdots,a_{K}}I_{gain}(\mathcal{D},a_{i}) \tag{6}\]  
The algorithm is iterative: initially, the whole training dataset is considered (tree root), and at the first step, this is split in two disjoint datasets (using the best attribute), then the two generated datasets are in turn split, each one into two datasets (using the best attribute for each split), and so on until one of the following conditions is reached:  
1. The maximum number of split has been performed (it is set as a parameter);
2. One leaf is \"pure\", that is, all input data in the leaf belong to the same class;
3. One leaf contains only one input sample. Fixing the maximum number of splits limits the dimension of the tree and, hence, the test complexity as detailed later. Moreover, having a tree with limited dimension avoids also overfitting problems that can arise, having leaves with a few sample data. During the _classification_ phase, the received signal samples are moved in the decision tree from the root down to the leaf that represents the most suitable class for those samples. In particular, input data are compared with the attribute selected at each node of the tree and moved in the corresponding branch.