Hjorth features and k-nearest neighbors algorithm for visual imagery classication

—Visual imagery is an interesting paradigm for use in Brain-Computer Interface systems. Through visual imagery we can extend the potential of BCI systems beyond motor imagery or evoked potentials. In this work we have studied the possibility of classifying different visual imagery shapes in the time domain using EEG signals, with the Hjorth parameters and k-nearest neighbors classiﬁer 69% accuracy has been obtained with a Cohen’s kappa value of 0.64 in the classiﬁcation of seven geometric shapes, obtaining results superior to other related works.


I. INTRODUCTION
Brain-Computer Interface (BCI) are systems that allow creating a direct communication channel between the brain and external electronic devices without the need to use the musculature [1], through these systems people with mobility problems and who cannot use other human-to-computer interfaces machine can carry out a certain communication. BCI systems are usually specialized in a specific paradigm, there are various paradigms, among the most used we can find the motor imagery, evoked potentials (P300, SSVEP) or slow cortical potentials (SCP) [2]. Through these paradigms the user is trained to be able to manipulate the BCI system, but in recent years a new paradigm, visual imagery, has been gaining strength. Visual imagery can be defined as the ability to observe objects that are not being perceived by sight [3]. Although visual imagery has been widely studied by the scientific community using fMRI or PET devices [4], the same does not occur in the field of BCI. For many years, the BCI community has focused on paradigms such as evoked potentials (P300 or SSVEP) and motor imagery, since very good results have been obtained through these paradigms, but, in recent years, new studies have appeared where focuses on the use of visual imagery, although many studies have been able to show that visual imagery is classifiable [5], [6], [7], [8] and therefore susceptible to being used in BCI systems, some work has emerged where it is not clear whether or not the classification of visual imagery [4], that is why in this work we have studied the possibility of classifying visual imagery and confirming the following hypotheses. Is it possible to classify multiple classes imagined shapes by EEG signals? Can we use the time domain to classify two imagined objects using EEG signals? Are all objects classifiable? Answering these questions, we want to move towards the incorporation of visual imagery as a paradigm to be used in BCI systems, in this way, the capacities of BCIs will be extended to new cognitive capacities and applications can have a more natural interaction, for example if we want to create a drawing or art application, it is much more natural to use visual imagery than other paradigms, imagine the reader, that we want to draw a triangle, if our system can detect which geometric figure the person is imagining, then it will be able to draw said figure, and we will not have to use the imagination to move a limb or fixate on blinking screens as in the case of a system based on the SSVEP paradigm.
The work carried out so far has focused on the classification of geometric shapes [6] and everyday objects [8], [5], [6], [7], [9]. Both geometric shapes and everyday objects have been classified successfully, but it has not been studied whether the type of object affects the classification, we can also observe that all the works using complex techniques for the processing and extraction of features of the EEG signals to later be classified, this is an important barrier when investigating and replicating the results obtained by other researchers, that is why in this work we have focused on the time domain, the techniques used being the simplest of implement. There are three important works related to the one presented in this article, on the one hand we have the work [6] where five geometric figures are classified with an accuracy of 44.60% using the EMOTIV EPOV device with 14 channels, another similar work is that of [9] where five geometric figures are also classified, the method used in this work is by means of a bank of filters with common spatial patterns and the results obtained in an average accuracy of 28%, being a probability level of 20%, this work was the second work on the classification of geometric figures using EEG signals. Another work related to the classification of geometric figures using EEG signals is [10], but in this work the classification between visual imagery and visual perception is compared, and the classification in visual perception of geometric figures, obtaining for visual perception a hit of 32.56 % using 32 channels.
As we can see, there are very few works that study the use of imagined geometric figures for the creation of noninvasive BCI systems with EEG signals.

