# Prediction and Comparison of In-Vehicle CO\({}_{2}\) Concentration Based on ARIMA and LSTM Models
## 2 Materials and Methods
### Prediction Models
#### 2.2.2 LSTM Model  
In 1997, [PERSON] and [PERSON] proposed the LSTM neural network [68], which is an improved version of a recurrent neural network (RNN). The single-cell structure of the LSTM cell structure is shown in Figure 5, with each cell having three gates: the \"input gate\", the \"forget gate\", and the \"output gate\". This \"gate\" can be opened or closed to determine whether the output of the memory state (the previous state of the network) of the model neural network reaches a threshold value at that layer, so that it can be added to the current calculation of that layer [69]. Each gating unit is a sigmoid activation function that controls the flow of information. In the LSTM model, each time step has a hidden state \(h_{t}\) and a cell state \(C_{t}\). Cell states are a central part of the LSTM model, which allows the neural network to selectively forget or preserve information. The cell state \(C_{t}\) at each time step depends on the cell state \(C_{t-1}\) at the previous time step, the input \(x_{t}\) at the current time step, and the output of the gating unit. LSTM's cell states can pass information between multiple time steps, allowing the neural network to capture long-term dependencies. It is possible to keep the important information and forget the minor information, to be able to identify the regular changes in time series data, and to realize the prediction. The training process of the LSTM neural network uses a back propagation algorithm combined with gradient cropping to address the shortcomings of traditional recurrent neural network gradient explosion. The mathematical formulations for the input gate (\(i_{t}\)), forgetting gate (\(f_{t}\)), and output gate (\(o_{t}\)) are presented in Equations (6)-(8). The memory cell C is utilized for the storage and transmission of long-term information within the network, with mathematical expressions depicted in Equations (9) and (10). Equation (11) depicts the output \(h_{t}\) generated by the LSTM network:  
\[i_{t}=\sigma(W_{i}\cdot[h_{t-1},x_{t}+b_{i}]) \tag{6}\]  
\[f_{t}=\sigma(W_{f}\cdot[h_{t-1},x_{t}]+b_{f}) \tag{7}\]  
\[o_{t}=\sigma(W_{o}\cdot[h_{t-1},x_{t}]+b_{o}) \tag{8}\]  
\[C_{t}=f_{t}\cdot C_{t-1}+i_{t}\cdot C_{t}^{{}^{\prime}} \tag{9}\]  
\[C_{t}^{{}^{\prime}}=tanh(W_{c}\cdot[h_{t},x_{t}]+b_{c}) \tag{10}\]  
\[h_{t}=o_{t}\cdot tanh(C_{t}) \tag{11}\]  
The key steps for time series prediction using LSTM are as follows:  
* Data preprocessing: Data preprocessing can effectively reduce noise, eliminate redundant information, and extract key features from data to enhance the training and prediction performance of neural network models. This research employs the max-min normalization method for data preprocessing. This process ensures that all data values are reflected within the [0, 1] interval. The calculation method for normalization is as follows: \[y_{i}=\frac{x_{i}-\min(x_{i})}{\max(x_{i})-\min(x_{i})}\] (12)
* Determining the neural network structure: Determine the inputs and outputs of the neural network and the number of neurons in the hidden layer. * Network training: Determine the loss function, activation function, optimizer, and other parameters utilized for training the LSTM network. The loss function adopts the mean squared error (MSE) as the criterion for evaluation. The computation of the MSE is illustrated below:  
Figure 5: LSTM cell structure. \[\text{MSE}=\frac{1}{n}\sum_{i=1}^{n}{(y_{i}-\hat{y_{i}})^{2}} \tag{13}\]  
MSE, which stands for mean squared error, is a metric used to assess the accuracy of a model's predictions. It is calculated by averaging the squared differences between the predicted and true values. The activation functions use the sigmoid function. The adaptive moment estimation (Adam) was selected as the optimizer for this research. The Adam optimizer is suitable for problems where the gradient is sparse or noisy. The update of its parameters is not affected by the gradient scaling transformation. It is a commonly used optimizer for deep learning.