Activity recognition on smartphones using an AKNN based support vectors

Purpose – Mobile phone-based human activity recognition (HAR) consists of inferring user ’ s activity type from the analysis of the inertial mobile sensor data. This paper aims to mainly introduce a new classi ﬁ cation approach called adaptive k-nearest neighbors (AKNN) for intelligent HAR using smartphone inertial sensors with a potential real-time implementation on smartphone platform. Design/methodology/approach – The proposed method puts forward several modi ﬁ cation on AKNN baseline by using kernel discriminant analysis for feature reduction and hybridizing weighted support vector machines and KNN to tackle imbalanced class data set. Findings – Extensive experiments on a ﬁ ve large scale daily activity recognition data set have been performed to demonstrate the effectiveness of the method in terms of error rate, recall, precision, F1-score and computational/memory resources, with several comparison with state-of-the art methods and other hybridization modes. The results showed that the proposed method can achieve more than 50% improvement in error rate metric and up to 5.6% in F1-score. The training phase is also shown to be reduced by a factor of six compared to baseline, which provides solid assets for smartphone implementation. Practical implications – This work builds a bridge to already growing work in machine learning related to learning with small data set. Besides, the availability of systems that are able to perform on ﬂ ight activity recognition on smartphone will have a signi ﬁ cant impact in the ﬁ eld of pervasive health care, supporting a variety of practical applications such as elderly care, ambient assisted living and remote monitoring. Originality/value – The purpose of this study is to build and test an accurate of ﬂ ine model by using only a compact training data that can reduce the computational and memory complexity of the system. This provides grounds for developing new innovative hybridization modes in the context of daily activity recognition and smartphone-based implementation. This study demonstrates that the new AKNN is able to classify the data without any training step because it does not use any model for ﬁ tting and only uses memory resources to store the corresponding support vectors.


Introduction
Automatic human activity recognition (HAR) systems aim to capture the state of the user and its environment by exploiting heterogeneous sensors that are either attached to the subject's body or placed at fixed locations in the environment, which enables continuous monitoring of numerous physiological signals.Equipped with a rich set of sensors and becoming an integral part of our daily life, smartphones are explored as an alternative platform to infer activities of the users (Voicu et al., 2019;Yuan et al., 2019).For instance, motion-related sensors, such as accelerometer and gyroscope, have been widely used in activity recognition systems as a wearable sensor The current issue and full text archive of this journal is available on Emerald Insight at: https://www.emerald.com/insight/0260-2288.htm (Horn et al., 2016;Randhawa et al., 2020) as well as identifying user's behavior through series of observations (Shoaib et al., 2014).These activities range from simple full body motor activities such as walking, running and sitting to complex functional activities such as reading a book, playing a soccer and cooking a homemade dish.This can be immensely useful in health-care applications (Horn et al., 2016;Minetto, 2015;Ray et al., 2019) such as eHealth monitoring, fall detection as well as context-aware mobile applications, human survey system, home automation.Besides, the performance of such activities can be important indicators for designing and reshaping ingredients of the future aging society (Chen and Shen, 2017) where the existence of, e.g.reliable warning systems for accident occurrence such as falling down, can be crucial to save individual lives and seek cost-cutting solutions.It is therefore envisaged that such devices can seamlessly monitor and keep track of our daily activities, learnt from sensory analysis and assist regulators in their short-, mediumand long-term decisions.
Due to their mobility, battery performance, relatively low computational and memory costs and real-time implementation prospects, smartphone-based HAR offers an edge in future health-care systems.Roughly speaking, HAR involves a combination of sensor networks hand-in-hand with the data mining and machine learning (ML) approaches (Pei et al., 2012;Randhawa et al., 2020).In this context, a basic procedure for mobile activity recognition encompasses a data collection task from users that perform sample activities to be recognized, a classification model generation by using these collected data to train and test the suggested classification algorithms and a model deployment stage where the learnt model is used to assign a class label to a given action or activity.The overall process of smartphone-based HAR system is shown in Figure 1.
Sensor data can be processed either in real-time (Kose et al., 2012) or logged for offline analysis and evaluation.The model generation is usually conducted offline where the model is built and fine-tuned with optimal parameters on a server system and later transferred to the phone to infer the user's activities according to these observations.Offline processing can be used for applications where online recognition is not necessary.For instance, if we are interested in monitoring the daily routine of a person, the sensors can collect the data during a day; the data will then be uploaded to a server at the end of the day, which, in turn, will be processed offline for classification purposes.While online processing is found useful in fitness-coach like application where the user is given a program with a set of activities, their duration and sequence of use and the interest is shifted toward what the user is currently doing.Likewise, in participatorysensing applications, online processing arises when one might be interested in collecting information from users that are currently "walking" in a particular part of a city.
On the other hand, surveying the literature about smartphone inertial sensor-based activity recognition (Straczkiewicz et al., 2021) revealed the overwhelmed majority of these studies adopted a two-phases strategy.In the first phase, a large-scale training is performed offline to learn model's parameters, followed by an online testing phase, which is embedded in smartphone memory resources.Besides, there is a strong consensus in this community that HAR training phase is typically very costly in terms of memory and computational resources as well as being impacted by the class-imbalance (because data set is not evenly distributed among various classes).Therefore, there is a general interest in providing activity recognition systems that overcome the class-imbalance dilemma and reduce the amount of training resources to enable its deployment into smartphone platform.This partly motivates the work undertaken in this paper where an adaptive k-nearest neighbors (AKNN) is put forward.More specifically, the paper advocates fourfold contributions: We performed a concise review of the main works in HAR field with a focus on comparative results reported by the studies as well as the prospect of ensemble-classifier like approach.
We developed a new AKNN approach that accommodates smartphone-based implementation and hybridizes two ML methods.In essence, the developed AKNN approach is inferred from a novel weighted support vector machines (WSVM) issued from the application of kernel discriminant analysis (KDA) for the dimensional reduction prior to use of WSVM, while providing some adaptive scheme to KNN according to the extracted support vectors (SVs).This resulted in a light training scheme that can easily be accommodated to smartphone platform requirements and overcame class-imbalance.
We provided a sound algorithmic implementation of the developed AKNN and conducted a qualitative comparison with conventional KNN algorithm.
We provided an extensive quantitative evaluation of the proposal using five publicly data set, namely, HAR (Anguita et al., 2013), HAPT (Reyes-Ortiz et al., 2016), sensors activity recognition (SAR) (Shoaib et al., 2014), Wireless Sensor Data Mining (WISDM) (Kwapisz et al., 2011) and UniMiB SHAR (Micucci et al., 2017).The proposed AKNN approach is shown to outperform all the reviewed state-of-the-art approaches in the field with an important margin.
The remainder of this paper is organized as follows.Section 2 summarizes the related research in the past ten years.Section 3 introduces our automatic activity recognition approach and provides a comparison between KNN and the proposed method.The experimental validation of the proposed approach is given in Section 4 where the details of the publicly available activity recognition data set used in this work are also described in this section.Finally, Section 5 concludes the paper.

