Water quality data season identification method and system
By combining the rules of the lunar calendar and the K-nearest neighbor machine learning model, dynamic seasonal identification of water quality data is achieved, which solves the problem that the division of seasons by Gregorian calendar months is not adapted to China's climate change, and realizes more accurate seasonal identification and intelligent management of water affairs system.
Patent Information
- Application Number
- CN202511432807.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2025-09-19
- Filing Date
- 2025-10-09
- Publication Date
- 2026-01-02
AI Technical Summary
Traditional methods of dividing seasons into Gregorian calendar months cannot accurately reflect the hydro-climate characteristics of China's monsoon climate, leading to biased predictions and inaccurate scheduling decisions in water management system models. This lack of scientific rigor, coupled with the absence of real-time monitoring of key climate variables such as precipitation intensity, evaporation rate, and air humidity, results in inaccurate data.
A seasonal coding method based on the Chinese lunar calendar solar terms is adopted, combined with a K-nearest neighbor machine learning model, to reconstruct and segment the water quality dataset, train the initial seasonal identification model for all four seasons, and optimize the seasonal identification model through dual-model prediction of seasonal transition intervals to achieve dynamic seasonal identification.
It improves the accuracy of seasonal identification, adapts to China's unique climate change, enhances the intelligent management level and operational efficiency of the water system, and supports scientific decision-making in smart water scenarios such as water supply scheduling, sewage treatment, source water monitoring, and intelligent operation and maintenance.
Smart Images

