# Adaptive Method for Packet Loss Types in IoT: An Naive Bayes Distinguisher
## 4 NB-TCP Algorithm  
Classification problem is one of the most widely studied and applied problems in the field of data mining. Naive Bayesian Model has become one of the classic models in the classification field due to the firm and rigorous mathematical theory foundation [31]. Based on [PERSON] theorem, it is assumed that the influence of each feature value on a given class is independent of each other, and the classification results are identified by combining known prior probability and conditional probability. Compared with other classification methods (e.g. support vector machine (SVM), decision tree algorithm), this method is simple and easy to understand. It can be effectively applied to the receiver to collect information and analyze. Not only will this not cause too much load on the network, but it also has fast classification speed, high accuracy, stable classification efficiency, insensitivity to missing data, and can quickly and effectively obtain classification results. Suppose the sample set is A, the sample  
that is, A\({}_{n}\) is classified into the class with the greatest posterior probability. Base on Equations (3), (4) and (9), an improvement congestion control algorithm called NB-Bayes is developed by Algorithms 1 and 2. There are two components of the improved algorithm, which are the ends of the TCP connection (e.g., TCP sender and TCP receiver). NB-TCP modify Newreno to distinguish congestion losses and wireless random losses, which performs the main classification work at the receiver. When the TCP receiver detects the packet loss, it calculates the feature value \(a_{pri}\) and \(a_{RPTI}\) according to Equations (1) and (2) respectively as an unclassified samples. The classification model is established using training samples during the training process. It obtains the category prior probability value and the category conditional probability value of feature attributes from training samples, which will be a time-consuming job. The training process is done before the whole classification process. In the classification process, the model can be used directly to predicate the category of unclassified samples based on Equation (9), therefor the classification speed is negligible. If the classifying result is wireless random loss, the ELN bit of the ACK packet will be marked, which will be returned to TCP sender when packet loss occurs, whatever the reason. ```
1:if packet loss then
2: Obtain \(a_{pri}\) and \(a_{RPTI}\) as a sample;
3: Classifying the sample by the learned model and assign the result to \(C\);
4:if\(C\) is wireless random loss then
5: Set \(ELN\)=1 in the ACK packet;
6:endif
7: Sent ACK packet;
8:endif
```  
**Algorithm 1** NB-TCP Algorithm at TCP Receiver. ```
1:if receive the 3 rd duplicate ACK then
2:if\(ELN==1\)then
3: Wireless random loss and with no action;
4:else
5: Congestion loss;
6:\(cwnd\)=\(cwnd/2\);
7: As NewReno;
8:endif
9:endif
```  
**Algorithm 2** NB-TCP Algorithm at TCP Sender. If TCP sender detects the third duplicate ACKs with unmarked tag ELN, it means that network congestion and will take congestion control actions. If the value of ELN is 1, that is wireless random loss, sender will not halving the congestion window and retransmit the packet. This kind of processing will largely avoid the unnecessary operation of halving the slow start threshold and reducing the congestion window during fast retransmission, and shield the sender from packet loss in the wireless link, thus improving the performance of TCP protocol. The accuracy of the classification model mainly depends on the priority feature and the RPTI feature. Traffic patterns in the IoT network may change, but the classification model is robust to adaptation. This is because that feature values are not affected by traffic patterns. The detailed reasons are listed as follows. The priority feature relies on the distribution of different priority packets at receiver to get the value. Traffic patterns dose not affect the drop rule so that it dose not affect the value.