A flood forecasting method based on multi-scale time modeling

By using a CNN-LSTM-ATTENTION hybrid model, the problem of modeling long-term cumulative effects and short-term extreme mutations in existing flood prediction methods is solved, achieving high-precision and low-latency flood prediction, which is suitable for real-time early warning in resource-constrained areas.

CN122153576APending Publication Date: 2026-06-05陕西省水旱灾害防御中心 +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
陕西省水旱灾害防御中心
Filing Date
2026-02-11
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing flood forecasting methods struggle to simultaneously model long-term cumulative effects and short-term extreme mutations in applications that rely solely on univariate rainfall time-series data. Attention mechanisms are insufficient in terms of lightweight design and real-time inference, data noise handling is not robust, and model inference latency is high on edge devices, limiting their application in real-time early warning.

Method used

The CNN-LSTM-ATTENTION hybrid model (CLA-FFNet) is adopted. It extracts local spatial features of rainfall sequences through convolutional layers, introduces channel attention mechanism for feature weighting and filtering, and then uses LSTM to capture temporal dependencies. Finally, it uses temporal attention mechanism to focus on key early warning periods, so as to achieve high-precision and low-latency end-to-end flood prediction.

Benefits of technology

It improves the accuracy of flood forecasting, reduces the estimation errors of ARIMA, LSTM, and Transformer, lowers inference latency, enhances the interpretability of the model and its robustness to missing data and noise, and is suitable for the real-time early warning needs of resource-constrained areas.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122153576A_ABST
    Figure CN122153576A_ABST
Patent Text Reader

Abstract

The application discloses a flood prediction method based on multi-scale time modeling, which is used for flood prediction in a region and comprises the following steps: acquiring rainfall data monitored by a meteorological station in a certain month before a prediction month, wherein the certain month is determined by a flood prediction model during construction; processing the rainfall data to form a rainfall sequence in time sequence, forming a flood prediction model constructed by rainfall data characteristics, and outputting a flood submergence degree by the flood prediction model; and forming a flood prediction for the prediction month in the region, wherein the flood prediction model is a neural network flood prediction model. The application fully mines rainfall observation data of a rainfall station, combines a flood season monitoring platform to judge a flood submergence range, constructs a high-quality and multi-source fusion flood prediction data set, and enhances the interpretability of the model through a double attention mechanism, so that the model can identify a key rainfall mode and an influence period and has good robustness to data loss and noise.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of data-driven flow forecasting technology, and specifically relates to a flood forecasting method based on multi-scale time modeling, which is a time-series data-driven flood forecasting method based on CNN-LSTM-ATTENTION. Background Technology

[0002] Against the backdrop of increased frequency and intensity of extreme rainfall events due to global warming, floods have become the most significant natural disaster globally, severely threatening human life and property, socio-economic stability, and ecosystem balance. Developing accurate and real-time flood forecasting technologies is crucial for enhancing global disaster prevention and mitigation capabilities. In terms of technological evolution, traditional flood forecasting primarily relies on physics-based hydrodynamic models (such as HEC-HMS and SWMM) and statistical learning methods (such as ARIMA and Support Vector Machines). These methods are either limited by data accuracy and computational efficiency or struggle to handle the nonlinearity and complexity of hydrological processes. In recent years, deep learning technology has gradually become mainstream. Recurrent Neural Networks (RNNs) and Long Short-Term Memory Networks (LSTMs) are widely used to capture long-term dependencies in time series data such as rainfall and flow rates; Convolutional Neural Networks (CNNs) are used to extract spatial features from topographic data such as remote sensing imagery; and the Transformer architecture based on attention mechanisms further enhances the model's ability to fuse multi-source spatiotemporal data and focus on key information. However, existing methods still have significant limitations: in application scenarios that rely solely on univariate rainfall time series data, traditional LSTM and other models struggle to simultaneously model long-term cumulative effects and short-term extreme mutations; attention mechanisms are insufficient in terms of lightweight design and real-time inference, failing to effectively focus on critical rainfall periods before floods occur; furthermore, their inadequate handling of data noise and high inference latency on edge devices also restrict their practical application in real-time early warning. Summary of the Invention

