For a wearable-based HAR system, it is not difficult to collect some data under a controlled environment. For instance, the data collection can be video recorded and any inconsistency in the label of the collected data from wearable sensors can be corrected. This type of data can be called “trusted". This notion of the trusted dataset is the central idea of our defense mechanism. Put it another way, our data collection process is a hybrid model covering both a closed environment and crowdsensing. Naturally, the size of an available trusted dataset is smaller than the untrusted dataset. The defense mechanism works as follows. At the beginning, it takes a trusted dataset and a machine learning algorithm as input. Here, we use the KNN approach proposed by Paudice et al.[1]}. Using the inputs, the mechanism trains a model to predict the label of a given sample. This model is then deployed between the data source and the database to filter out and correct the labels of poisoned samples before inserting them into the database. The design of the system with the defense mechanism is depicted using figure REF . Algorithm  describes the steps of the defense mechanism. With \(K\)  as its hyperparameter, it takes a potential poisonous sample \((x, y)\)  as input. Then, it calculates the distance of each sample in the trusted set to the input sample, then pick the \(K\)  closest samples (line 1 in algorithm ). Finally, it replaces \(y\)  in \((x,y)\)  with the mode of the labels of selected \(K\)  samples.
<FIGURE>