# Improving Deep Learning-Based Recommendation Attack Detection Using Harris Hawks Optimization
## 3 Proposed Approach
### Detection Algorithms
Taking the DL-DRA-HHO method in our experiments as an example, \(D\) is set to 4 as shown in Table 5. \(K_{1},K_{2},K_{3}\), and \(K_{4}\) are set to size of the square, activation function, batch size, and epoch, respectively. The candidate values of \(K_{1},K_{2},K_{3}\), and \(K_{4}\) are integers between [20, 100], elements in set [linear, sigmoid, tanh, elu, relu, and selu], integers between [8, 128], and integers between [3, 30], respectively. Based on these descriptions and the improved HHO algorithm, we propose a hyperparameter automatic optimization algorithm as described in Algorithm 2 to optimize key hyperparameters for the deep learning-based detection methods. In Algorithm 2, line 1 performs the data type conversion to meet the requirements of HHO algorithm. Lines 2 and 3 initialize the population and the best solution. Line 4 sets the maximum number of iterations. Line 5 calculates the fitness for each solution. F-measure is used as the fitness in this paper. Line 6 filters the optimal solution after each iteration. Lines 7 to 9 add an early stop condition to improve the original HHO algorithm. If the maximum fitness has not changed for \(m\) consecutive iterations, it indicates that the current optimal solution has a certain stability. The iteration will be terminated. Moreover, \(m\) is set to 5 in our experiments. Lines 10 to 28 execute the exploration and exploitation operations to find the optimal solution. Line 30 returns the search result. In Algorithm 2, line 1 performs the data type conversion to meet the requirements of HHO algorithm. After this step, both discrete and continuous key hyperparameters can be optimized by the HHO algorithm. Lines 2 and 3 initialize the population and the best solution. The algorithm randomly generates initial positions. The number of initial positions is the same as the size of population. Line 4 sets the maximum number of iterations. Line 5 calculates the fitness for each solution. F-measure is the weighted adjusted average of precision and recall, which can comprehensively reflect the classification performance of the detection model. Therefore, F-measure is used as the fitness for each solution in this paper. Line 6 filters the optimal solution after each iteration. The best solution in the current population will be found in this step. Lines 7 to 9 add an early stop condition to improve the original HHO algorithm. If the maximum fitness has not changed for \(m\) consecutive iterations, it indicates that the current optimal solution has a certain stability. The iteration will be terminated. Furthermore, \(m\) is set to 5 in our experiments. Lines 10 to 28 execute the exploration and exploitation operations to find the optimal solution. In the phase of exploration, the random factors \(r_{1}\), \(r_{2}\), \(r_{3}\), \(r_{4}\), and \(q\) in Equation (1) can effectively expand the scope of the global search. Meanwhile, the search algorithm can avoid falling into the local optimal solution in the early stage of the algorithm. In the phase of exploitation, the algorithm searches for the local optimal solution through four attack strategies as shown in Equations (4), (6), (10) and (11). Line 30 returns the search result. After this step, the optimal solution is obtained. Based on the optimal key hyperparameters obtained from Algorithm 2, we propose Algorithm 3 to detect the recommendation attack. As shown in Algorithm 3, user profiles in the set of detection result are classified into two categories: genuine profile or attack profile. ```
0: training set \(Set_{train}\), test set \(Set_{test}\), deep learning-based detection method \(DLDM\), and the optimal key hyperparameters \(X_{rabbit}\). 0: detection result set \(Set_{result}\). 1: Classifier \(\leftarrow\) Train \(DLDM\) to generate a classifier by using \(Set_{train}\) and \(X_{rabbit}\). 2:\(Set_{result}\)\(\leftarrow\) Detect \(Set_{test}\) using the generated classifier. 3:return\(Set_{result}\)
```  
**Algorithm 3** Recommendation attack detection algorithm with the optimized key hyperparameters.