[0003] To overcome the above problems, this invention proposes a flood prediction method based on multi-scale time modeling. This method is a time-series data-driven flood prediction method based on CNN-LSTM-ATTENTION. The method of this invention uses a hybrid model of CNN-LSTM-ATTENTION (CLA-FFNet) to extract local spatial features of rainfall sequences through convolutional layers, introduces a channel attention mechanism for feature weighting and filtering, then uses LSTM to capture time dependencies, and uses a time attention mechanism to focus on key early warning periods. Finally, it achieves high-precision, low-latency end-to-end flood prediction, providing effective technical support for real-time early warning in resource-constrained areas.

[0004] To achieve the above objectives, the solution of the present invention is as follows:

[0005] A flood prediction method based on multi-scale temporal modeling is used to predict floods in a region. It acquires rainfall data monitored by meteorological stations for a predetermined number of months prior to the prediction month. This predetermined number of months is determined during the construction of the flood prediction model. The rainfall data is processed to form a chronological rainfall sequence. This rainfall sequence is used as a feature input to the flood prediction model, which outputs the inundation level, thus forming a flood prediction for the prediction month in the region. The flood prediction model is a neural network flood prediction model composed of a CNN input layer, a spatial attention layer, a long short-term memory layer, a temporal attention layer, and a fully connected output layer. The process of determining the predetermined number of months includes:

[0006] Step 1: Collect precipitation data from meteorological stations in the region that are several times the number of months in the specified area, and compile the precipitation data into a rainfall sequence in chronological order;

[0007] Step 2: Annotate the rainfall sequence based on hydrological thresholds or flood inundation records to generate a precipitation dataset with flood occurrence classification;

[0008] Step 3: Process the precipitation dataset: This includes interpolating missing values ​​in the dataset and removing abnormal data caused by equipment malfunction or recording errors;

[0009] Step 4: Divide the processed precipitation dataset into training set, validation set and test set according to time order. The training set is used for model parameter learning, the validation set is used for model parameter adjustment, and the test set is used to test the final effect of the model.

[0010] Step 5: Select one month from the training or validation set of the precipitation dataset as the prediction target month with a known classification, and select the rainfall sequence data features formed by a preliminary segment of rainfall data from months prior to the prediction target month; input the rainfall sequence data features of the segment of months into the flood prediction model, and the flood prediction model outputs the probability distribution vector of the flood inundation category, and select the category with the maximum probability from the distribution vector as the final flood inundation category;

[0011] Step 6: Compare the category containing the maximum and minimum probability values ​​in the probability distribution vector with the known classification of the target month to determine whether the probability distribution vector of the flood inundation category output by the flood prediction model is close to the known classification of the target month.

[0012] Step 7: If the comparison results are close, the selected period of months that is close is the determined period of months. If the comparison results are not close, the length of the selected period of months is adjusted, and the rainfall sequence data features are formed by selecting rainfall data of the adjusted period of months before the month of the prediction target. The rainfall sequence data features of the adjusted period of months are input into the flood prediction model, and the flood prediction model outputs the probability distribution vector of the flood inundation category. The process returns to step 6 until the determined period of months is determined.

[0013] The solution is further as follows: In step 6, whether the comparison is close or not is determined by setting a percentage threshold. If the comparison result reaches the set percentage threshold, it is considered to be close or not. The percentage threshold is not less than 80% and is initially set to 95%.

[0014] The scheme further includes: the method further includes recording the number of adjustments for a selected period of months; if a finite number of adjustments still do not reach a close approximation, then adjusting the percentage threshold; if the percentage threshold is adjusted to below 80%, then the obtained rainfall data is considered not to support the flood prediction model prediction.

[0015] The scheme further includes: if the percentage threshold is adjusted to be lower than 80%, the parameters of the neural network flood prediction model are adjusted; if the parameters still do not approach the threshold after adjustment, the obtained rainfall data is considered not to support the flood prediction model prediction.

[0016] The solution further includes a data ratio of 7:1:2 for the training set, validation set, and test set.

[0017] The solution further includes: In step 3, the interpolation of missing values ​​in the dataset is performed using STL decomposition. The formula for STL decomposition is:

[0018]

[0019] In the formula: This is the original rainfall sequence; This is a trend item; For seasonal items; For residual terms;