II. MATERIALS AND METHODS
In this work we used the g.Nautilus device developed by the g.Tec company. We have used the eight Ag/AgCl electrodes located in the parietal-occipital area, specifically the following electrodes: P3, P4, PO3, POz, PO4, PO7, PO8 and Oz, the AFz electrode being the reference electrode ( Figure  1). The electrodes are wet electrodes. Once the conductive gel was placed, the impedance of all the electrodes was less than 10 KΩ. The sampling frequency was 250 Hz and with 16 bits of resolution. This work has been partially funded by the project TIN2017-88515-C2-2-R of the Ministry of Economyand Competitiveness of Spain and complies with all the ethical precepts that are required. While the EEG signals were being recorded, a Notch filter between 48 and 52 Hz was applied to the signals to eliminate artifacts produced by the power line, and also a Butterworth type band-pass filter of order five between 0.01 and 100 Hz [11].
Seven people (four men and three women) with an average age of 32 years have participated in this work, all participants were informed about the paradigm before the experiment and they were informed that during the instant of visual imagery they will try to move little so as not to contaminate the EEG signals with muscular artifacts. EEG records were taken in a room with low light, where at the time of registration only the user who registers is not to be disturbed, the person sits in front of a computer at a distance of 80 cm from the 17" screen. For one second, a cross appears on the screen with a black background, indicating the start of the trial, followed by a random picture of the one shape ( Figure 3) for two seconds, then the picture disappears from the screen and the user for five seconds must visualize by the imagination the shape that is indicated ( figure 2).
The protocol has been registered using the OpenVibe software [12]. Once we have registered the signals and they have been filtered, the trials have been divided into segments without overlap. Before segmenting the trials, the bad channels have been automatically eliminated. Bad channels are considered those that the standard deviation (equation 1) in the time domain is twice higher than the average standard deviation of the other channels [13].
where X i is the i-channel, n is the number of channels and µ a is is the mean of the i-channel.
Once the trials have been segmented and reject bad channels each segment has been filtered through the CAR filter (equation 2).
III. HJORTH FEATURES The Hjorth parameters are a set of three statistical values that describe the EEG signal in the time domain, these parameters were introduced by Bo Hjorth in 1970 [14]. The parameters are activity (equation 6), mobility (equation 7) and complexity (equation 8). The activity parameter represents the variance of the signal over time. Mobility represents the average frequency and complexity represents the change in frequency.
The hjorth parameters have been widely used to characterize EEG signals [15], [16], [17]. In this work, the hjorth parameters are applied for each channel, therefore, as we have eight channels, the dimension of the features vectors is 24.

IV. K-NEAREST NEIGHBORS ALGORITHM
k-nearest neighbor classifier is a classifier used for classifying EEG signals [18]. This algorithm is based on a function that calculates the distance between the different points (the points represent the characteristic vectors) and depending on the proximity with a set n of points, a label will be assigned to the examples that we want to classify.
A fundamental part of this algorithm is the distance function, in our case the distance function used is the Minkowski (equation 8) function.
This is a simple yet robust classifier that has proven its worth using BCI systems [19]. Data a vector of features that must be classified, let x 1 , .., x k be the k closest neighbors to the vector to be classified, it is returned the most common value of the k closest neighbors to the vector to be classified, in the case that k = 1 then the value closest to the vector to be classified will determine its value.

