## 3 Methodology
### Build Prediction Methods
#### 3.5.3. A Hybrid Intelligence of LSTM and the Genetic Algorithm (GA)
We run the genetic algorithm to evolve the population and select the best individual from the last generation as the best solution. These optimal parameters, such as the window size and the number of units of the LSTM network, were used to build and train the neural network. The choice of these parameters was based on the need to maximize the performance of the model and improve its ability to capture complex patterns in unemployment time series data. Integrating an LSTM neural network with a GA involves combining the learning capability of the neural network to model sequential data with the optimization capability of the genetic algorithm to search for the best set of hyperparameters for the neural network. The specific steps involved in this process are detailed below:  
1. Import the libraries and modules necessary for prediction. This includes libraries for manipulating data (NumPy, Pandas, and Scikit-learn), plotting data (Matplotlib), neural networks (Keras), and genetic algorithms (DEAP), as well as extra libraries for manipulating bit structures (Bitstring) and generating random binary values using the Bernoulli distribution (SciPy). 2. Import the time series data; the time series will be used for model training and evaluation. The unemployment data are expressed in a comma-separated value (CSV) format. 3. Prepare the data set; the data are divided into sequences of specified length (window size), which will be used as input for the LSTM neural network. In addition, the corresponding input and output data are prepared. 4. Define the training and evaluation function \"train_evaluate\" that creates and trains the LSTM neural network for a given individual of the genetic algorithm. This function returns the training accuracy using the RMSE metric on a validation set. Define the structure of the genetic algorithm; the DEAP library is used to define the structure of the genetic algorithm. Characteristics of individuals are defined, such as gene size, population, crossover, mutation and selection operations, and the fitness evaluation function of each individual in the population. 6. Run the genetic algorithm to evolve the population over several generations. During each generation, individuals are crossed, mutated, and selected for fitness. 7. Select the best individual from the last generation as the best solution found by the genetic algorithm. The optimal parameters of this individual are specified (number of windows and number of units of the LSTM model) by setting the values in the variables \"window_size_bits\" and \"num_units_bits\". 8. Use the best solution found to build and train the LSTM neural network with the optimal parameters. The model is trained using the training data set, and its performance is evaluated using the test data set. During training, the cross-validation technique is used, where 10% of the training data is reserved as a validation set. This process allows model performance to be monitored on unseen data while tuning hyperparameters to avoid overfitting and improve model generalization. 9. Finally, the results obtained by the model are graphed. The model predictions are compared with the actual values of the time series. The described process allows integrating an LSTM neural network with a genetic algorithm to optimize the hyperparameters of the model and improve its predictive capacity in the unemployment prediction task. The Python code for our hybrid GA-LSTM prediction method is released on the GitHub repository \"unemployment rate prediction\" at [[https://github.com/kevinmero/Unemployment-rate-prediction](https://github.com/kevinmero/Unemployment-rate-prediction)]([https://github.com/kevinmero/Unemployment-rate-prediction](https://github.com/kevinmero/Unemployment-rate-prediction)) (accessed on 19 February 2024).