[0020] The STL decomposition steps are as follows: First, smooth the original sequence using LOESS with a window size of 12 months to extract the long-term trend. LOESS fits each time point and its neighboring data using locally weighted regression. The weighting function is calculated as follows:

[0021]

[0022] In the formula: For time points The normalized distance from the current point is calculated; then, the trend term is subtracted from the original sequence to obtain the detrended sequence. The data were grouped by month, and the LOESS algorithm was applied to fit seasonal fluctuations to extract the seasonal component. Then, the trend term and seasonal term are subtracted from the original sequence to obtain the residual term. Finally, for the residual terms Linear interpolation is performed on the missing values ​​in the data, and then compared with the trend term. and seasonal items Add them together to reconstruct the complete sequence. The specific calculation process is as follows:

[0023]

[0024] In the formula: This is the residual term after interpolation.

[0025] The solution further involves the following steps: After the rainfall sequence features are input into the model, they are sequentially processed through the CNN input layer, spatial attention layer, long short-term memory layer, temporal attention layer, and fully connected output layer. The fully connected output layer outputs a probability distribution vector of the flood inundation category, and the category with the highest probability is selected as the final flood inundation category based on the distribution vector.

[0026] The CNN input layer simplifies and reconstructs the feature data, using abstract features from different times as vectors to form new time-series rainfall data, which serves as input to the spatial attention module to learn internal dynamic patterns. Specifically, the rainfall sequence feature data first passes through a one-dimensional convolutional layer with 3 kernels, maintaining the same feature vector length after convolution. Then, it passes through a max pooling layer with a 2x1 pooling window with a stride of 2, followed by another one-dimensional convolutional layer and a max pooling layer. Finally, it passes through a fully connected layer to output a feature matrix containing local rainfall features and time steps.

[0027] The spatial attention layer dynamically weights the features of the input time-series rainfall data to improve robustness to different rainfall patterns; it divides the feature matrix into feature vectors containing local rainfall features at a number of time steps. After the feature vectors are calculated by a single layer of neurons, they are activated by the Sigmoid function and then normalized using the Softmax function.

[0028] The Long Short-Term Memory (LSTM) layer consists of a forget gate, an input gate, and an output gate. Entering the forget gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1, determining how much information from the previous cell state is retained or forgotten. Entering the input gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1. Simultaneously, the result of the normalization operation is processed by the tanh function to generate a new candidate value, representing new information that may be added to long-term memory. Next, the long-term memory input data is multiplied by the vector generated by the forget gate, and then the product of the vector generated by the input gate and the candidate value is added to obtain the long-term memory output. Entering the output gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1, and the long-term memory output is processed by the tanh function. Finally, the data passing through the output gate is multiplied by the value obtained from the long-term memory output processed by the tanh function to obtain the hidden state at the current time step.

[0029] The temporal attention layer and fully connected output layer are as follows: When the spatial attention layer gradually injects weighted sequence data into the long short-term memory layer units, the hidden state output sequence re-enters the temporal attention layer. After ReLU activation and Softmax normalization, temporal attention weights are generated. Based on the temporal attention weights, the hidden states of all time steps are weighted and fused to output a condensed temporal context vector. Then, the attention context vector enters a fully connected layer. Finally, it is activated by the softmax function and outputs the probability distribution vectors of four categories. The category with the highest probability is selected from the distribution vectors as the final flood category and output by the output layer.

[0030] The scheme is further defined as follows: the number of months in the collection area is at least 20 times the number of months in the determined period; in step 5, the initial selection of a period of 24 months is defined as follows.

[0031] Compared with the prior art, the beneficial technical effects of the present invention using the above technical solution are as follows:

[0032] This invention fully utilizes rainfall observation data from rain gauge stations. By comparing the output of the prediction model with the known classification of the predicted monthly data, the optimal rainfall sequence features are selected as input into the prediction model. Combined with flood season monitoring platforms, the inundation range of floods is determined, constructing a high-quality, multi-source fusion flood prediction dataset. This provides accurate sample labels for model training, effectively supporting the subsequent training and validation of the flood prediction model. Compared to traditional methods, this invention achieves higher prediction accuracy, reducing estimation errors by approximately 51%, 8.3%, and 12.5% ​​compared to ARIMA, LSTM, and Transformer, respectively. Furthermore, it exhibits lower inference latency, meeting the real-time and computational efficiency requirements of flood early warning systems. In addition, the model enhances interpretability through a dual attention mechanism, enabling the identification of key rainfall patterns and impact periods, and demonstrating good robustness to missing data and noise. In summary, this invention can effectively predict whether a flood will occur and the inundation level, possessing significant academic and applied value for refining flood early warning research.