State of the art and related work
HAR has received a substantial interest recently.Currently, although there is a good prospect for collecting data with such smart devices, there is a limited capability in terms of automatic decision support capability and making sense out of this large data repository.There is an urgent need for new data mining and ML techniques to be developed to this end, such as SVM (Anguita et al., 2012), J48 (Kwapisz et al., 2011), logistic regression (Kwapisz et al., 2011), multilayer perceptron (Kwapisz et al., 2011), decision tree (Fan et al., 2013), hidden Markov model (HMM) (Lee and Cho, 2016), Long short-term memory (LSTM) recurrent neural networks (Ord oñez and Roggen, 2016), random forest (NJ and Kavitha, 2017), KNN (Mandong and Munir, 2018), artificial neural networks (ANN) (Suto and Oniga, 2018), bagging (Wu et al., 2019), boosting algorithm (Wu et al., 2019), convolutional neural networks (CNN) (Wu et al., 2019) and improved LSTM networks (Wan et al., 2020).Table 1 reports the comparison of different classification methods in the same framework when dealing with HAR (in Table 1, a > b means using classifier a resulted in a higher accuracy than classifier b).
Recently, several authors have demonstrated that two classifiers can be combined in different ways to improve the recognition performance in HAR tasks.For example, Ord oñez et al. (2012) showed that an ANN could be combined with HMMs to deal with activity recognition problems.Lester et al. (2006) developed a hybrid model that combined a modified version of AdaBoost with HMMs and demonstrated its effectiveness for recognizing various human activities using the embedded wearable devices.Anguita et al. (2012) proposed the multi-class SVM approach (MC-SVM), where the One-Vs-All approach is advocated because of its memory optimization compared to the One-Vs-One method.They have also introduced in Anguita et al. (2012), the concept of a multi-class hardware-friendly SVM (MC-HF-SVM) approach.This method was designed for binary classification problems by using a fixed-point arithmetic in the feed-forward phase of the SVM classifier, with the purpose of allowing its use for batteryconstrained devices.However, such classifiers are not able to effectively distinguish very similar activities, such as going upstairs and going downstairs.Menhour et al. (2018) developed new schemes named principal component analysis (PCA)/KNN-SVM and linear discriminant analysis (LDA)/ KNN-SVM, and they have demonstrated that LDA can outperform the traditional PCA for maximum discrimination between classes.A new approach for improving daily activity recognition combined with PCA, LDA and weighted-SVM (WSVM) has been addressed in Abidine et al. (2018) to overcome the problems of non-informative sequence features and class imbalance.The same authors have proposed in Abidine et al. (2019), an efficient classification model for physical activity recognition based on k-means clustering and SVM-HMM hybrid classification approach that uses labels outputting of SVM in HMM.
In the next section, we will present the principle of the proposed method called Adapted KNN (AKNN) approach.It allows a good representation and reduction of training set by using only the SVs.