Figure CN121256296A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of water quality data analysis and processing technology, and in particular to a method and system for seasonal identification of water quality data. Background Technology
[0002] Against the backdrop of the rapid development of smart water management, urban water supply, sewage treatment, and rainwater harvesting systems have accumulated massive amounts of high-frequency, multi-dimensional operational data. This data encompasses key indicators such as timestamps, water temperature, pH value, turbidity, conductivity, liquid level, pressure, and energy consumption, exhibiting significant seasonal characteristics. Accurate seasonal identification is crucial for improving the operational efficiency of water management systems and ensuring water quality safety. In other words, improving the operational efficiency and ensuring water quality safety of water management systems highly depend on in-depth analysis, modeling, and prediction of this data.
[0003] However, in practical applications, the system's operating parameters exhibit significant seasonal fluctuations due to the cyclical changes in natural climate. For example, low temperatures in winter can inhibit the efficiency of biochemical treatment, snowmelt in spring or the beginning of the rainy season can easily cause pipeline overload, peak water consumption in summer can exacerbate water supply pressure, and autumn droughts may affect the stability of water supply. Therefore, accurately identifying the actual seasonal conditions corresponding to the data is a core prerequisite for building effective models and making scientific scheduling decisions.
[0004] Traditional water data analysis typically uses fixed Gregorian calendar months to divide seasons: March-May for spring, June-August for summer, September-November for autumn, and December-February for winter. However, this method has a significant drawback: it fails to consider the hydro-climatic characteristics of China's monsoon climate. Specifically, my country's monsoon rainfall is concentrated and extremely unevenly distributed in time and space, easily triggering sudden high pollution loads, long-term concentration effects, secondary algal pollution, and sediment carrying effects, leading to drastic changes in water quality. The intensity, frequency, and complexity of these changes far exceed those in temperate maritime climate regions. Furthermore, the traditional division method severs the dynamic coupling between hydrological processes and climatic elements, failing to accurately reflect the true seasonal characteristics of water quality in a given year. This ultimately results in biased model predictions, inaccurate scheduling decisions, and insufficient scientific rigor.
[0005] Furthermore, key climate variables such as precipitation intensity, evaporation rate, and air humidity are difficult to monitor in real time. However, the lunar calendar, closely aligned with China's hydrological and climatic patterns, can serve as a proxy for these key climate variables, helping models to more accurately pinpoint actual climate turning points for the year. Therefore, there is an urgent need to establish a dynamic seasonal identification method that integrates the lunar calendar to improve the intelligent management level and operational efficiency of water management systems. Summary of the Invention
[0006] This invention provides a method and system for seasonal identification of water quality data, solving the problem of dynamic seasonal identification of real-time water quality data.
[0007] According to one aspect of the present invention, a method for seasonal identification of water quality data is provided. The method includes: acquiring a dataset containing water quality samples from different times, wherein each water quality sample contains water quality parameters closely related to seasonal changes and the Gregorian calendar time in which the water quality parameters were collected; for any water quality sample, determining a seasonal code and a time parameter for the water quality parameters in the water quality sample based on the Gregorian calendar time in the water quality sample, wherein the seasonal code includes spring code, summer code, autumn code, winter code for known seasons, and a code to be identified for unknown seasons; reconstructing and segmenting the dataset based on the seasonal code and time parameter of each water quality sample in the dataset to obtain a known season dataset and an unknown season dataset, wherein each new water quality sample in the known season dataset and the unknown season dataset contains a seasonal code, a time parameter, and a water quality parameter; and utilizing the existing data... The known seasonal dataset is used to train the seasonal identification model, resulting in initial seasonal identification models for spring, summer, autumn, and winter. From these initial seasonal identification models, a suitable initial seasonal identification model is selected for each new water quality sample in the unknown seasonal dataset. Using the selected initial seasonal identification model, seasonal identification is performed on each new water quality sample in the unknown seasonal dataset to obtain a predicted code. The new water quality samples from the known seasonal dataset and the newly coded water quality samples are then integrated into a dataset with complete known seasonal codes. Using this dataset with complete known seasonal codes, the initial seasonal identification models for spring, summer, autumn, and winter are optimized to predict seasonal codes for the latest unknown seasonal water quality parameters.
[0008] Preferably, the water quality parameters closely related to seasonal changes include influent temperature reflecting climate seasonality, influent turbidity reflecting seasonal changes in water quality, and influent conductivity reflecting seasonal fluctuations in ion concentration.
[0009] Preferably, for any water quality sample, determining the seasonal code and time parameter for the water quality parameters based on the Gregorian calendar time in the water quality sample includes: for any water quality sample, determining the solar term Gregorian calendar period to which the Gregorian calendar time in the water quality sample belongs according to the seasonal coding rules, so as to obtain the season and seasonal code determined by the solar term Gregorian calendar period; determining the difference in the number of days between the Gregorian calendar time in the water quality sample and January 1 of the current year as the time parameter; wherein, the seasonal coding rules include: defining the solar term Gregorian calendar period corresponding to the beginning of spring to the Grain Rain solar term each year as spring, and setting the spring code; defining the solar term Gregorian calendar period corresponding to the beginning of summer to the Great Heat solar term each year as summer, and setting the summer code; defining the solar term Gregorian calendar period corresponding to the beginning of autumn to the Frost's Descent solar term each year as autumn, and setting the autumn code; defining the solar term Gregorian calendar period corresponding to the beginning of winter to the Great Cold solar term of the following year as winter, and setting the winter code; defining the remaining solar term Gregorian calendar period as an unknown season, and setting the code to be identified.
[0010] Preferably, the step of reconstructing and segmenting the dataset based on the seasonal code and time parameter of each water quality sample in the dataset to obtain a known seasonal dataset and an unknown seasonal dataset includes: obtaining the water quality parameters of each water quality sample from the dataset; combining the water quality parameters of each water quality sample in the dataset with its seasonal code and time parameter to obtain a new water quality sample, thereby obtaining a reconstructed dataset formed by all the new water quality samples; and segmenting the reconstructed dataset into the known seasonal dataset and the unknown seasonal dataset according to whether the seasonal code of each new water quality sample is a code of a known season or a code to be identified for an unknown season.
[0011] Preferably, the step of training the seasonal recognition model using the known seasonal dataset to obtain initial seasonal recognition models corresponding to spring, summer, autumn, and winter includes: For spring, constructing a binary classification label for identifying spring, and using the time parameters and water quality parameters in the known seasonal dataset as features, and the binary classification label for identifying spring as the target, training the seasonal recognition model to obtain the initial seasonal recognition model corresponding to spring, wherein the label is set to 1 when the seasonal code of each new water quality sample in the known seasonal dataset is the spring code, otherwise the label is set to 0; For summer, constructing a binary classification label for identifying summer, and using the time parameters and water quality parameters in the known seasonal dataset as features, and the binary classification label for identifying summer as the target, training the seasonal recognition model to obtain the initial seasonal recognition model corresponding to summer, wherein the seasonal code of each new water quality sample in the known seasonal dataset is the summer code. During encoding, the label is set to 1 otherwise; for autumn, a binary classification label for identifying autumn is constructed, and the time parameters and water quality parameters in the known seasonal dataset are used as features, with the binary classification label for identifying autumn as the target. The seasonal identification model is trained to obtain an initial seasonal identification model corresponding to autumn. Specifically, when the seasonal code of each new water quality sample in the known seasonal dataset is the autumn code, the label is set to 1; otherwise, the label is set to 0. For winter, a binary classification label for identifying winter is constructed, and the time parameters and water quality parameters in the known seasonal dataset are used as features, with the binary classification label for identifying winter as the target. The seasonal identification model is trained to obtain an initial seasonal identification model corresponding to winter. Specifically, when the seasonal code of each new water quality sample in the known seasonal dataset is the winter code, the label is set to 1; otherwise, the label is set to 0. The seasonal identification model employs a K-nearest neighbor machine learning model.
[0012] Preferably, the step of selecting a suitable initial seasonal identification model for each new water quality sample in the unknown seasonal dataset from the trained initial seasonal identification models corresponding to spring, summer, autumn, and winter includes: dividing each new water quality sample in the unknown seasonal dataset into a corresponding seasonal transition subset according to the Gregorian calendar time corresponding to each new water quality sample in the unknown seasonal dataset; the seasonal transition subset includes the spring-summer transition subset corresponding to Grain Rain and before Summer Begins each year, the summer-autumn transition subset corresponding to Great Heat and before Autumn Begins each year, the autumn-winter transition subset corresponding to Frost's Descent and before Winter Begins each year, and the winter-spring transition subset corresponding to Great Cold and before Spring Begins each year; selecting initial seasonal identification models corresponding to spring and summer for the spring-summer transition subset, initial seasonal identification models corresponding to summer and autumn for the summer-autumn transition subset, initial seasonal identification models corresponding to autumn and winter for the autumn-winter transition subset, and initial seasonal identification models corresponding to winter and spring for the winter-spring transition subset.
[0013] Preferably, the step of using the initial seasonal identification model selected for each new water quality sample in the unknown seasonal dataset to perform seasonal identification for each new water quality sample in the unknown seasonal dataset and obtain a predicted code includes: for any seasonal transition subset, using the time parameters and water quality parameters in the seasonal transition subset as features, using the initial seasonal identification models corresponding to the two adjacent seasons selected for the seasonal transition subset, performing seasonal identification for each new water quality sample in the seasonal transition subset respectively, obtaining two output labels for each new water quality sample; and using the two output labels for each new water quality sample, determining a predicted code for each new water quality sample.
[0014] Preferably, the step of determining the predicted code for each new water quality sample using the two output labels of each new water quality sample includes: for any new water quality sample, if only one of the two output labels of the new water quality sample is 1 and is the output label of the initial seasonal identification model corresponding to the latter of the two adjacent seasons, then the seasonal code of the new water quality sample is determined to be the seasonal code of the latter of the two adjacent seasons; otherwise, the seasonal code of the new water quality sample is determined to be the seasonal code of the former of the two adjacent seasons.
[0015] According to another aspect of the present invention, the present invention also provides a water quality data seasonal identification system, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the water quality data seasonal identification method as described above.
[0016] This invention achieves dynamic identification of water quality data through seasonal coding, dataset reconstruction and segmentation, seasonal identification model training and seasonal identification, thereby improving the accuracy of seasonal identification. It solves the problems of inaccurate seasonal identification of water quality data caused by the incompatibility of the Gregorian calendar month division of seasons with China's unique climate change and the lack of key climate variables such as precipitation intensity, evaporation rate and air humidity. It can be widely applied to smart water management scenarios that require seasonal identification, such as water supply scheduling, sewage treatment, source water monitoring, intelligent operation and maintenance, and water quality prediction. Attached Figure Description
[0017] Figure 1 This is a flowchart of the water quality data seasonal identification method provided by the present invention.
[0018] Figure 2 This invention provides a method for seasonal identification of water resources data and a flowchart of its application. Detailed Implementation
[0019] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the embodiments described below are only for illustration and explanation of the present invention and are not intended to limit the present invention.
[0020] This invention is based on the Chinese lunar calendar's solar term rules (Spring begins with Lichun and Grain Rain, Summer begins with Lixia and Great Heat, Autumn begins with Liqiu and Frost's Descent, and Winter begins with Lidong and Great Cold), and combines relevant water quality parameters (or water quality characteristics) that are easily affected by the seasons, such as water temperature, water turbidity, and water conductivity. It uses a K-nearest neighbor machine learning model to achieve high-precision dynamic seasonal identification, which solves the problem that the Gregorian calendar's division of seasons is not adapted to China's climate change and that the lack of key climate variables such as precipitation intensity, evaporation rate, and air humidity leads to inaccurate seasonal identification of water quality data.
[0021] See Figure 1 The water quality data seasonal identification method provided by this invention includes the following steps: Step S101: Obtain a dataset containing water quality samples from different times, wherein each water quality sample contains water quality parameters closely related to seasonal changes and the Gregorian calendar time in which the water quality parameters were collected.
[0022] The water quality parameters that are closely related to seasonal changes include, but are not limited to, influent temperature reflecting climate seasonality, influent turbidity reflecting seasonal changes in water quality, and influent conductivity reflecting seasonal fluctuations in ion concentration.
[0023] Step S102: For any water quality sample, determine the seasonal code and time parameter for the water quality parameters in the water quality sample based on the Gregorian calendar time in the water quality sample.
[0024] For any water quality sample, the solar term period to which the Gregorian calendar time of the water quality sample belongs is determined according to the seasonal coding rules, so as to obtain the season and seasonal code determined by the solar term period. The seasonal coding rules include: defining the solar term period from the Beginning of Spring to Grain Rain as spring and setting the spring code; defining the solar term period from the Beginning of Summer to Great Heat as summer and setting the summer code; defining the solar term period from the Beginning of Autumn to Frost's Descent as autumn and setting the autumn code; defining the solar term period from the Beginning of Winter to Great Cold of the following year as winter and setting the winter code; and defining the remaining solar term periods as unknown seasons and setting the unidentified code. Obviously, the seasonal code determined by the solar term period should be one of the spring code, summer code, autumn code, winter code of the known season, or the unidentified code of the unknown season. For example, a water sample has a Gregorian calendar date of March 1, 2025. This date falls within the Gregorian calendar period corresponding to the solar terms from the Beginning of Spring to Grain Rain, therefore it is identified as spring, and the season code is specifically the spring code. Another water sample has a Gregorian calendar date of May 1, 2025. This date falls within the Gregorian calendar period between Grain Rain and the Beginning of Summer, therefore it is identified as an unknown season, and the season code is specifically the code to be identified.
[0025] For any water quality sample, calculate the difference in the number of days between the Gregorian calendar date in the water quality sample and January 1st of the current year, and determine this difference in days as the time parameter. For example, if the Gregorian calendar date in the water quality sample is January 31, 2025, and the difference in the number of days between it and January 1, 2025 is 30, then determine the difference of 30 days as the time parameter for that water quality sample.
[0026] Step S103: Based on the seasonal code and time parameters of each water quality sample in the dataset, the dataset is reconstructed and segmented to obtain known seasonal datasets and unknown seasonal datasets.
[0027] The water quality parameters of each water quality sample are obtained from the dataset, and the water quality parameters of each water quality sample in the dataset are combined with its seasonal code and time parameter to obtain a new water quality sample, thus obtaining a reconstructed dataset formed by all the new water quality samples. Then, according to whether the seasonal code of each new water quality sample is a code of a known season or a code to be identified for an unknown season, the reconstructed dataset is divided into a known season dataset and an unknown season dataset. Obviously, whether it is the known season dataset or the unknown season dataset, each new water quality sample should contain a seasonal code, a time parameter, and water quality parameters.
[0028] Step S104: Train the season recognition model using the known season dataset to obtain the initial season recognition models corresponding to spring, summer, autumn and winter respectively.
[0029] The seasonal recognition model of this invention employs a K-nearest neighbor machine learning model, performing four independent training iterations using the known seasonal dataset to obtain the initial seasonal recognition model corresponding to each of the four seasons. Specifically: For spring, a binary classification label for identifying spring is constructed. Using the time parameters and water quality parameters in the known seasonal dataset as features, and the binary classification label for identifying spring as the target, the K-nearest neighbor machine learning model is trained to obtain the initial seasonal identification model corresponding to spring. In this model, when the seasonal code of each new water quality sample in the known seasonal dataset is the spring code, the label is set to 1; otherwise, the label is set to 0.
[0030] For summer, a binary classification label for identifying summer is constructed, and the K-nearest neighbor machine learning model is trained using the time parameters and water quality parameters in the known seasonal dataset as features and the binary classification label for identifying summer as the target, to obtain the initial seasonal identification model corresponding to summer. In this model, the label is set to 1 when the seasonal code of each new water quality sample in the known seasonal dataset is summer, and otherwise the label is set to 0.
[0031] For autumn, a binary classification label for identifying autumn is constructed. Using the time parameters and water quality parameters in the known seasonal dataset as features, and the binary classification label for identifying autumn as the target, the K-nearest neighbor machine learning model is trained to obtain the initial seasonal identification model corresponding to autumn. In this model, the label is set to 1 when the seasonal code of each new water quality sample in the known seasonal dataset is autumn, and otherwise the label is set to 0.
[0032] For winter, a binary classification label for identifying winter is constructed, and the K-nearest neighbor machine learning model is trained using the time parameters and water quality parameters in the known seasonal dataset as features and the binary classification label for identifying winter as the target, to obtain the initial seasonal identification model corresponding to winter. In this model, the label is set to 1 when the seasonal code of each new water quality sample in the known seasonal dataset is the winter code, and otherwise the label is set to 0.
[0033] Step S105: Select a suitable initial seasonal identification model for each new water quality sample in the unknown seasonal dataset from the initial seasonal identification models corresponding to spring, summer, autumn and winter, which have been trained respectively.
[0034] Based on the Gregorian calendar date corresponding to each new water quality sample in the unknown seasonal dataset, each new water quality sample in the unknown seasonal dataset is divided into a corresponding seasonal transition subset. The seasonal transition subsets include the spring-summer transition subset corresponding to Grain Rain (after Grain Rain) and before Summer Begins (before Summer Begins) each year; the summer-autumn transition subset corresponding to Great Heat (after Great Heat) and before Autumn Begins (before Autumn Begins) each year; the autumn-winter transition subset corresponding to Frost's Descent (after Frost's Descent) and before Winter Begins (before Winter Begins) each year; and the winter-spring transition subset corresponding to Great Cold (after Great Cold) and before Spring Begins (before Spring Begins). Then, from the trained initial seasonal recognition models corresponding to each of the four seasons, initial seasonal recognition models corresponding to spring and summer are selected for the spring-summer transition subset; initial seasonal recognition models corresponding to summer and autumn are selected for the summer-autumn transition subset; initial seasonal recognition models corresponding to autumn and winter are selected for the autumn-winter transition subset; and initial seasonal recognition models corresponding to winter and spring are selected for the winter-spring transition subset.
[0035] In other words, this invention will use the initial seasonal identification model corresponding to adjacent two seasons to redetermine the seasonal code for each new water quality sample in the four seasonal transition subsets of the unknown seasonal dataset.
[0036] Step S106: Using the initial seasonal identification model selected for each new water quality sample in the unknown seasonal dataset, perform seasonal identification for each new water quality sample in the unknown seasonal dataset, obtain a predicted code, and integrate the new water quality samples in the known seasonal dataset and the new water quality samples that have obtained the predicted code into a dataset with a complete known seasonal code.
[0037] For any seasonal transition subset, using the time parameters and water quality parameters within the subset as features, and employing the initial seasonal identification models corresponding to the two adjacent seasons selected for the subset, seasonal identification is performed on each new water quality sample within the subset. This yields two output labels for each new water quality sample, and these two output labels are used to determine a predicted code for each sample. Specifically, for any new water quality sample, if only one of its two output labels is 1 and corresponds to the output label of the initial seasonal identification model corresponding to the latter of the two adjacent seasons, then the seasonal code of the new water quality sample is determined to be the seasonal code of the latter of the two adjacent seasons; otherwise, the seasonal code of the new water quality sample is determined to be the seasonal code of the former of the two adjacent seasons. Taking the spring-summer transition subset as an example, all new water quality samples in this subset are samples from the spring-summer transition period. The two adjacent seasons are spring and summer. When identifying the season, the time parameters and water quality parameters of these new water quality samples are used as features. The initial season identification model corresponding to spring is used to identify the season and output the first label. The initial season identification model corresponding to summer is used to identify the season and output the second label. If only the second label is 1, then it is determined to be summer, and the predicted code is summer code. Otherwise, it is determined to be spring, and the predicted code is spring code.
[0038] After obtaining the predicted code for each new water quality sample in the four seasonal transition subsets of the unknown seasonal dataset, the new water quality samples in the known seasonal dataset and each new water quality sample in the four seasonal transition subsets are integrated into a dataset with complete known seasonal codes. That is, the seasonal codes of all samples in this dataset are codes for known seasons.
[0039] Step S107: Using the dataset with complete known seasonal codes, optimize the initial seasonal identification models corresponding to spring, summer, autumn and winter respectively, so as to predict seasonal codes for the latest unknown seasonal water quality parameters.
[0040] Using the same method as in step S104, the initial seasonal identification models for spring, summer, autumn, and winter are trained again to optimize the model parameters of each initial seasonal identification model, resulting in optimized seasonal identification models for each season. In practical applications, if the Gregorian calendar time of the collected water quality parameters can directly determine whether it belongs to spring / summer / autumn / winter, then seasonal identification is not required. If the Gregorian calendar time of the collected water quality parameters determines that it belongs to a seasonal transition period, then the seasonal identification method used in step S106 is used to identify the season for the water quality parameter, obtaining the corresponding predictive code. This allows the seasonality and / or predictive code of the water quality parameter to be applied to smart water management scenarios requiring seasonal identification, such as water supply scheduling, sewage treatment, source water monitoring, intelligent operation and maintenance, and water quality prediction, making scheduling decisions in smart water management scenarios more scientific.
[0041] The following combination Figure 2 The present invention provides a more detailed description of the water data seasonal identification method and its application process.
[0042] Step S201: Import the dataset.
[0043] The format should be a pandas DataFrame (df), where the index should be of type DatetimeIndex, and the time frequency can be minutes, hours, or days; the remaining columns should be water quality parameters, namely influent temperature, influent turbidity, and influent conductivity, with the data type being float.
[0044] Step S202: Define the seasonal coding rules, divide the dynamic seasonal intervals, and assign a unique seasonal code to each interval; where 1-4 are the codes for the already determined seasons, and -1 is the code for the season to be determined.
[0045] The method for defining seasonal coding rules specifically involves defining the range of solar terms using Gregorian calendar dates, including: Spring Begins - Grain Rain: Spring season lasts from February 3 to April 21 each year (spring is coded as 1). Summer Solstice - Great Heat: May 5th to July 24th each year is summer (summer code is 2); Autumn Begins - Frost's Descent: Autumn lasts from August 7th to October 24th each year (Autumn is coded as 3). Winter Solstice - Major Cold: The period from November 7th to January 21st of the following year is winter (winter code is 4). Dynamic seasonal intervals: Intervals outside the above time periods are unknown seasons (the code to be identified is uniformly marked as -1, indicating that it is to be predicted).
[0046] It should be noted that the solar terms in the lunar calendar are determined based on the position of the sun on the ecliptic, are not affected by leap months in the lunar calendar, and their Gregorian calendar dates are relatively fixed.
[0047] Step S203: Calculate time parameters based on DatetimeIndex, use time parameters and water quality parameters as features, and seasonal coding as the target to reconstruct the dataset.
[0048] In step S203, the method for reconstructing the dataset may include the following steps: Step S203-1: Convert the Gregorian date of each water quality sample to the difference of days between that Gregorian date and January 1 of that year (Day of Year, DOY), which is used to reflect the relative position of that Gregorian date in the whole year.
[0049] Step S203-2: Obtain water quality parameters closely related to seasonal changes, including influent temperature (reflecting climate seasonality), influent turbidity (reflecting seasonal changes in water quality), and influent conductivity (reflecting seasonal fluctuations in ion concentration).
[0050] Step S203-3: Obtain the seasonal code of the water quality parameters, i.e., the seasonal code definition result in step S202.
[0051] Step S203-4: Combine the above three types of information into a unified dataset, which is to reconstruct the dataset.
[0052]
[0053] Wherein, season represents the seasonal code, doy represents the DOY value, temp represents the inlet water temperature, tur represents the inlet water turbidity, and con represents the inlet water conductivity.
[0054] Step S204: Based on the seasonal coding, split the reconstructed dataset into datasets with known seasons (coded as 1-4) and datasets with unknown seasons (coded as -1).
[0055] Step S205: Using the dataset of known seasons (coded as 1-4), train and optimize the parameters of the K-nearest neighbor machine learning model (or KNN model) to obtain four KNN season recognition models for spring, summer, autumn and winter.
[0056] Taking spring as an example, step S205 may include the following steps: Step S205-1: Construct a new binary label column, `label`, with the following numerical definition: If the seasonal code is spring code 1, then the label = 1; If the seasonal code is summer code 2, autumn code 3, and winter code 4, then the label = 0.
[0057] Step S205-2: Reconstruct the dataset of known seasons (coded as 1-4). Specifically, arrange the samples in the dataset of known seasons (coded as 1-4) according to the time sequence of DatetimeIndex to obtain the reconstructed dataset of known seasons (coded as 1-4).
[0058] Step S205-3: Through normalization, the numerical values of features in the reconstructed dataset of known seasons (coded as 1-4) are scaled to the range of 0-1, and the feature normalizer is saved so that the same normalization rules can be reused when processing new data.
[0059] The normalization process uses existing techniques, which will not be elaborated here.
[0060] Step S205-4: According to the time order, divide the normalized reconstructed dataset of known seasons (encoded as 1-4) into a training set (80%) and a test set (20%).
[0061] Step S205-5: Use Mahalanobis distance as a similarity measure:
[0062] in To obtain the covariance matrix of the samples in the training set, These are two samples from the training set.
[0063] Step S205-6: Based on the number of training samples Choose the K value:
[0064] in, This indicates rounding down to the nearest integer.
[0065] Step S205-7: Use the K value selected in step S205-6 and the distance metric selected in step S205-5 to train the KNN model on the training set, and make predictions on the test set to obtain the prediction results.
[0066] Step S205-8: Calculate the accuracy rate:
[0067] Step S205-9: Adjust the K value. Starting from the initial K value, gradually increase or decrease the K value, and repeat steps S205-7 and S205-8 until the accuracy is higher than 95%, thus obtaining the KNN seasonal recognition model for spring.
[0068] Using essentially the same steps as steps S205-1 to S205-9, KNN seasonal recognition models for summer, autumn, and winter are obtained respectively. The only difference is that the binary classification label column `label` constructed in step S205-1 is different when training the KNN seasonal recognition models for different seasons. For example, when training the KNN seasonal recognition model for summer, if the seasonal code is summer code 2, then the label `label` = 1; if the seasonal codes are spring code 1, autumn code 3, and winter code 4, then the label `label` = 0.
[0069] Step S206: Define the seasonal transition interval and associate the seasonal recognition models of the two adjacent seasons as a model combination. For example, January 21 to February 2 corresponds to the transition between winter and spring, and the associated model is the KNN seasonal recognition model of winter and spring.
[0070] In step S206, the steps of defining the seasonal transition interval and its model combination are as follows: The transition period between winter and spring (winter → spring): from the day after the Great Cold (e.g., January 22) to the day before the Beginning of Spring (e.g., February 2) each year, the corresponding model combination is the KNN seasonal recognition model for winter and spring; Spring-summer transition period (spring→summer): from the day after Grain Rain (e.g., April 22) to the day before Summer Solstice (e.g., May 4) each year, the corresponding model combination is the KNN seasonal recognition model for spring and summer; The transition period between summer and autumn (summer → autumn): from the day after the Great Heat (e.g., July 25) to the day before the Beginning of Autumn (e.g., August 6) each year, the corresponding model combination is the KNN seasonal recognition model for summer and autumn; The transition period between autumn and winter (autumn→winter): from the day after the first frost (e.g., October 25th) to the day before the start of winter (e.g., November 6th) each year, the corresponding model combination is the KNN seasonal recognition model for autumn and winter.
[0071] Step S207: Based on the seasonal transition interval, extract the time parameters and water quality parameters of each sample in the dataset of the unknown season (coded as -1), and use the adjacent KNN seasonal identification models to predict and compare them to generate the final seasonal code.
[0072] In step S207, the prediction and comparison method may include the following steps: Step S207-1: Based on the four seasonal transition intervals defined in step S206, filter the samples in the unknown season (coded as -1) dataset that fall into the four seasonal transition intervals to form the four seasonal transition subsets of the season to be determined. Step S207-2: For each seasonal transition interval, load the KNN seasonal recognition model for the two seasons before and after the seasonal transition interval for parallel prediction of the two models, and load the feature normalizer saved in step S205-3 to normalize the numerical values of the features in the seasonal transition subset.
[0073] Step S207-3: For samples within each seasonal transition interval, use the model of the previous season and the model of the next season to make predictions, and obtain the judgment results of the two models on whether the sample belongs to its own season.
[0074] Step S207-4: Combining the judgment results of the two models, determine the final season according to the following priority rules: If the model predicts a value of 1 only for the previous season, then it is determined to be the previous season; If the model predicts 1 only for the next season, then it is determined to be the next season; If both models predict 1, the previous season's prediction is preferred. If both models predict 0, the default is to determine it as the previous season.
[0075] Step S208: Update the encoding of the undetermined season in the dataset of the unknown season using the prediction results, and then integrate the updated dataset and the dataset of the determined season to obtain a complete seasonal encoding sequence that is consistent with the time order of the dataset imported in step S201.
[0076] Step S209: Export the results, with the index DatetimeIndex and the season column containing seasonal codes (only 1-4). The time frequency is consistent with the data imported in step S201.
[0077] Step S210: Optimize the four KNN seasonal recognition models for spring, summer, autumn and winter obtained in step S205 using the exported results.
[0078] Step S211: For the current calendar date that is in the transition period between seasons, determine the season of the current calendar date using the same method as in step S207, based on the water quality parameters collected on the current calendar date and the time parameters determined based on the current calendar date.
[0079] Step S212: For time series prediction targets that are greatly affected by the seasons, taking the amount of coagulant added to a water supply plant as an example, based on the season of the current calendar date, select the sub-model of the amount of coagulant added to the water supply plant corresponding to the season of the current calendar date from the four-season sub-model of the amount of coagulant added to the water supply plant to predict the amount of coagulant added to the water supply plant, thereby improving the prediction accuracy of the amount of coagulant added to the water supply plant.
[0080] The results of seasonal identification can also be used as labels to divide the dataset required for time series prediction targets into four subsets corresponding to spring, summer, autumn, and winter. These subsets participate in the training and optimization of the seasonal sub-models for time series prediction targets, thereby improving the prediction accuracy of the seasonal sub-models. Taking the prediction of coagulant dosage in water supply plants as an example, the dataset required for predicting the coagulant dosage in water supply plants is divided, and then the seasonal sub-models for the coagulant dosage in water supply plants are trained and optimized to be applied to the prediction of coagulant dosage in water supply plants in step S212, thereby improving the prediction accuracy of these prediction targets.
[0081] In addition to assisting in the prediction of coagulant dosage in water supply plants and improving prediction accuracy, the seasonal identification results of this invention can also be used to assist in water plant scheduling, adopting corresponding operation and maintenance modes for different seasons, ensuring water quality safety while reducing management difficulty and improving operational efficiency.
[0082] Although the present invention has been described in detail above, it is not limited thereto, and those skilled in the art can make various modifications based on the principles of the present invention. Therefore, all modifications made in accordance with the principles of the present invention should be understood to fall within the protection scope of the present invention.
Claims
1. A method for seasonal identification of water quality data, characterized in that, The method includes: Obtain a dataset containing water quality samples from different times, wherein each water quality sample contains water quality parameters closely related to seasonal changes and the calendar time in which the water quality parameters were collected; For any water quality sample, the seasonal code and time parameter of the water quality parameters in the water quality sample are determined based on the Gregorian calendar time in the water quality sample, wherein the seasonal code includes the spring code, summer code, autumn code, winter code of the known season, and the code to be identified for the unknown season; Based on the seasonal code and time parameter of each water quality sample in the dataset, the dataset is reconstructed and segmented to obtain a known seasonal dataset and an unknown seasonal dataset. Each new water quality sample in the known seasonal dataset and the unknown seasonal dataset contains a seasonal code, a time parameter, and a water quality parameter. The season recognition model is trained using the known season dataset to obtain the initial season recognition models for spring, summer, autumn and winter respectively. For each new water quality sample in the unknown season dataset, select an appropriate initial season recognition model from the initial season recognition models corresponding to spring, summer, autumn and winter that have been trained. Using the initial seasonal identification model selected for each new water quality sample in the unknown seasonal dataset, seasonal identification is performed for each new water quality sample in the unknown seasonal dataset to obtain a predicted code, and the new water quality samples in the known seasonal dataset and the new water quality samples that have obtained the predicted code are integrated into a dataset with a complete known seasonal code; Using the dataset with complete known seasonal codes, the initial seasonal identification models corresponding to spring, summer, autumn, and winter are optimized to predict seasonal codes for the latest unknown seasonal water quality parameters.
2. The method according to claim 1, characterized in that, The water quality parameters that are closely related to seasonal changes include influent temperature, which reflects the seasonality of climate; influent turbidity, which reflects the seasonal changes in water quality; and influent conductivity, which reflects the seasonal fluctuations in ion concentration.
3. The method according to claim 1, characterized in that, The process of determining the seasonal code and time parameter for the water quality parameters of any water quality sample based on the Gregorian calendar time in the water quality sample includes: For any water quality sample, the solar term period to which the Gregorian calendar time of the water quality sample belongs is determined according to the seasonal coding rules, so as to obtain the season and seasonal code determined by the solar term period. The difference in the number of days between the Gregorian calendar date and January 1st of the current year in the water quality sample is determined as the time parameter; The seasonal coding rules include: The solar term period from the Beginning of Spring to Grain Rain each year is defined as spring, and the spring code is set accordingly. The solar terms from the Beginning of Summer to the Great Heat each year are defined as summer, and the summer code is set accordingly. The Gregorian calendar period from the Beginning of Autumn to the Frost's Descent solar terms each year is defined as autumn, and the autumn code is set accordingly; The Gregorian calendar period from the Beginning of Winter in each year to the Great Cold in the following year is defined as winter, and the winter code is set accordingly. Define the remaining solar term period in the Gregorian calendar as an unknown season and set the code to be identified.
4. The method according to claim 1, characterized in that, The process of reconstructing and segmenting the dataset based on the seasonal code and time parameters of each water quality sample in the dataset to obtain known seasonal datasets and unknown seasonal datasets includes: Obtain the water quality parameters for each water sample from the dataset; The water quality parameters of each water quality sample in the dataset are combined with its seasonal code and time parameters to obtain a new water quality sample, and then a reconstructed dataset is formed by all the new water quality samples. Based on whether the seasonal code of each new water quality sample is a code of a known season or a code to be identified for an unknown season, the reconstructed dataset is divided into a known season dataset and an unknown season dataset.
5. The method according to claim 1, characterized in that, The step of training the season recognition model using the known seasonal dataset to obtain the initial season recognition models corresponding to spring, summer, autumn, and winter includes: For spring, a binary classification label for identifying spring is constructed, and the time parameter and water quality parameter in the known seasonal dataset are used as features. The binary classification label for identifying spring is used as the target to train the seasonal identification model, and the initial seasonal identification model corresponding to spring is obtained after training. In this case, when the seasonal code of each new water quality sample in the known seasonal dataset is the spring code, the label is set to 1; otherwise, the label is set to 0. For summer, a binary classification label for identifying summer is constructed, and the time parameter and water quality parameter in the known seasonal dataset are used as features. The binary classification label for identifying summer is used as the target to train the seasonal identification model, and the initial seasonal identification model corresponding to summer is obtained after training. In this case, when the seasonal code of each new water quality sample in the known seasonal dataset is the summer code, the label is set to 1; otherwise, the label is set to 0. For autumn, a binary classification label for identifying autumn is constructed, and the time parameter and water quality parameter in the known seasonal dataset are used as features. The binary classification label for identifying autumn is used as the target to train the seasonal identification model, and the initial seasonal identification model corresponding to autumn is obtained after training. In this case, when the seasonal code of each new water quality sample in the known seasonal dataset is the autumn code, the label is set to 1; otherwise, the label is set to 0. For winter, a binary classification label for identifying winter is constructed, and the time parameter and water quality parameter in the known seasonal dataset are used as features. The binary classification label for identifying winter is used as the target to train the seasonal identification model, and the initial seasonal identification model corresponding to winter is obtained after training. In this case, when the seasonal code of each new water quality sample in the known seasonal dataset is the winter code, the label is set to 1; otherwise, the label is set to 0. The seasonal identification model employs a K-nearest neighbor machine learning model.
6. The method according to claim 5, characterized in that, The step of selecting a suitable initial seasonal identification model for each new water quality sample in the unknown seasonal dataset from the trained initial seasonal identification models corresponding to spring, summer, autumn, and winter includes: According to the Gregorian calendar time corresponding to each new water quality sample in the unknown seasonal dataset, each new water quality sample in the unknown seasonal dataset is divided into a corresponding seasonal transition subset. The seasonal transition subset includes the spring-summer transition subset corresponding to Grain Rain and before Summer Begins each year, the summer-autumn transition subset corresponding to Great Heat and before Autumn Begins each year, the autumn-winter transition subset corresponding to Frost's Descent and before Winter Begins each year, and the winter-spring transition subset corresponding to Great Cold and before Spring Begins each year. From the trained initial seasonal recognition models corresponding to spring, summer, autumn, and winter, select initial seasonal recognition models corresponding to spring and summer for the spring-summer transition subset, select initial seasonal recognition models corresponding to summer and autumn for the summer-autumn transition subset, select initial seasonal recognition models corresponding to autumn and winter for the autumn-winter transition subset, and select initial seasonal recognition models corresponding to winter and spring for the winter-spring transition subset.
7. The method according to claim 6, characterized in that, The step of using the initial seasonal identification model selected for each new water quality sample in the unknown seasonal dataset to perform seasonal identification for each new water quality sample in the unknown seasonal dataset, and obtaining the predicted code includes: For any seasonal transition subset, using the time parameters and water quality parameters in the seasonal transition subset as features, and utilizing the initial seasonal identification models corresponding to the two adjacent seasons selected for the seasonal transition subset, seasonal identification is performed on each new water quality sample in the seasonal transition subset, resulting in two output labels for each new water quality sample; Using the two output labels of each new water quality sample, a predictive code is determined for each new water quality sample.
8. The method according to claim 7, characterized in that, The process of determining a predictive code for each new water quality sample using its two output labels includes: For any new water quality sample, if only one of the two output labels of the new water quality sample is 1 and is the output label of the initial seasonal identification model corresponding to the latter of the two adjacent seasons, then the seasonal code of the new water quality sample is determined to be the seasonal code of the latter of the two adjacent seasons; otherwise, the seasonal code of the new water quality sample is determined to be the seasonal code of the former of the two adjacent seasons.
9. A water quality data seasonal identification system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the computer program is executed by the processor, it implements the steps of the water quality data seasonal identification method as described in any one of claims 1 to 8.