[0033] The invention will be further explained in detail below with reference to the accompanying drawings and specific embodiments. Attached Figure Description

[0034] Figure 1 This is a flowchart of the network model data processing of the present invention;

[0035] Figure 2 For training loss and accuracy graphs. Detailed Implementation

[0036] A flood prediction method based on multi-scale temporal modeling is used to predict floods in a region. It acquires rainfall data monitored by meteorological stations for a predetermined number of months prior to the prediction month. This predetermined number of months is determined during the construction of the flood prediction model. The rainfall data is processed to form a chronological rainfall sequence. This rainfall sequence is used as a feature input to the flood prediction model, which outputs the inundation level, thus forming a flood prediction for the region in the prediction month. The flood prediction model is a neural network flood prediction model composed of a CNN input layer, a spatial attention layer, a long short-term memory layer (or LSTM temporal recurrent layer), a temporal attention layer, and a fully connected output layer. The process of determining the predetermined number of months includes:

[0037] Step 1: Collect precipitation data from meteorological stations in the region that are several times the number of months in the specified area, and compile the precipitation data into a rainfall sequence in chronological order;

[0038] Step 2: Annotate the rainfall sequence based on hydrological thresholds or flood inundation records to generate a precipitation dataset with flood occurrence classification;

[0039] Step 3: Process the precipitation dataset: This includes interpolating missing values ​​in the dataset and removing abnormal data caused by equipment malfunction or recording errors;

[0040] Step 4: Divide the processed precipitation dataset into training set, validation set and test set according to time order. The training set is used for model parameter learning, the validation set is used for model parameter tuning, and the test set is used to test the final effect of the model. The ratio of the training set, validation set and test set is 7:1:2.

[0041] Step 5: Select one month from the training or validation set of the precipitation dataset as the prediction target month with a known classification, and select the rainfall sequence data features formed by a preliminary segment of rainfall data from months prior to the prediction target month; input the rainfall sequence data features of the segment of months into the flood prediction model, and the flood prediction model outputs the probability distribution vector of the flood inundation category, and select the category with the maximum probability from the distribution vector as the final flood inundation category;

[0042] Step 6: Compare the category containing the maximum and minimum probability values ​​in the probability distribution vector with the known classification of the target month to determine whether the probability distribution vector of the flood inundation category output by the flood prediction model is close to the known classification of the target month.

[0043] Step 7: If the comparison results are close, the selected period of months that is close is the determined period of months. If the comparison results are not close, the length of the selected period of months is adjusted, and the rainfall sequence data features are formed by selecting rainfall data of the adjusted period of months before the month of the prediction target. The rainfall sequence data features of the adjusted period of months are input into the flood prediction model, and the flood prediction model outputs the probability distribution vector of the flood inundation category. The process returns to step 6 until the determined period of months is determined.

[0044] In the above method: the number of months in the collection area is at least 20 times the number of months; in step 5, the initial selection of a period of 24 months.

[0045] In step 6, whether the comparison is close or not is determined by setting a percentage threshold. If the comparison result reaches the set percentage threshold, it is considered to be close or not. The percentage threshold is not less than 80% and is initially set to 95%.

[0046] The method further includes recording the number of adjustments made for a selected period of months. If the adjustment still fails to reach a similar level after a limited number of adjustments, the percentage threshold is adjusted. If the percentage threshold is adjusted to below 80%, the obtained rainfall data is considered not to support the flood prediction model.

[0047] The method further includes: if the percentage threshold is adjusted to be lower than 80%, the parameters of the neural network flood prediction model are adjusted; if the parameters still do not approach the threshold after adjustment, the obtained rainfall data is considered not to support the flood prediction model prediction.

[0048] In step 3, the interpolation of missing values ​​in the dataset is performed using STL decomposition. The formula for STL decomposition is:

[0049]

[0050] In the formula: This is the original rainfall sequence; This is a trend item; For seasonal items; For residual terms;