Proposed adaptive k-nearest neighbors-based support vector
Our proposed approach has been motivated primarily by our desire to leverage the effects of imbalanced training data set, which is quite common in HAR problems where some activities are rather marginal, to very rare, with respect to other activities.For this purpose, in light of previous research in Abidine et al. (2018), Abidine et al. (2019), one may reasonably question the effectiveness of the WSVM, which has been widely populated in this field as well as KNN-based approach.Traditionally, WSVM has been applied to investigate the effect of overweighting the minority class on SVM modeling between the performed activities and deals with a "class-imbalance problem" (Fang et al., 2014).However, its high computational cost cannot be ignored neither.Observing that the high dimensional data, which is prevalent in HDR tasks, would rather make the handling of the imbalanced training data set possibly biased.Therefore, a cornerstone idea in our approach is to apply a dimensional reduction approach based on KDA prior to use of WSVM and providing some adaptive scheme to KNN according to the extracted support vector, which yields the new AKNN.The detailed architecture is highlighted in Figure 2.
Sensor data for different activities has been collected and stored using smartphone inertial sensors.Data has also been divided into two partitions: training-set and test-set.First, we reduce the number of features using KDA method using labeled data set to obtain the best discrimination between the classes in the new feature space.This is motivated by the fact that KDA has been shown to be more effective than the LDA due to separability criteria between classes in a highdimensional implicit feature space (Kung, 2014), where the data are linearly separable.Second, we train the WSVM on the KDA features to generate the SVs that determine the boundary of activity data.The extracted SV that creates the new reduced balanced training data makes the classification process less complex.The ultimate classifier is performed by the Adapted KNN algorithm using the k samples limited only within the SVs such that when a new sample appears, it will be classified to its most similar class.An estimated label vector is generated by the AKNN classifier, and the system will output the recognized activity.These steps are briefly visualized in Figure 2. The following subsections will discuss in detail each step of the proposed approach.

