## 4 Methodology
### Repeat steps (b) and (c) until convergence. The BoF model vocabulary set \(\mu_{1}^{v}\) with \(v\) ranges from \([1\ K]\), with a total of \(K\) cluster centers used to create a final feature vector associated with each RP of the known training and the required test data. The final training data \(T\) consisting of the final feature \(\tilde{Y}\) and location labels \(X\) is used to estimate the location based on the test RSS value at an unknown location of the serving region. In Equation (9), the final feature vector \(\tilde{Y}\) from the raw RSS data \(Y\) is calculated for each reference point based on the available vocabulary set \(\mu_{i}^{v}\). The mathematical form is given by  
\[\tilde{Y}_{i}=\Big{\{}\big{\{}\psi_{i,j}-\mu_{i}^{v}\big{\}}_{v=1}^{K}\Big{\}} _{i=1}^{M}. \tag{9}\]  
The training data consisting of the final feature vector and its associated labels \(<\tilde{Y},X>\) is used to train the classifier to estimate location coordinates based on the test data. The BoF model extracts the feature vector from the raw data, which remain robust and distinct in the presence of both spatial and spectral noise. The test feature vectors are classified with a trained classifier, and the estimated location is compared with the true location to calculate mean indoor positioning error. The test features of the BoF models are classified with the distance-based classifier. Using KNN classification provides better precision when integrated with the proposed BoF model. The KNN method identifies the K nearest feature vectors in \(\tilde{Y}\) with the lowest Euclidean distance \(d\) to the existing training features. For a test feature \(\xi\) in \(R^{M}\) vector space, the Euclidean distance is shown in Equation (10). \[d_{i}=\sqrt{(\xi_{j}-\psi_{i,j})^{2}} \tag{10}\]  
where \(d_{i}\) in Equation (10) represents the distance of test feature \(\xi\) and \(i\)th feature vector \(\tilde{Y}\) from the training data. The test \(\xi\) is assigned to the majority vote of the k-nearest features of the training data \(N_{k}(\tilde{Y})\) shown in Equation (11). The \(N_{k}(\tilde{Y})\) are the \(k\)-nearest features of the test feature \(\xi\) in the training set \(\tilde{Y}\)). The optimal value of k in the KNN algorithm is used differently in the literature [39; 40]. Usually, the value of K is between 3 and 5; for larger values the accuracy of the system degrades, as outliers are also included as neighbors. Fractional probability \(p\) is used to assign class label \(X\) to test feature \(\xi\). \[p(X_{i}/\xi)=\frac{1}{k}(\sum_{i\in N_{k}(\tilde{Y})}I(X==i)) \tag{11}\]  
The class label, i.e., the RP coordinates, is assigned to test feature \(\xi\) on the basis of the fractional probability given in Equation (11). The class label for which \(p(X_{i}/\xi)\) results in a maximum value is assigned to each test feature during the experiment. The KNN classification model is less complex; hence, it is integrated with the proposed pre-processing approach. The step-by-step functionality of the proposed approach can also be shown in Algorithm 1 and Figure 3.  
``` Input : Raw RSSI fingerprint \(Y\) and the respective label coordinates \(X\) given in Equation (7) and Equation (6), respectively. Output : Final feature vector \(\tilde{Y}\) given in Equation (9). Initialization: The parameter cluster center \(K\). 1 Calculate the \(k\) vocabulary set \(\mu_{j}^{k}\) using Equation (8). 2 Calculate training features \(\tilde{Y}\) using the vocabulary set \(\mu_{j}^{k}\) using Equation (9). 3 Train KNN classifier with the train data consisting of training features \(\tilde{Y}\) and their respective label coordinates \(X\). 4 for each test finger print \(\psi\)do
5 Calculate final test BoF feature \(\xi\) using the vocabulary set \(\mu_{j}^{k}\) of Equation (9). 6 Find the Euclidean distance of the test feature \(\xi\) and the training feature set \(\psi\) using Equation (10). 7 Calculate the fractional probability given in Equation (11). 8 Assign the largest fractional probability class label as indoor position location.