[0051] The STL decomposition steps are as follows: First, smooth the original sequence using LOESS with a window size of 12 months to extract the long-term trend. LOESS fits each time point and its neighboring data using locally weighted regression. The weighting function is calculated as follows:

[0052]

[0053] In the formula: For time points The normalized distance from the current point is calculated; then, the trend term is subtracted from the original sequence to obtain the detrended sequence. The data were grouped by month, and the LOESS algorithm was applied to fit seasonal fluctuations to extract the seasonal component. Then, the trend term and seasonal term are subtracted from the original sequence to obtain the residual term. Finally, for the residual terms Linear interpolation is performed on the missing values ​​in the data, and then compared with the trend term. and seasonal items Add them together to reconstruct the complete sequence. The specific calculation process is as follows:

[0054]

[0055] In the formula: This is the residual term after interpolation.

[0056] Typically, datasets contain approximately 1% missing monthly data (monthly rainfall of 0), primarily concentrated in earlier periods (such as the 1980s) when monitoring equipment was out of service. These missing values ​​can significantly impact model training and prediction, thus requiring scientific methods for data restoration. This example uses Seasonal-Trend Decomposition (STL decomposition) to interpolate the missing values. STL (Seasonal and Trend decomposition using Loess) is a statistical method that decomposes a time series into seasonal, trend, and residual terms. Its core idea is to extract the long-term trend, periodic fluctuations, and random noise from the series using sliding window locally weighted regression (LOESS).

[0057] In this embodiment: After the rainfall sequence data features are input, they are processed sequentially through the CNN input layer, spatial attention layer, long short-term memory layer, temporal attention layer and fully connected output layer. The fully connected output layer outputs the probability distribution vector of the flood inundation category, and the category with the maximum probability is selected as the final flood inundation category based on the distribution vector.

[0058] The CNN input layer simplifies and reconstructs the feature data, using abstract features from different times as vectors to form new time-series rainfall data, which serves as input to the spatial attention module to learn internal dynamic patterns. Specifically, the rainfall sequence feature data first passes through a one-dimensional convolutional layer with 3 kernels, maintaining the same feature vector length after convolution. Then, it passes through a max pooling layer with a 2x1 pooling window with a stride of 2, followed by another one-dimensional convolutional layer and a max pooling layer. Finally, it passes through a fully connected layer to output a feature matrix containing local rainfall features and time steps.

[0059] The spatial attention layer dynamically weights the features of the input time-series rainfall data to improve robustness to different rainfall patterns; it divides the feature matrix into feature vectors containing local rainfall features at a number of time steps. After the feature vectors are calculated by a single layer of neurons, they are activated by the Sigmoid function and then normalized using the Softmax function.

[0060] The Long Short-Term Memory (LSTM) layer consists of a forget gate, an input gate, and an output gate. Entering the forget gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1, determining how much information from the previous cell state is retained or forgotten. Entering the input gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1. Simultaneously, the result of the normalization operation is processed by the tanh function to generate a new candidate value, representing new information that may be added to long-term memory. Next, the long-term memory input data is multiplied by the vector generated by the forget gate, and then the product of the vector generated by the input gate and the candidate value is added to obtain the long-term memory output. Entering the output gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1, and the long-term memory output is processed by the tanh function. Finally, the data passing through the output gate is multiplied by the value obtained from the long-term memory output processed by the tanh function to obtain the hidden state at the current time step.

[0061] The temporal attention layer and fully connected output layer are as follows: When the spatial attention layer gradually injects weighted sequence data into the long short-term memory layer units, the hidden state output sequence re-enters the temporal attention layer. After ReLU activation and Softmax normalization, temporal attention weights are generated. Based on the temporal attention weights, the hidden states of all time steps are weighted and fused to output a condensed temporal context vector. Then, the attention context vector enters a fully connected layer. Finally, it is activated by the softmax function and outputs the probability distribution vectors of four categories. The category with the highest probability is selected from the distribution vectors as the final flood category and output by the output layer.

[0062] As a neural network, such as Figure 1 As shown, the CNN input layer receives rainfall sequence data for a specified number of months as input features, with an input feature dimension of 1. The convolutional layer contains two one-dimensional convolutional layers (ReLU activation function) and two max pooling layers to extract temporal and spatial features from the time series. The features output from the convolutional and pooling layers are mapped to the hidden space, and the two-dimensional spatiotemporal feature matrix output by the fully connected layer is denoted as... ,in This represents the number of features in a single time step. It is the number of time steps.