Kernel discriminant analysis
To extract the nonlinear discriminant features, KDA (Tian et al., 2019), a non-linear discriminating method based on kernel trick (Kung, 2014), was developed.By introducing a kernel function which corresponds to the non-linear mapping U, all the computation can conveniently be carried out in the input space, see Figure 3 for a graphical illustration of the approach.More formally, the mapping is defined in the feature space (F) as: To get a nonlinear form of LDA, we simply apply a nonlinear kernel that should be symmetric positive-definite (Kung, 2014) as below: Where hu; vi represents the dot product in the Hilbert space u,v[ F Let S f B and S f w denote the in-between-class scatter matrix and the within-class scatter matrix in the feature space, respectively.In this new feature space, the objective function that needs to be maximized is as follows: (5)

Weighted support vector machines training
Although SVMs often produce effective solution for balanced data sets, they are sensitive to the imbalance data sets which may yield a suboptimal model.The basic idea of weighted support vector training (WSVM) (Dzulkifli et al., 2019) is to handle the imbalance problem by assigning each data point a different weight assigning two misclassification costs C À and C 1 in the primal Lagrangian in the objective function [equation ( 6)] for the minority (y i =À1) and majority classes (y i = 11) by minimizing the following: Where f is a nonlinear mapping and m 1 (resp.m À ) are the number of positive (resp.negative) instances in the initial database (m À 1 m 1 = m).This is a nonlinear extension with a property of maximizing the margin between two classes.
The dual optimization problem of WSVM with different constraints on a i can be solved similarly to Fern andez Hilario et al. (2018).The result of the above problem is solving the maximum of the following function: Where a 1 i and a À i represent the Lagrangian multipliers of positive and negative instances, respectively.The corresponding data points are called SV.
If the training data gets more imbalanced, the ratio between the positive and negative SVs also becomes more imbalanced.Some authors (Abidine et al., 2018;Fern andez Hilario et al., 2018;Yang et al., 2007), have proposed adjusting different cost parameters to solve the imbalanced problem.They put forward the corresponding solutions to deal with this problem in the SVM algorithm: One way to deal with this problem is to increase the tradeoff C 1 associated with the positive instances as in (Abidine et al., 2018) where different misclassification C i per class were used to solve this problem.Especially, by taking C -=C i and C 1 = C, where m 1 and m i stand for the number of samples of majority classes and the number of samples in the i th class, respectively.The main ratio cost value C i for each activity can be obtained using: Where C is the common cost parameter of the WSVM.

An adaptive K-nearest neighbors classification using support vector
The K-nearest neighbor algorithm is amongst the simplest of all ML algorithms (Lu et al., 2018), and therefore easy to be implemented.The m training instances x[ R n are vectors in an n-dimensional feature space, each with a class label.In the KNN method, the result of a new query is classified based on the majority of the KNN category.This rule is usually called "voting KNN rule."Such a classifier relies only on storage of feature vectors and class labels of the training instances whereas no model fitting is applied.They work based on the minimum distance (or similarity) from an unlabeled vector (a test point) to the training instances to determine the K-nearest neighbors.K (positive integer) is a user-defined constant.Usually Euclidean distance is used as the distance metric between x and the neighbor training x i represented by: One of the many issues that affect the performance of the KNN algorithm is the approach to combine the class labels.The simplest method is to take the majority vote, but this can generate a problem if the nearest neighbors vary widely in their distances.The intuition behind adaptive KNN is to calculate the contribution of k nearest neighbors, and to give more interest to the points which are nearby and less interest to those points which are farther away.Consequently, we start finding the k neighbors that have the smallest distances to the test data.
In the second phase, we compute the contribution of each k nearest neighbors based on KNN algorithm by computing the adaptive distance (d a ) from observation of different categories.
Finally, we set the classification results according to the distance values of various categories, where the distance (d a ) is higher in the decision when the existing observations (training set) are close to the new observation.We proposed in this paper the inverse of Euclidean distance as the adaptive distance d a as follows.The prediction of the class for new test data (x) is computed by using different (d a ) for each nearest neighbor (NN) labeled (y NNi ), with q as the total number of NN as follows: Instance x is assigned to the class y NNi for which the adaptive distances of the representatives among the k nearest neighbors sum to the greatest value.More formally: We label the data in the related window as the activity for which we have the maximum amount of data in the final K set.For instance, if K is 10 and the final list is "1 1 5 3" (1 vote for running, 1 vote for walking, 5 votes for sitting and 3 votes for standing) for the average feature, then the activity is labeled as sitting according to the average feature.We show in Figure 4, the concept of Adaptive KNN using the balanced data set extracted from the SV.The training data has been significantly reduced by using the WSVM learning to deal with the imbalanced problem.The labeled SVs have become the new nearest neighbors.According to the proposed idea, the corresponding algorithm can be summarized by the pseudo-code described in Pseudo-code summarizing the proposed activity recognition approach.
Algorithm : Adaptive KNN (AKNN) Procedure: Find class labels corresponding to activity classes Require  12 Predict Y AKNN the class label of observation x //Equation ( 14) 13 Return the activity classes C i , with i = 1. ..N

End
To illustrate the merits of the proposed concept, we summarized in Table 2 the advantages and disadvantages of the KNN compared to our introduced AKNN.

Experiment results
Our experiment used mainly some publicly available data set to examine the performance of our method.In this section, we start by describing the data set used in these experimental procedures, the learning algorithm implemented, the attribute extraction technique used to validate the construction of new features and the evaluation results.Nevertheless, our study skips data collection and preprocessing steps on purpose because we want to improve the HAR by providing better feature extraction and classification scheme.

Data sets
Publicly available and annotated data sets for activity recognition (Anguita et al., 2013;Kwapisz et al., 2011;Reyes-Ortiz et al., 2016;Shoaib et al., 2014, andMicucci et al., 2017) have been conducted to evaluate the performance of the proposed approach.We used four different data sets, using different physical activities (locomotion: walking, running, walking upstairs, walking downstairs), (postures: laying, sitting and standing) and (transitions: sit-to-stand, stand-to-sit).These data sets vary in their formats, type of sensors they are generated from and sampling frequencies.The data collection task was performed on an Android Samsung Galaxy SII phone.The first used data set is named Human Activity Recognition Dataset (HAR).The second data set (HAPT) with postural transitions is quite similar to the previous one, but it includes postural transitions such as sit to stand.The third data set is known as the SAR.The fourth data set is the data set created by the WISDM laboratory.Finally, the last data set, named University of Milano Bicocca Smartphone-based HAR (UniMiB SHAR), is grouped into two coarse grained classes: one containing the activities of daily living (ADL) and the other containing the types of falls (Figure 5).Some of these data sets included tri-axis angular   3.
In contrast to other data sets, UniMib SHAR data set includes both ADL and Fall activities described in Figure 5. ADL consists nine activities: from standing to lying on a bed (LyingDownFS), from laying on the bed to standing (StandingUpFL), from standing to sitting on a chair (StandingUpFS), from standing to sitting on a chair (SittingDown), climb the stairs moderately (GoingDownS), down the stairs moderately (GoingUpS), normal walking (Walking), continuous jumping (Jumping), moderate running (Running).There are also 8 Fall scenarios: Generic fall backward from standing (FallingBack), Fall backward while trying to sit on a chair (FallingBackSC), Falls using compensation strategies to prevent the impact (FallingWithPS), Fall forward from standing, use of hands to dampen fall (FallingForw), Fall right from standing (FallingLeft), Fall right from standing (FallingRight), Falls with contact to an obstacle before hitting the ground (HittingObstacle), Getting unconscious (Syncope).
The number of observations of each activity in each data set is shown in Table 4.This enables us to visualize the disparity between activities in terms of number of observations (particularly for HAPT, e.g."Walking" and "Sit to Stand") and (WISDM data set, e.g."Walking" and "Standing").The HAPT data set has an imbalanced data distribution where the transiting activities are under-represented in comparison to non-transiting activities as shown Figure 6.

Evaluation measures
Five performance measures are used to test the proposed model, namely, accuracy, precision, recall, F1-score and error  Figure 6 The number of activities recorded per each of the 12 activity groups for the HAPT data set rate as defined below using evaluations of true positives, false positives and false negatives as follows: where N is the total number of instances.We adopt the accuracy, precision, recall, F-score and error rate as our evaluation metrics for fair comparison with some of the stateof-the-arts methods.In an extremely imbalanced data set, the overall classification accuracy is not regarded as an appropriate performance measure, but, instead, this measure was used to evaluate the accuracy of each activity class.

Feature extraction analysis
It has been noticed that the performance of AKNN algorithm decreases with the existence of dependencies between features.Therefore, in this study, an approach based on KDA algorithm is conducted to eliminate the redundancy information from the segmented raw data.The kernel function used is the Gaussian kernel function, with a fixed s = 1. Figure 7 shows clusters of data points class projection in the KDA and compared to LDA spaces, respectively, for WSDM data set.As it can be seen, each physical activity (six classes) is represented by a color in the projected 3D space using the first three feature vectors in WISDM data set.As it can be noticed, it is possible to obtain a good separation between the human activity classes using KDA method, better than the one generated by LDA method.This projection aims to maximize the inter-class variations between the different activities.Besides, the use of KDA features as a basis for training SVM model would inevitably to a substantial reduction of the training phase because the smaller number of KDA features that can be generated from the original input data.
The preceding indicates the usefulness of the chosen KDA feature decomposition and its ability to discriminate various classes, compared to the commonly used LDA technique.
To detail the LDA feature decomposition carried out in Figure 7, we represent in Figure 8 the LDA feature selection process for each dataset.Especially, the input dimensionality is reduced by selecting the number of extracted features equal to N-1 where N is the number of physical activities.This leads to a representation of the initial data on a N-1 feature space.

Classification results
To evaluate the performance of the proposed approach for automatic HAR, we have used the extracted features by KDA and the WSVM algorithm tested with a LibSVM implementation (Hsu et al., 2003).
4.3.2.1 Model parameters tuning.Some of the classifier parameters are adjusted until we maximize the error rate through 10-cross validation technique.Results are computed by averaging the results obtained on each test fold.For the AKNN method, we have used an order q of similarity distance in a range of [1, 1.5, 2] and the k parameter in the range [1,3,5,7,9,11].The hyper-parameter s is estimated using a grid search method in the range [0.1-1].The summary of the optimal values obtained with the proposed method are summarized in Table 5.We have used the radial-basis function (RBF): K(x, y) = exp (À0.5.kxÀ yk 2 /s 2 ) where the width s is specified as a priori by the user.For the WSVM classification, we optimize the cost parameter C i adapted for each activity class by using the WSVM classifier with the common cost fixed parameter C = 1.The error weights assigned to various classes are set such that w i = m 1 /m i (or using the expression (10)).4.3.2.2 Performance evaluation and comparison.We conducted several experiments to compare the results of the proposed method for all data sets.We have used 70% training and 30% testing on all data sets.As for activity recognition performance, we have used various combinations of possible features (KDA, LDA) and various SVM refinements when standard SVM, weighted SVM and K-NN selection approach for SVs in SVM training phase.Especially, we also considered what we refer as AKNN baseline, where neither KDA feature selection, nor WSVM were used in the input phase.In total the following methods were constructed for comparison purposes WSVM, AKNN-baseline and hybrid methods LDA/SVM-KNN, LDA/WSVM-KNN, KDA/SVM-KNN, KDA/WSVM-KNN, KDA/SVM-AKNN.In addition to the preceding, the results reported by some state-of-the-art methods that used the same data set (Abidine et al., 2019;Abidine and Fergani, 2020;Anguita et al., 2012;Bharathi and Bhuvana, 2020;Wan et al., 2020;Zainudin et al., 2017;Zheng et al., 2018;Li et al., 2018;Lv et al., 2020) are acknowledged and discussed as well.These findings are now summarized in Table 11.The latter clearly indicates that the proposed classifier achieved the highest scores in terms of F1-score, precision, recall and error-rate metrics.It improved significantly the performance of smartphone-based HAR, with a good classification accuracy in all data sets.For instance, with HAR data set, the classification error of our model is reduced to 0.8%, which corresponds to 50% improvement on the second-best state-of-the art method reported in the literature that used a multi-layer perceptron architecture (Bharathi and Bhuvana, 2020).Similarly, it achieved 2.2%, 2.3%, 1% improvement on F1-score, recall and precision metrics, respectively, when compared to the second best approach.The improvement is especially striking in error rate.While MC-SVM, multiclass hardware friendly SVM (MC-HF-SVM), decision trees and random forest methods present more than 10% of error rate, which indicates a more than ten times improvement of our method over these approaches.For the HAPT data set, the level of improvement of the developed method is 61.1%, 1.2%, À0.04%, 0.4%, with respect to error rate, recall, precision and F1-score, respectively, when compared to the second-best method.
Similarly, the level of improvement in case of SAR data set is 21.4%, 2.7%, 0.5% and 0.3%.For WiSDM data set, the improvement sequence is 34.7%, 1.5%, 3.6% and 2.7%.Finally, for UniMib SHAR data set, our method achieves 17.3%, 3.5%, 7.5% and 5.6% improvement with respect to error rate, recall, precision and F1-score, respectively, over the second-best performance.This testifies of robustness and efficiency of the proposed method for daily activity recognition tasks.Comparing all ML classifiers for each data set in this table shows a sensible performance improvement where F1-score is higher for the proposed method and equal to 0.98, 0.98, 0.99, 0.95, and 0.85 for HAR, HAPT, SAR, WISDM and UniMib SHAR data sets, respectively.
The analysis also sheds light on the relevance concept of hybridization of WSVM and AKNN classifiers to enhance recognition capabilities of daily living activities.This can be partly explained by the fact that WSVM is used as the training algorithm to select SVs for the AKNN classifier.We also notice from these results that WSVM significantly outperforms AKNN for recognizing imbalanced data activities across all data sets, particularly for HAPT, WSIDM and UniMib SHAR.This can be explained by the fact that in these data sets, some activities contain a large number of samples, whereas others are only assigned a very small number of samples.The consideration of postural transitions as individual imbalanced classes in HAPT data set can increase the degree of difficulty of the recognition task, and therefore, can decrease the recognition rates of basic activities.In addition, UniMib SHAR database contains a total of 11.771 samples not equally distributed across activity types: 7.759 samples describing ADLs and 4.192 samples describing falls.Indeed, from the results highlighted Table 11, we notice that KDA/WSVM-KNN outperforms KDA/SVM-KNN.For instance, the error rate reduces from 7.9% for KDA/SVM-KNN to 4.1% for KDA/WSVM-KNN in case of HAR data set, and the same trend is almost observed for other performance metrics and other data sets.This is explained by the fact that WSVM is adapted for the imbalanced data set and consequently the obtained SVs regarded as the new training data set for different activity classes are balanced, unlike SVM where the number of SVs is imbalanced.The KDA features are found more relevant compared to the LDA features.This results from the improvements introduced by KDA/SVM-KNN, and KDA/WSVM-KNN compared to LDA/SVM-KNN, and LDA/WSVM-KNN.
Nevertheless, we notice that in SAR and WISDM data sets, the error rate is only slightly improved in the proposed method compared to HAR, HAPT and UniMib SHAR data sets.Also, the F1-score is lower for the proposed approach in the WISDM, and UniMib SHAR data sets using the accelerometer sensor while the activity was being performed.This is explained by the fact that the number of features (6) for both data sets is not sufficient when using KDA algorithm.A high dimension of features increases the complexity and has a negative effect on the final result.Hence, feature extraction using KDA in the proposed method becomes crucial for HAR, HAPT (561 features) and UniMib SHAR (453 features).
When using LDA features instead of KDA, the results do not confirm the superiority of LDA/WSVM-KNN over LDA/ SVM-KNN across all data sets, although this occurred in the majority of the data sets.
In terms of the scope of the training phase, we can claim that the use of KDA features substantially reduces the scale and enhances the efficiency of the subsequent classifier task as KDA identifies the most relevant features for the training process.Therefore, the proposed method provides a better prediction of these activities when trained on the KDA features compared to other methods, particularly for HAR, HAPT and UniMib SHAR data sets as illustrated in Table 11.
The computer used in this work for computing the execution time is equipped with an Intel Core i5-7700 CPU and 8 GB RAM.
As expected, the execution times of our approach are considerably reduced as the number of SV to compute the adapted distances of AKNN decreases.For example, in the case of UniMib SHAR data set, the execution times of testing decreases from 31.1 sec to 5.1 sec, by a factor of 6, while the training improves from 95.1 sec to 16.5 sec, by a factor close to 6 as well.This trend continues across all data sets.
It should be noted that despite the introduction of KDA and WSVM induces extra computational requirement as compared to baseline AKNN, this is widely compensated by the substantial reduction of subsequent SVs manipulation, which yields a sharp decrease in CPU execution time as compared to AKNN baseline.
4.3.2.4 Memory usage performance.Finally, we investigated the performance of the developed approach in terms of the amount of memory resources required.We compared again the baseline AKNN method to our model that involves KDA and WSVM.The result of this process is highlighted in Table 13.
The preceding indicates that training of the developed approach consumes between 5 times and 8 times less memory resources for training the developed compared to the baseline AKNN method.

Discussion
Besides the results in the Table 11, to get a detailed knowledge of the performances on each current activity, we calculate the confusion matrices for the proposed method in the Tables 14, 15 and 16 by using the balanced HAR data set, imbalanced SAR and WISDM data sets, respectively, with six different user's physical activities.These results show strong support for the effectiveness of our proposed method.Referring from Tables 14, 15 and 16, we see that in WISDM data set, with the exception for the dynamic activities "W.Upstairs" and "W.Downstairs," the performance has high performance scores, whereas the score is higher and nearly consistent across all the activities in HAR and SAR data sets.This can be due to the highly imbalanced nature of WISDM where the percentage of data for "W.Upstairs" and "W.Downstairs" are about 12% and 10%, respectively, whereas for walking it is about 38%.
According to the Table 14, it can be observed that 99.3% of "W.Upstairs" activity instances are correctly recognized, while 0.3% goes into "W.Downstairs" and 0.2% are confused with "Walking" activity.The similar classes such as "Walking," "W.Upstairs" and "W.Downstairs" show similar trend of sharing errors among each other.The reason is the similar status of smartphone when the user does these dynamic activities.The activities as "Sitting," "Standing" and "Laying" could be classified more accurately.We explained this by the fact that the nature of data distribution is almost uniform among all classes.We can also notice that the static activities "Sitting," "Standing," and "Laying" share errors among each other.A total of 2.7% of "Standing" activity instances misclassified as "Sitting" activity and 1.4% of "Sitting" activity instances are misclassified as "Standing" activity.The main reason for this might be that both sitting and standing are still a static posture; hence the accelerometer readings are similar.However, the minority class "Laying" in terms of number of instances ( 792) is totally recognized using the proposed method.
In Table 15, the best accuracy was achieved for four activities (walking, sitting, standing and jogging).Walking was recognized with 99.4% accuracy.Sitting and standing showed accuracy of 100% and 99.7%, respectively.It appears the system is able to reliably recognize these two activities.The activities "Walking Upstairs" and "Walking Downstairs" are less recognizable compared to other activities.But a closer examination of this table indicates that all of the misclassified instances are recognized interchangeably between these two activities.When grouping these two activities as one (activity: stairs), the system was able to recognize it with 100% accuracy.The presented system was able to classify simple activities with a very good accuracy.
In Table 16, in most cases, we get a high level of accuracy.For the two most common activities in terms of number of samples, "Walking" and "Jogging," we generally achieve accuracies above 97%.Both "Walking" and "Jogging" activities have significantly more samples than other activities, which would make the recognition results biased toward these activities."Jogging" appears easier to identify than other activities, which seems to make sense, as jogging involves more extreme changes in acceleration.On the contrary, it appears much more difficult to identify the two stair climbing activities.(88.9% for "W.Upstairs" and 92.9% for "W.Downstairs"), but as we shall see shortly, that is because those two similar activities are often confused with one another.Indeed, when grouping these two activities as one (activity: stairs), the system was able to recognize it with 100% accuracy.For the static activities, we can note that there are very few instances of "Sitting" (306) and "Standing" (246), but we can still identify these activities quite well with the proposed method.Although some of the user's activities recorded reflect somewhat insufficient performance as in WISDM dataset for "W.Upstairs" and "W.Downstairs," we could state that our method is capable of producing a decent accuracy.As mentioned above, the impact of gyroscope and accelerometer sensors were found to be sensitive to physical positions.Indeed, the gyroscope is not able to differentiate between similar activities like "Sitting" and "Standing."On the other hand, the accelerometers perform badly with "W.Upstairs" and "W.Downstairs."For the WISDM and UniMib SHAR data sets using an accelerometer sensor, we can note that the performances are decreasing comparatively to the other data sets.The results show that only one-axis acceleration is enough to classify simple full body motor activities.However, a sensor fusion-based strategy to collect the data sets would be useful for more accurate recognition performances.

Conclusion
In this work, we developed a novel activity recognizer model AKNN by revisiting the concept of extracting and handling the SVs used in standard SVM.The idea is to prone the training phase by using KDA features and hybridizing weighted SVM and KNN to enable handling of class imbalance data.The KDA dimension reduction technique selects the minimal number of discriminative and relevant features in the feature space.Extensive experimental evaluations using five publicly available data sets of daily activity recognition indicate a high classification performance compared to other ML classifiers.This is due to the ability of our approach to make the learning dataset more balanced and the high quality of the SVs generated by the combination of weighted SVM and KNN method.This deals with the class-boundary-skew problem and extracts useful SV to reduce the training dataset.The proposed method maintains the advantage of the WSVM in training phase.Additionally, the accuracy also tends to decrease when including few informative features to classify.
The purpose of this study is to build and test an accurate offline model using a compact training SVs from the original training data.This model reduces the computational and memory complexity of the system.Hence the real-time classification will be much faster using this light-weight approach.The proposed approach is promising to do real-time classification of activities, which can reduce the processing time to enable user-independent and operating system independent real-time recognition of the physical activities in Android OS smartphone.The comparison of the model with other state-ofthe art approaches that used the same data set as well various hybridization modes of SVM, WSVM, LDA, KNN, KDA testify of the quality of the proposal.Besides, the substantial reduction of computational and memory resources of the training phase provides solid assets for real-time implementation of the developed model on conventional smartphone platform.More work is still needed so that this method generalizes well to more users and more complex activities.Moreover, it would be interesting to use transfer learning as a new approach to tackle the imbalanced class.
On the other hand, as an ultimate perspective work, one shall point the growing interest in online activity recognition.The starting idea is therefore to implement the proposed system in Android platform that performs in real time as follows: Step 1: Establishing a connection between the data recording device (Smartphone user) and the controller (as a software running on a Windows computer or on a smart phone) using the User Datagram Protocol to transmit the data.
Step 2: Turn the control signal start gathering, preprocessing, feature extraction and training.The specific data to be arranged in a special format to comply with regulations on data formats.We stored the k SVs and the adaptive distances (d i ) for each nearest neighbor, in memory of controller to be used as a template at classification step.
Step 3: Recognition results will be sent to the smartphone user using the Transmission Control Protocol Connection.Due to the requirement of continuous activity recognition, the calculation should be done in parallel with the process of writing data, which is used for the next recognition.

Figure 1
Figure 1 Process of activity recognition

Figure 2
Figure 2 Proposed smartphone-based activity recognition framework DB Train : Training Database Labels_train= (Y 1 . . .Y m ) // The corresponding labels of DB train DB test //DB test : Test Dataset DB

-Figure 5
Figure 5 Activity samples distribution for the UniMib SHAR data set

Figure 7
Figure 7 Distribution of multi-activity patterns in (a) LDA, and (b) KDA spaces for WISDM data set

Figure 8
Figure 8 Feature selection by applying LDA on the training data for each data set

Table 1
Comparison of classification state-of-the-art methods in HAR

Table 2
Advantages and disadvantages of KNN and AKNN algorithms

Table 3
Overview of publicly available datasets of activity recognition used in the evaluation of the proposed approach.Accelerometer (a), gyroscope (G), magnetometer (M)

Table 4
Annotated list of physical activities

Table 5
Optimal values of the proposed methodParameters Method HAR HAPT SAR WISDM UniMiB SHAR

Table 6
Weights w i in HAR data set

Table 7
Weights w i in HAPT data set

Table 8
Weights w i in SAR_belt data set Table 10 Weights w i in UniMib SHAR data set Table 11 Comparison using the performance metrics (in percent) of the proposed model against the state-of-the-art methods Table 12 CPU Time for the proposed activity classifier on HAR, HAPT, SAR, WISDM and UniMib SHAR datasets

Table 13
Memory resources for the training phase of the proposed method on HAR, HAPT, SAR, WISDM and UniMib SHAR data sets, compared to AKNN baseline

Table 14
Confusion matrix of proposed method on the HAR data set (percentage) Table 15 Confusion matrix of proposed method on the SAR dataset (percentage)

Table 16
Confusion matrix of proposed method on the WISDM dataset (percentage)