A method for real-time detection of temperature and humidity sensor failure
By using a gradient boosting tree model to monitor the deviation of temperature and humidity sensors in real time, the problem of needing to manually inspect the sensors periodically has been solved, enabling efficient and rapid failure detection and reducing the risk of production accidents.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANDONG YIGEQI IND AUTOMATION TECH CO LTD
- Filing Date
- 2025-11-19
- Publication Date
- 2026-05-05
AI Technical Summary
Existing temperature and humidity sensors require regular manual inspection to check for malfunctions, resulting in low efficiency and a high risk of production accidents.
A gradient boosting tree-based deviation prediction model is adopted. Through data acquisition, feature preprocessing, and model training, the effectiveness of the sensor is monitored in real time. The multi-decision tree model is used to capture the nonlinear characteristics between the sensor input features and output deviation, reduce the impact of noise, and achieve rapid prediction.
It enables real-time failure detection of sensors, improves detection efficiency, reduces the risk of production accidents, and has a prediction speed in the millisecond range, meeting the needs of real-time monitoring.
Smart Images

Figure CN121430702B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of sensor detection technology, and in particular relates to a real-time detection method for temperature and humidity sensor failure. Background Technology
[0002] There are several possible reasons why temperature and humidity sensors may exceed tolerances. These can be mainly attributed to factors such as crossover error, systematic error, response error, zero drift, and full-scale drift. Humidity interference with temperature measurement can cause errors due to multi-parameter coupling in the sensor. Circuit offset can lead to fixed errors caused by defects in the sensor's hardware design. Measurement lag during sudden environmental changes can result in response errors. After long-term use, zero drift and full-scale errors can both cause the sensor to eventually exceed tolerances. Some errors can accumulate to form a comprehensive error.
[0003] During the use of sensors, manual inspection is required periodically to check for failure or to replace them after failure. Therefore, in industrial production, manual inspection is not only inefficient, but also prone to production accidents and significant losses. Summary of the Invention
[0004] The purpose of this invention is to provide a real-time detection method for temperature and humidity sensor failure, aiming to solve the problem that in the process of using sensors, it is necessary to manually check for failure periodically, or replace them after failure. Therefore, in industrial production, the use of manual inspection is not only inefficient, but also prone to production accidents and significant losses.
[0005] This invention is implemented as follows: a method for real-time detection of temperature and humidity sensor failure, the method comprising:
[0006] Data collection is performed, input features are constructed, and the input features are preprocessed, including original features and derived features;
[0007] A dataset is constructed based on the preprocessed input features, and the dataset is divided into multiple parts, including a training set and a test set. A bias prediction model is constructed based on a gradient boosting tree.
[0008] The bias prediction model is trained using a training set. After training, the prediction accuracy of the bias prediction model is verified using a test set to obtain the trained bias prediction model.
[0009] The sensor's real-time characteristics are collected and imported into the deviation prediction model. The effectiveness of the sensor is determined based on the temperature and humidity deviation output by the deviation prediction model.
[0010] Preferably, the deviation prediction model employs two single-output models or one multi-output model. The two single-output models are used to output the temperature deviation and humidity deviation, respectively. The step of constructing the single-output model includes:
[0011] Model initialization: Construct an initial model of gradient boosting tree and set the loss function, which is the MSE loss function;
[0012] Generate base decision trees: Fit the negative gradient of the previous model using base decision trees, construct multiple base decision trees, and fuse them to generate the overall model;
[0013] Iteration: Through multiple rounds of iteration, a single-output model containing the weighted sum of all base decision trees is generated.
[0014] Preferably, the loss function is expressed as
[0015] ;
[0016] in, This represents the true value of humidity deviation or the true value of temperature deviation. This indicates the true value of the humidity deviation. This represents the true value of the temperature deviation. middle, This indicates the predicted humidity deviation. Indicates the predicted temperature deviation. This represents the input features.
[0017] Preferably, in the step of generating the basis decision tree, for the i-th sample, the predicted value of the model in the (m-1)-th round is... The negative gradient of its loss function is:
[0018] ;
[0019] in, This represents the negative gradient under a humidity or temperature sample. This represents the true value of the humidity or temperature deviation corresponding to the i-th sample.
[0020] Preferably, in the step of generating the overall model based on the fusion of base decision trees, the m-th base tree is... With learning rate Weighted and incorporated into the previous round's overall model, the overall model for round m is represented as follows:
[0021] .
[0022] Preferably, in the step of generating a single-output model containing the weighted sum of all base decision trees, the single-output model is represented as:
[0023] ;
[0024] in, For the number of iterations, This is the initial model.
[0025] Preferably, a robust loss function is used instead of the MSE loss function, defined as:
[0026] ;
[0027] The negative gradient is expressed as:
[0028] .
[0029] Preferably, by adding a regularization term to the robustness loss function, the regularization loss is expressed as:
[0030] ;
[0031] in, , Let m be the number of leaf nodes of the m-th tree. It is the output value of the j-th leaf of the m-th tree. , and This is the regularization coefficient.
[0032] Preferably, during the training process, the accuracy of the model is evaluated using three sets of evaluation metrics, including mean absolute error, root mean square error, and coefficient of determination.
[0033] This invention uses a multi-decision tree model to accurately capture the nonlinear features between sensor input features and output deviations. By utilizing residual iteration and regularization, it can significantly reduce the impact of noise on prediction results. Compared with deep learning models, this invention has a faster inference speed, with single-sample prediction taking only milliseconds, which can meet the real-time monitoring needs of sensors. Attached Figure Description
[0034] Figure 1 A flowchart of a real-time detection method for temperature and humidity sensor failure provided in an embodiment of the present invention;
[0035] Figure 2 This is a schematic diagram of the failure detection results of the temperature and humidity sensor provided in an embodiment of the present invention. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0037] like Figure 1 The diagram shown is a flowchart of a real-time detection method for temperature and humidity sensor failure provided in an embodiment of the present invention. The method includes:
[0038] Data collection is performed, input features are constructed, and the input features are preprocessed, including original features and derived features;
[0039] A dataset is constructed based on the preprocessed input features, and the dataset is divided into multiple parts, including a training set and a test set. A bias prediction model is constructed based on a gradient boosting tree.
[0040] The bias prediction model is trained using a training set. After training, the prediction accuracy of the bias prediction model is verified using a test set to obtain the trained bias prediction model.
[0041] The sensor's real-time characteristics are collected and imported into the deviation prediction model. The effectiveness of the sensor is determined based on the temperature and humidity deviation output by the deviation prediction model.
[0042] In this embodiment of the invention, the invention is mainly divided into two parts. One part is to construct a deviation prediction model to fit the nonlinear relationship between the input features and the temperature and humidity deviation. The other part is to determine whether the sensor is malfunctioning by making a threshold judgment based on the prediction results output by the deviation prediction model.
[0043] In this invention, multiple base decision trees are generated iteratively, each tree is fitted with the residual (or negative gradient) of the previous model, and finally the outputs of all base trees are weighted and summed to obtain the final prediction model, namely the bias prediction model.
[0044] The following derives the mathematical model of a single-output GBT (Gradient Boosting Tree) using humidity deviation prediction (k=1) as an example. Temperature deviation prediction (k=2) is completely similar; only the tags need to be replaced. .
[0045] The steps involved in building the model include:
[0046] Step 1, Model Initialization (Round 0):
[0047] The initial model is a constant function, and the goal is to minimize the loss function on the training set. Let the loss function be the mean squared error (MSE, suitable for regression tasks, and the residual is equivalent to the negative gradient), defined as:
[0048] ;
[0049] in, This represents the true value of humidity deviation or the true value of temperature deviation. This indicates the true value of the humidity deviation. This represents the true value of the temperature deviation. middle, This indicates the predicted humidity deviation. Indicates the predicted temperature deviation. This represents the input features.
[0050] To minimize the initial loss Initial model We need to take the mean of the humidity deviation in the training set, which is the optimal constant solution under MSE loss:
[0051] ;
[0052] Where c is a constant, This means that regardless of the input feature X, the initial predicted value is the mean of the humidity or temperature deviation of the training set.
[0053] Step 2, iteratively generate the base decision tree (m-th round, 1≤m≤T):
[0054] The core of each iteration is to fit the negative gradient of the previous model, i.e. the residual, with a base decision tree, and then integrate the tree into the overall model with a learning rate γ.
[0055] A. For the i-th sample, the predicted value of the model in the (m-1)-th round is , For the input feature corresponding to the i-th sample, the negative gradient of its loss function, i.e., the pseudo-residual, is expressed as:
[0056] ;
[0057] Substitute into the MSE loss function: ;
[0058] Differentiating, we get:
[0059] ;
[0060] As can be seen, when the loss function is MSE, the residual is equal to the negative gradient, which means the difference between the previous prediction value and the actual deviation. The goal of the base tree (i.e. the base decision tree) is to reduce this difference.
[0061] B. Training the m-th base decision tree :
[0062] With residuals As pseudo-labels, use the training set Training a CART regression tree .
[0063] The essence of CART regression trees is to divide the feature space. Non-overlapping leaf node regions , Given the number of leaf nodes in the m-th tree, assign an optimal output value to each region. The mean of the residuals within that region is the optimal solution that minimizes the MSE.
[0064] ;
[0065] in, Indicates falling within the area The number of samples in (like ).
[0066] C. Update the overall model:
[0067] The m-th base tree With learning rate Weighted and incorporated into the previous round's overall model, we obtain the overall model for round m:
[0068] ;
[0069] Learning rate The purpose is to reduce the contribution of each base tree, preventing a single tree from having too large an impact on the model, thereby improving generalization ability. The smaller the value, the more iterations are needed to achieve the same level of accuracy.
[0070] Step 3: Generate the final prediction model:
[0071] After T iterations, the final humidity deviation prediction model is the weighted sum of all base trees (including the initial model):
[0072] ;
[0073] When k=1, the model predicts humidity deviation; when k=2, it predicts temperature deviation. The base decision tree is trained for the m-th round to address humidity bias. This is the base decision tree trained for temperature deviation in the m-th round.
[0074] Loss function expansion and regularization:
[0075] In the embodiments of the invention, the MSE function can be replaced by a robust loss function, that is, the mean absolute error can be used as the loss function, as follows:
[0076] ;
[0077] At this point, the negative gradient (pseudo-residual) is no longer equal to the residual and needs to be recalculated.
[0078]
[0079] in, It is a sign function, which is 1 when x>0, -1 when x<0, and 0 when x=0.
[0080] At this point, the optimal output value of the leaf node of the time-signed residual fitted by the base tree becomes the median of the true residual in that region, the optimal solution under MAE loss:
[0081] .
[0082] Regularization term (to prevent overfitting):
[0083] To prevent the model from overfitting the training data, a regularization term needs to be added to the loss function to penalize the complexity of the base tree. Commonly used regularization losses in engineering implementations (such as XGBoost and LightGBM) are:
[0084] ;
[0085] in, , Let m be the number of leaf nodes of the m-th tree. It is the output value of the j-th leaf of the m-th tree. , and This is the regularization coefficient.
[0086] When using a multi-output prediction model, it is necessary to predict both humidity and temperature deviations simultaneously. This can be achieved by constructing two independent single-output GBT models (as described above) or by directly constructing a multi-output GBT model (sharing the feature space to improve efficiency).
[0087] The core of multi-output GBT is that in each iteration, the base tree simultaneously fits the residual vectors of the two outputs. Mathematically, the residual vector in the m-th iteration is:
[0088]
[0089] At this point, the cardinality The output is a two-dimensional vector. For each of the two predicted biases, the output of the multi-output prediction model is expressed as:
[0090] ;
[0091] The advantage of multi-output models is that they share the feature splitting process (such as feature selection and node splitting in CART trees), reducing computational load and making them suitable for real-time sensor monitoring scenarios.
[0092] In this invention, timeliness determination conditions for sensors are set, for newly acquired sensor features. The corresponding prediction biases, namely humidity prediction bias and temperature prediction bias, are output through two single-output models or one multi-output model, which are constructed as follows: , Then, the following logic will be used to make the judgment:
[0093] If so, the sensor is considered to be faulty.
[0094] If the condition is met, an early warning will be issued; otherwise, the sensor will be considered normal. Set a threshold for temperature. Set a threshold for humidity. This serves as an early warning coefficient, triggering an early warning when the deviation reaches 80% of the threshold, thus enabling early intervention before failure.
[0095] After obtaining the bias prediction model, the bias prediction model is trained, and the steps are as follows:
[0096] Data partitioning: Divide the data into a training set (fitting the model), a validation set (tuning parameters), and a test set (evaluating generalization ability) in a 7:2:1 ratio to ensure that the bias distribution of each set is consistent after partitioning (to avoid data leakage).
[0097] Iterative training logic:
[0098] a) Initialization: Use the "mean humidity deviation / mean temperature deviation" of the training set as the initial prediction values;
[0099] b) Residual fitting: Train a base decision tree in each round and fit the residual of the previous round's prediction (residual = true deviation - previous round's prediction deviation).
[0100] c) Regularization constraints: Large weights are penalized through lambda_l1 (L1 regularization) and lambda_l2 (L2 regularization) to avoid overfitting;
[0101] d) Early Stopping: If the loss on the validation set (e.g., MAE) does not decrease for 10 consecutive rounds, training is stopped to prevent invalid iterations.
[0102] The core parameters of the model, specifically for the regression task of "temperature and humidity deviation prediction," are optimized using LightGBM as follows:
[0103] Parameter name effect Recommended value range objective Loss function (regression task) regression_l1 (MAE, robust to outliers) / regression_l2 (MSE, suitable for data without outliers) learning_rate Learning rate (step size, the smaller the step size, the more trees are needed). 0.01~0.1 n_estimators Number of base decision trees (learning rate is needed to avoid overfitting) 100~300 max_depth Maximum depth of a single tree (to prevent overfitting) 3~6 (few features, no need for excessive depth) subsample The proportion of subsamples used when training each tree (random sampling to reduce overfitting). 0.8~1.0 colsample_bytree Feature sampling ratio during training of each tree (to avoid single feature dominance) 0.7~1.0 min_child_samples Minimum number of samples for leaf nodes (to prevent generating overly fine leaves). 5~10
[0104] In this invention, evaluation metrics for assessing the model are provided, as shown in the table below:
[0105] Evaluation indicators meaning Target value (example) Mean Absolute Error (MAE) The mean absolute difference between the predicted bias and the actual bias (the smaller the value, the smoother the result). Humidity MAE ≤ 0.2%RH, Temperature MAE ≤ 0.05℃ Root Mean Square Error (RMSE) The root mean square of the predicted bias and the actual bias (sensitive to large biases). Humidity RMSE ≤ 0.3%RH, Temperature RMSE ≤ 0.08℃ Coefficient of determination (R²) The model's ability to explain variations in bias (the closer to 1, the better). R²≥0.9
[0106] During failure monitoring, the trained deviation prediction model is connected to the sensor real-time monitoring system. The sensor real-time monitoring system collects data from the sensor, acquiring the sensor's original features in real time and generating corresponding derived features based on the original features. The original and derived features are preprocessed to obtain real-time features, which are then imported into the deviation prediction model. The deviation prediction model simultaneously outputs the predicted humidity deviation and temperature deviation, such as humidity deviation = 2.1%RH and temperature deviation = 0.4℃.
[0107] Failure determination and response: Different actions are triggered based on the accuracy level of the sensor: the result determination levels are shown in the table below.
[0108] Prediction results Failure determination System Response Humidity deviation ≤ threshold and temperature deviation ≤ threshold normal Record the deviation value and continue monitoring. Humidity deviation > threshold or temperature deviation > threshold Failure 1. Trigger audible and visual alarms; 2. Push maintenance notifications (e.g., "Sensor A humidity deviation exceeds the standard, calibration / replacement required"); 3. Automatically switch to backup sensor. The deviation is close to the threshold (e.g., reaching 80% of the threshold). Warning A notification will be sent stating "The deviation is approaching the threshold; early calibration is recommended" to prevent sudden failures.
[0109] Model Iterative Optimization
[0110] After long-term use, the relationship between error and bias of a sensor may change due to aging and environmental changes (data distribution drift), requiring regular model updates. New "feature-bias" data (including newly added failure samples) should be collected every 3-6 months; model retraining: the GBT model should be retrained with the new dataset plus historical valid data to replace the old model; if the sensor accuracy decreases (e.g., it still cannot reach the original threshold after calibration), the failure threshold needs to be readjusted.
[0111] Test experiment:
[0112] Taking an "industrial Class A temperature and humidity sensor" as an example, the experiment was conducted as follows: Data foundation: 12 months of data were collected from 1000 sensors (a total of 12,000 samples, including 1080 failed samples). Input features included 5 original features + 3 derived features (cumulative zero-point drift, usage time, and crossover error × systematic error); Model training: LightGBM was used for training with parameters: objective=regression_l1, learning_rate=0.05, n_estimators=200, and max_depth=4. The model operation was carried out according to the following procedure:
[0113] (1) Input feature preprocessing: Standardize X (e.g., , For the first The mean of each feature, (Standard deviation)
[0114] (2) Model initialization: calculation and (Mean bias of training set);
[0115] (3) Iterative training: Calculate the residuals from m=1 to T. Retrain the multi-output base tree Update the model and ;
[0116] (4) Final prediction: Input new features Output and ;
[0117] (5) Failure determination: Compare the prediction deviation with the threshold and output the result of "normal / warning / failure".
[0118] The final experimental results are as follows Figure 2 And as shown in the table below:
[0119]
[0120] Conclusion: Sensor uploaded and displayed data showed the following: crossover error = 2.3%, system error = 1.7%, response error = 2.1%, zero drift = 0.3℃ / month, full-scale drift = 0.7% / month, and model predicted humidity deviation = 2.2%RH (exceeding the 2%RH threshold), indicating a failure. This method can accurately identify sensor failures in advance, and the system pushes maintenance notifications within 10 seconds, avoiding production accidents caused by inaccurate humidity measurements.
[0121] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for real-time detection of temperature and humidity sensor failure, characterized in that, The method includes: Data collection is performed, input features are constructed, and the input features are preprocessed, including original features and derived features; A dataset is constructed based on the preprocessed input features, and the dataset is divided into multiple parts, including a training set and a test set. A bias prediction model is constructed based on a gradient boosting tree. The bias prediction model is trained using a training set. After training, the prediction accuracy of the bias prediction model is verified using a test set to obtain the trained bias prediction model. The sensor's real-time characteristics are collected and imported into the deviation prediction model. The effectiveness of the sensor is determined based on the temperature and humidity deviation output by the deviation prediction model. The deviation prediction model employs either two single-output models or one multi-output model. The two single-output models are used to output the temperature deviation and humidity deviation, respectively. The steps for constructing a single-output model include: Model initialization: Construct an initial model of gradient boosting tree and set the loss function, which is the MSE loss function; Generate base decision trees: Fit the negative gradient of the previous model using base decision trees, construct multiple base decision trees, and fuse them to generate the overall model; Iteration: Through multiple rounds of iteration, a single-output model containing the weighted sum of all base decision trees is generated; The loss function is expressed as: ; in, This represents the true value of humidity deviation or the true value of temperature deviation. This indicates the true value of the humidity deviation. This represents the true value of the temperature deviation. middle, This indicates the predicted humidity deviation. Indicates the predicted temperature deviation. Represents input features; In the step of generating the basis decision tree, for the i-th sample, the predicted value of the model in the (m-1)-th round is... The negative gradient of its loss function is: ; in, This represents the negative gradient under a humidity or temperature sample. This represents the true value of the humidity or temperature deviation corresponding to the i-th sample.
2. The real-time detection method for temperature and humidity sensor failure according to claim 1, characterized in that, In the step of generating the overall model based on the fusion of base decision trees, the m-th base tree is... With learning rate Weighted and incorporated into the previous round's overall model, the overall model for round m is represented as follows: 。 3. The real-time detection method for temperature and humidity sensor failure according to claim 1, characterized in that, In the step of generating a single-output model containing the weighted sum of all base decision trees, the single-output model is represented as: ; in, For the number of iterations, This is the initial model.
4. The real-time detection method for temperature and humidity sensor failure according to claim 1, characterized in that, The robust loss function is used instead of the MSE loss function, defined as: ; The negative gradient is expressed as: 。 5. The real-time detection method for temperature and humidity sensor failure according to claim 4, characterized in that, Adding a regularization term to the robustness loss function results in the regularization loss being expressed as: ; in, , Let m be the number of leaf nodes of the m-th tree. It is the output value of the j-th leaf of the m-th tree. , and This is the regularization coefficient.
6. The real-time detection method for temperature and humidity sensor failure according to claim 1, characterized in that, During the training process, the accuracy of the model is evaluated using three sets of evaluation metrics, including mean absolute error, root mean square error, and coefficient of determination.
Citation Information
Patent Citations
Shopping mall building air conditioner cooling load prediction method based on GBDT, storage medium and equipment
CN112001439A
Residual fitting mechanism-based simplified deep forest regression soft measurement method for furnace grate furnace MSWI process dioxin emission
WO2023165635A1