[0063] The specific calculations are as follows:

[0064]

[0065]

[0066]

[0067]

[0068]

[0069] In the formula, It is an input vector. The input includes timestamps. And the rainfall for all months of that year. and These are the outputs of the two convolutional layers. and These are the outputs of two pooling layers. It is a weight matrix. ⊗ is the bias variable, and ⊗ is the convolution operation.

[0070] A spatial attention mechanism is introduced before the LSTM input, specifically calculated as follows:

[0071]

[0072]

[0073]

[0074] In the formula, This represents the feature vector at time step t; (i=1,2...m) represents the i-th eigenvalue at the t-th time step; It is a spatial attention function; It is the attention weight vector at time step t; (i=1,2...m) is the weight of the i-th feature at the t-th time step; This represents element-wise multiplication.

[0075] After computation of a single layer of neurons, the input feature vector is processed by the Sigmoid function: Activate, then use the Softmax function: Normalization is performed to ensure the finite additivity of the weights.

[0076] The weighted feature sequence is input into the LSTM network. To fully utilize the spatiotemporal information of the input, this embodiment improves the attention mechanism of the original LSTM. Spatial weights (or feature weights) are first dynamically assigned to the input features in a single time step. Then, by fully utilizing the hidden state of the LSTM at each step, temporal attention weights are assigned to the hidden state of each time step. In this paper, rainfall is used as the input feature, and the weights of spatial and temporal attention affect the input and output of the LSTM unit. With the help of the spatial attention module and the temporal attention module, this improvement can dynamically adjust the attention weights and improve the performance of the LSTM unit. The specific calculation is as follows:

[0077]

[0078] In the formula, the unit state The calculation is as follows:

[0079]

[0080] In the formula, the previous hidden layer state The calculation is as follows:

[0081]

[0082] Forgetting coefficient Generated and determined by the forget gate. exist The value maintained in the middle is calculated as follows:

[0083]

[0084] Output coefficient of the output gate Responsible for controlling the final output of the network. The specific calculations are as follows:

[0085]

[0086]

[0087] In the formula, , , , These are the information for the forget gate, input gate, and output gate of the model, respectively. Candidate values ​​represent new information that may be added to long-term memory. , , , These represent the weights of the hidden layer states of the forget gate, input gate, and output gate in the model structure, respectively. , , , These represent the biases of the hidden layer states of the forget gate, input gate, and output gate of the structure, respectively. This represents the hidden layer state at time t-1. This is the input vector for the model.

[0088] Obtain the hidden state output sequence A time attention mechanism is introduced to calculate the weights of each time step: After ReLU activation and Softmax normalization, temporal attention weights are generated and then weighted and summed. .

[0089] Dropout regularization is introduced into the network with a Dropout Rate of 0.2, and combined with L2 regularization (weight decay of 1e-5) to prevent overfitting.

[0090] The model was trained using the Adam optimizer with a learning rate of 0.001, momentum parameters β1 = 0.9 and β2 = 0.999, and a batch size of 32. The loss function was the multi-class cross-entropy loss. Early stopping was used to prevent overfitting; training was stopped when the validation set loss function value did not decrease significantly (less than 1e-4) over 10 consecutive epochs. The model parameters were initialized using He Normal to accelerate convergence.

[0091] The multi-class cross-entropy loss is calculated as follows:

[0092] In the formula, It is an integer index of the real category. Yes, the model predicts that the sample belongs to a category. For the probability, training loss, and accuracy, see [link to relevant documentation]. Figure 2 .

[0093] The model performance was evaluated using accuracy, recall, F1 score, and inference latency as performance metrics. Performance comparisons were conducted on flood prediction tasks based on ARIMA, LSTM, Transformer models, and the method described in this embodiment. The results are shown in Table 1.

[0094] Confusion matrix:

[0095]

[0096]

[0097] Diagonal line: Correct prediction; Off-diagonal line: Misjudgment. For example, E32 indicates that the actual value is severe flooding, but the predicted value is moderate flooding.

[0098] Accuracy:

[0099]

