# Application of Deep Convolutional Neural Networks and Smartphone Sensors for Indoor Localization
## 4 Experiment and Results
### Performance of Indoor Localization  
This section contains the results for indoor localization using the proposed mKNN approach. The performance of mKNN is compared with KNN for localization. The localization process involves three steps: Indoor scene recognition, magnetic database search space narrowing, and localization. Indoor scene recognition is performed with the trained CNN classifier as described in Section 4.2. The recognized scene is then used to load the magnetic database of the recognized floor and narrow down the search space. It divides the magnetic database into a sub-database where only the recognized scene area is searched for the possible match(es) between the user magnetic sample and magnetic database. KNN involves the matching of a sample against the database and finding \(K\) number of candidates which have the lowest error. The selected \(K\) candidates are later used to calculate the centroid which serves as the predicted location of the user. We followed the same process for our mKNN as explained in Algorithm 1; however, we used the concept of 'weight' which is calculated using the error of each candidate as well as its minimum spatial distance to its neighbors. It helps to mitigate higher errors. \begin{table}
\begin{tabular}{c c c} \hline
**Class** & **CNN Accuracy** & **SVM Accuracy** \\ \hline
0 & 0.942 & 0.890 \\
1 & 0.925 & 0.880 \\
2 & 0.920 & 0.800 \\
3 & 0.912 & 0.880 \\
4 & 0.887 & 0.740 \\
5 & 0.854 & 0.710 \\
6 & 0.953 & 0.910 \\
7 & 0.924 & 0.880 \\
8 & 0.957 & 0.899 \\
9 & 0.870 & 0.760 \\
10 & 0.901 & 0.843 \\
11 & 0.890 & 0.820 \\
12 & 0.882 & 0.810 \\
13 & 0.928 & 0.846 \\
14 & 0.913 & 0.808 \\ Average 0.9104 & 0.8317 & \\ \hline \end{tabular}
\end{table} 
Table 1: Accuracy statistics for CNN and support vector machines (SVM). Figure 9: Accuracy and loss of convolutional neural network (CNN) classifier for training. We take user captured images from his smartphone and later same procedure is used to predict his location with KNN and mKNN. The value of \(K\) is same for KNN and mKNN which is 7. However, for mKNN, we initially set \(K\) to 11 and then select 7 candidates based on their calculated weights. The localization is performed on three floors and Figure 10 shows the results for KNN and mKNN. Table 2 displays the statistics for KNN and mKNN to show their localization performance. The results shown in Figure 10 demonstrate that the proposed mKNN performs better than that of KNN to locate a person indoor. The results are better for both Galaxy S8 and LG G6. Another noteworthy point is the analogous performance by Galaxy S8 and LG G6. The use of magnetic patterns over magnetic intensity helps to mitigate the device dependence. While the magnetic database is built using Galaxy S8, yet, the localization performance of LG G6 is very similar to Galaxy S8. The lower errors are on account of scene recognition and magnetic pattern matching. We can see that the results for MFS-S8 with scene information are higher than those of pattern matching. When different smartphones are used the magnetic data intensity is different owing to the sensitivity of the installed magnetometer of the smartphone. However, the patterns formed by magnetic intensity of these smartphones are very much similar. Scene recognition shrinks the magnetic database and thus reduces the localization error. If the scene information is not used for localization, the errors are very high as shown in Figure 10. Similarly the mean, 50% and 75% errors are very high when MFS is used without scene recognition using different devices. Additionally, since the database is built using Galaxy S8, the maximum as well mean errors are higher for LG G6 using MFP without scene information. Table 2 shows that the mean error with KNN is 1.86 m and 1.40 m for LG G6 and Galaxy S8 smartphones, respectively.