# Spectral Data-Driven Prediction of Soil Properties Using LSTM-CNN-Attention Model
## 2 Materials and Methods
### Model and Methodology
#### 2.5.4 Proposed Model and Prediction Workflow  
The LSTM-CNN-Attention model integrates temporal, spatial, and feature-specific information from spectral data to predict soil properties with high accuracy. Figure 5 illustrates the model architecture, while Figure 6 provides a detailed flowchart of the prediction workflow.  
Figure 5: The framework of the proposed LSTM-CNN-Attention model.  
The model workflow begins with the input of spectral data. Sequential dependencies inherent in soil spectral features are captured by the LSTM layer, which is adept at extracting long-term dependencies and temporal patterns. This layer generates context-aware feature representations, effectively summarizing sequential information across wavelengths. These sequential representations are refined by the attention mechanism, which dynamically assigns weights to different features. By leveraging the self-attention mechanism, the model derives Query (\(Q\)), Key (\(K\)), and Value (\(V\)) matrices and calculates a scaled dot product to measure feature importance. This operation is followed by softmax normalization, which transforms the computed scores into a probability distribution. The attention mechanism enables the model to prioritize the most informative spectral bands, focusing on regions critical for predicting specific soil properties. The weighted feature representations are then processed by the convolutional layer, which extracts spatial patterns and localized correlations through multiple convolutional filters. These filters operate at varying scales to recognize complex spatial relationships in the spectral data. Subsequently, a fully connected linear layer aggregates the refined features and generates predictions for soil properties. During training, the model's predictions are compared against ground truth values, and its parameters are optimized using gradient descent to minimize error.  
The prediction workflow, as illustrated in Figure 6, systematically outlines the steps involved. Spectral data undergo preprocessing to remove noise and artifacts, followed by partitioning into training, validation, and test sets. During the training phase, the model is initialized and iteratively optimized using mini-batch gradient descent. Hyperparameter tuning is conducted based on validation set performance, and training continues until convergence criteria are satisfied or a maximum number of epochs is reached. The trained model is then evaluated on the test set using metrics such as R2 and root mean square error (RMSE) to ensure robust and reliable predictions.  
The integration of LSTM, attention, and CNN components offers a comprehensive approach to feature extraction and soil property prediction. The LSTM layer effectively captures sequential dependencies, the attention mechanism highlights key spectral features,  
Figure 6: The flowchart of soil property prediction with the LSTM-CNN-Attention method.  
and the CNN layer enhances spatial feature extraction. This synergistic design ensures superior performance compared with traditional methods, making it particularly well suited for soil property prediction tasks.  
The entire framework is trained in an end-to-end manner, ensuring that the parameters of the LSTM, Attention, and CNN are jointly optimized, thereby enhancing both predictive performance and generalization. The parameters for each model component are presented in Table 1.