[0100] Recall is expressed as the number of correctly predicted samples divided by the total number of samples predicted to belong to that class.

[0101]

[0102] Recall represents the proportion of samples correctly identified by the model within a given real-world flooding level, reflecting the model's ability to capture scenarios at that level. For example, in the severe flooding category, This indicates the number of correctly predicted items within that category. The total F1 score for this category:

[0103] The F1 score is a combined metric of precision and recall, used to measure a model’s overall ability to identify false positives and false negatives at a given level of flooding.

[0104]

[0105] Macro average:

[0106] Considering the overall prediction performance of the four categories, a macro average is used to obtain the overall precision, recall, and F1 score.

[0107]

[0108] In the formula, For the correct prediction number, , For the discrepancy between actual and predicted quantities, This represents the total number of samples.

[0109] Table 1 Performance comparison of this embodiment with other models

[0110]

[0111] This embodiment fully utilizes rainfall observation data from rain gauge stations and combines it with flood season monitoring platforms to determine the inundation range of floods, constructing a high-quality, multi-source fusion flood prediction dataset. This provides accurate sample labels for model training, effectively supporting the subsequent training and validation of the flood prediction model. The model enhances interpretability through a dual attention mechanism, can identify key rainfall patterns and impact periods, and exhibits good robustness to missing data and noise.

Claims

1. A flood prediction method based on multi-scale time modeling, for predicting floods within a region, characterized in that, Rainfall data monitored by meteorological stations in the region for a certain number of months prior to the predicted month is obtained. The determined number of months is determined during the construction of the flood prediction model. The rainfall data is processed to form a rainfall sequence in chronological order. The rainfall sequence is used as the feature input of the rainfall sequence data to construct the flood prediction model. The flood prediction model outputs the inundation degree of the flood, forming a flood prediction for the predicted month in the region. The flood prediction model is a neural network flood prediction model composed of a CNN input layer, a spatial attention layer, a long short-term memory layer, a temporal attention layer, and a fully connected output layer. The process of determining the number of months includes: Step 1: Collect precipitation data from meteorological stations in the region that are several times the number of months in the specified area, and compile the precipitation data into a rainfall sequence in chronological order; Step 2: Annotate the rainfall sequence based on hydrological thresholds or flood inundation records to generate a precipitation dataset with flood occurrence classification; Step 3: Process the precipitation dataset: This includes interpolating missing values ​​in the dataset and removing abnormal data caused by equipment malfunction or recording errors; Step 4: Divide the processed precipitation dataset into training set, validation set and test set according to time order. The training set is used for model parameter learning, the validation set is used for model parameter adjustment, and the test set is used to test the final effect of the model. Step 5: Select one month from the training or validation set of the precipitation dataset as the prediction target month with a known classification, and select the rainfall sequence data features formed by a preliminary segment of rainfall data from months prior to the prediction target month; input the rainfall sequence data features of the segment of months into the flood prediction model, and the flood prediction model outputs the probability distribution vector of the flood inundation category, and select the category with the maximum probability from the distribution vector as the final flood inundation category; Step 6: Compare the category containing the maximum and minimum probability values ​​in the probability distribution vector with the known classification of the target month to determine whether the probability distribution vector of the flood inundation category output by the flood prediction model is close to the known classification of the target month. Step 7: If the comparison results are close, the selected period of months that is close is the determined period of months. If the comparison results are not close, the length of the selected period of months is adjusted, and the rainfall sequence data features are formed by selecting rainfall data of the adjusted period of months before the month of the prediction target. The rainfall sequence data features of the adjusted period of months are input into the flood prediction model, and the flood prediction model outputs the probability distribution vector of the flood inundation category. The process returns to step 6 until the determined period of months is determined.

2. The flood prediction method according to claim 1, characterized in that, In step 6, whether the comparison is close or not is determined by setting a percentage threshold. If the comparison result reaches or exceeds the set percentage threshold, it is considered to be close or not. The percentage threshold is not less than 80% and is initially set to 95%.

3. The flood prediction method according to claim 2, characterized in that, The method further includes recording the number of adjustments for a selected period of months. If a finite number of adjustments are made and the target still does not approach the target, a percentage threshold is adjusted. If the percentage threshold is adjusted to below 80%, the obtained rainfall data is considered not to support the flood prediction model.