V. RESULTS
In this work, a multiclass classification has been carried out, specifically, seven classes have been classified at the same time. Classes are the different geometric shapes that have been used to record EEG signals. To test the process, we have chosen to use the k-fold cross validation technique, this technique is widely used in offline BCI studies [20]. The k value used is equal to five. Using 5-fold cross validation, the data is randomly divided into 5 folds to test five times and the results obtained are averaged.
To evaluate the system and be able to compare it with other works, it has been chosen to provide three different evaluation metrics, firstly, the accuracy (equation 10) is reported, secondly, the kappa of Cohen [21] (equation 11) is reported, which is a good indicator to discover how it is includes the classifier, and finally the p value (equation 12), which is the average of the confusion matrix, diagnostic elements.
Where TP is true positive, TN is true negative, P number of positives and N number of negatives.
Where p o is the observed accuracy and p e is the theoretical accuracy, is own work the theoretical accuracy is 0.14 (1/num. classes).
Where p ij is an estimate of probability of the i-th and j-th element in confusion matrix, the element p ij is a diagonal element and L is number of classes. This indicator is easy to interpret, for a value of p = 1 it means that the classifier has made a perfect classification, if p = 1 / L where L is the number of classes to classify, then the classifier has an efficiency equal to chance.
In the first place, the k parameter in the k-nearest neighbors has been calculated, which tells us how many neighbors we will take into account to assign the class to the example that we want to classify. The results show that with the value of k = 1 the maximum is obtained, being 69.60%. In figure 4 you can see the success curve in relation to the k value of the k-nearest neighbors, the maximum is obtained with a value of 1, this means that the value obtained by the examples to be classified are that of the point with the distinction lower, that is, the points will be assigned according to the closest point.
Another important aspect is the size of the segments, the size of the segments tells us how much temporal information we need to be able to classify the EEG signals in their correct class. In our work we have tested which segment offers the best results, time segments of 250 ms, 500 ms, 1 s and 2 s have been tested. The results have shown that the 250 ms segment is the one that offers the best results, which are the results that are shown in all the results offered below.  In table 1 we can see the results obtained by each subject through 5-fold cross validation with segments of 250ms and a k value of the k-nearest neighbor algorithm equal to 1. We can see that a maximum success rate of 89% is reached for subject 1 and a minimum value of 45% for subject 3, these results are much higher than the results obtained in other studies. In the figure 5 we can see the average confusion matrix of all the subjects, the matrix is highly diagonal indicating that the result of the classification is beyond chance and that the behavior of the classifier is good.
In the work of [6] a minimum of 36 % in the classification of five geometric objects and a maximum of 56 % of success have been obtained and in the work of [9] the maximum obtained for five geometric figures is 37 % , this indicates that it is possible to classify the imagination of geometric figures in the time domain using the parameters hjorth.    The figures 6,7,8 show the activiy, mobility and complexity for each figure, as we can see the activity is one of the parameters that provides more differences between the geometric shapes used.
VI. DISCUSSION Figure 5 shows the average confusion matrix when classifying the geometric figures, for this it has been necessary to divide the trial into 250 ms segments. We can see that the percentage of success is high in all the geometric figures, comparing with other works similar to this one, results are obtained much higher, for example in the work of [10] a 44.60% is obtained for the classification of five geometric figures, while in our work a 69% is obtained for seven geometric figures using the Hjorth parameters, which is a simple way to calculate the features of the EEG signals. It would be necessary to continue studying the potential that the classification of imagined geometric figures can offer, using more figures and even trying to detect compositions of geometric figures.

VII. CONCLUSION
In this work we have studied the possibility of classifying the visual imagery of seven different geometric shapes in the time domain, the hjorth parameters being useful for classification. This opens up the possibility of integrating visual imagery into BCI systems and thus being able to create more natural art or design applications. The results obtained show that the seven geometric shapes can be classified with a maximum of 89% and a minimum of 57%, the average being 69%, surpassing the results of other related works. It has been studied that the 250 ms segments are the best for classification, this opens the window to create BCI systems with low latency since even the Hjort technique is a computationally economical technique, therefore without having to perform large processing and complex techniques, such as the use of Deep learning or ICA-type filters, we can get to classify EEG signals with high acuracy. This is the third study where, using EEG signals, the visual imagery of geometric shapes is classified and it is the first work that classifies more than five imagined geometric shapes, showing that it is possible to integrate the visual imagery of geometric shapes in BCI systems.

VIII. COMPLIANCE WITH ETHICAL STANDARDS
Conflict of interest There is no conflict of interest. Ethical approval Informed consent was obtained from all the individual participants included in the study.