4. The flood prediction method according to claim 3, characterized in that, The method further includes: if the percentage threshold is adjusted to be lower than 80%, the parameters of the neural network flood prediction model are adjusted; if the parameters still do not approach the threshold after adjustment, the obtained rainfall data is considered not to support the flood prediction model prediction.

5. The flood prediction method according to claim 1, characterized in that, The ratio of the training set, validation set, and test set is 7:1:

2.

6. The flood prediction method according to claim 1, characterized in that, In step 3, the interpolation of missing values ​​in the dataset is performed using STL decomposition. The formula for STL decomposition is: In the formula: This is the original rainfall sequence; This is a trend item; For seasonal items; For residual terms; The STL decomposition steps are as follows: First, smooth the original sequence using LOESS with a window size of 12 months to extract the long-term trend. LOESS fits each time point and its neighboring data using locally weighted regression. The weighting function is calculated as follows: In the formula: For time points The normalized distance from the current point is calculated; then, the trend term is subtracted from the original sequence to obtain the detrended sequence. The data were grouped by month, and the LOESS algorithm was applied to fit seasonal fluctuations to extract the seasonal component. Then, the trend term and seasonal term are subtracted from the original sequence to obtain the residual term. Finally, for the residual terms Linear interpolation is performed on the missing values ​​in the data, and then compared with the trend term. and seasonal items Add them together to reconstruct the complete sequence. The specific calculation process is as follows: In the formula: This is the residual term after interpolation.

7. The flood prediction method according to claim 1, characterized in that, After the rainfall sequence features are input into the model, they are processed sequentially through the CNN input layer, spatial attention layer, long short-term memory layer, temporal attention layer and fully connected output layer. The fully connected output layer outputs the probability distribution vector of the flood inundation category, and the category with the maximum probability is selected as the final flood inundation category based on the distribution vector. The CNN input layer simplifies and reconstructs the feature data, using abstract features from different times as vectors to form new time-series rainfall data, which serves as input to the spatial attention module to learn internal dynamic patterns. Specifically, the rainfall sequence feature data first passes through a one-dimensional convolutional layer with 3 kernels, maintaining the same feature vector length after convolution. Then, it passes through a max pooling layer with a 2x1 pooling window with a stride of 2, followed by another one-dimensional convolutional layer and a max pooling layer. Finally, it passes through a fully connected layer to output a feature matrix containing local rainfall features and time steps. The spatial attention layer dynamically weights the features of the input time-series rainfall data to improve robustness to different rainfall patterns; it divides the feature matrix into feature vectors containing local rainfall features at a number of time steps. After the feature vectors are calculated by a single layer of neurons, they are activated by the Sigmoid function and then normalized using the Softmax function. The Long Short-Term Memory (LSTM) layer consists of a forget gate, an input gate, and an output gate. Entering the forget gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1, determining how much information from the previous cell state is retained or forgotten. Entering the input gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1. Simultaneously, the result of the normalization operation is processed by the tanh function to generate a new candidate value, representing new information that may be added to long-term memory. Next, the long-term memory input data is multiplied by the vector generated by the forget gate, and then the product of the vector generated by the input gate and the candidate value is added to obtain the long-term memory output. Entering the output gate, the result of the normalization operation is processed by the sigmoid function to generate a vector between 0 and 1, and the long-term memory output is processed by the tanh function. Finally, the data passing through the output gate is multiplied by the value obtained from the long-term memory output processed by the tanh function to obtain the hidden state at the current time step. The temporal attention layer and fully connected output layer are as follows: When the spatial attention layer gradually injects weighted sequence data into the long short-term memory layer units, the hidden state output sequence re-enters the temporal attention layer. After ReLU activation and Softmax normalization, temporal attention weights are generated. Based on the temporal attention weights, the hidden states of all time steps are weighted and fused to output a condensed temporal context vector. Then, the attention context vector enters a fully connected layer. Finally, it is activated by the softmax function and outputs the probability distribution vectors of four categories. The category with the highest probability is selected from the distribution vectors as the final flood category and output by the output layer.

8. The flood prediction method according to claim 1, characterized in that, In step 1: the number of months in the collection area is at least 20 times the number of months; in step 5, the initial selection of a period of 24 months.