An automatic analysis system and method for detecting characteristic pollutants in drilling fluid
Through an automated drilling fluid detection system, molecular structure analysis and random forest model are used, combined with SHAP value analysis and disturbance processing, the problem of low detection efficiency of traditional drilling fluid pollutants is solved, and a fast and accurate detection effect is achieved.
Patent Information
- Application Number
- CN202411129644.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-08-16
AI Technical Summary
Traditional drilling fluid characteristic pollutant detection methods have a long detection cycle and cannot meet the needs of rapid monitoring.
An automatic analysis system and method is proposed to achieve fast and accurate pollutant detection by collecting drilling fluid samples, performing molecular structure analysis, converting it into molecular descriptors, training based on random forest model, combining SHAP value analysis and perturbation processing.
It greatly reduces human intervention, improves detection efficiency, can process and analyze large-scale data in real time, and achieves fast and accurate pollutant detection.
Smart Images

Figure CN119027614B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of drilling fluid detection, and in particular to an automatic analysis system and method for detecting characteristic pollutants in drilling fluid. Background Art
[0002] The application of drilling fluid is essential in the drilling construction process. The lubricating property of drilling fluid can reduce the friction between the drill bit and the formation, thereby extending the service life of the drill bit and improving drilling efficiency; drilling fluid can also prevent the well wall from collapsing and maintain the stability of the wellbore by applying appropriate pressure to the well wall; in addition, drilling fluid also plays an important role in controlling bottom hole pressure, transmitting hydraulic energy, providing formation information and preventing formation damage.
[0003] However, traditional methods for detecting characteristic contaminants in drilling fluid usually rely on laboratory analysis. Although the test results are relatively accurate, the detection cycle is long. It usually takes several hours to several days from sample collection to obtaining analysis results, which cannot meet the needs of rapid monitoring. Summary of the invention
[0004] In view of this, the present invention proposes an automatic analysis system and method for detecting characteristic contaminants in drilling fluid, aiming to solve the problem of low efficiency in detecting characteristic contaminants in drilling fluid in current technology.
[0005] On the one hand, the present invention proposes an automatic analysis method for detecting characteristic pollutants in drilling fluid, comprising: collecting a drilling fluid sample, performing molecular structure analysis on the filtered drilling fluid sample, obtaining three-dimensional structure data of various chemical molecules in the drilling fluid sample, and converting the three-dimensional structure data into molecular descriptors;
[0006] Based on the random forest model, the molecular descriptors are divided into a training set, a validation set and a test set, and the proportions of the training set, the validation set and the test set are adjusted according to the data volume of the molecular descriptors; the molecular descriptors in the training set are input into the random forest model, and the random forest model is trained to learn the relationship between the molecular descriptors and the pollutant concentration;
[0007] Determine the contribution value of the molecular descriptor to the pollutant concentration by SHAP value analysis, pre-set a benchmark contribution threshold, select the molecular descriptors whose contribution values are greater than or equal to the benchmark contribution threshold, perturb the molecular descriptors, obtain the perturbed molecular descriptors and re-input them into the random forest model one by one to obtain the perturbed pollutant concentration; pre-set a significance threshold, and determine whether to remove the current molecular descriptor based on the standard deviation of the output perturbed pollutant concentration and the significance threshold;
[0008] The three-dimensional structure data includes: the atomic composition of the molecules in the drilling fluid sample, the bonding relationship between atoms, the bond length, the bond angle and the relative position in the three-dimensional space.
[0009] Furthermore, when the molecular descriptor is divided into a training set, a validation set and a test set, it includes:
[0010] Preset a first partition factor, a second partition factor, and a third partition factor, obtain the data volume of the molecular descriptor, and select a partition factor according to the data volume:
[0011] When the data volume is less than or equal to 1000, a first partitioning factor is selected, and the first partitioning factor is that the training set, validation set and test set account for 70%, 20% and 10% of the data volume respectively; when the data volume is greater than 1000 and less than or equal to 5000, a second partitioning factor is selected, and the second partitioning factor is that the training set, validation set and test set account for 60%, 20% and 20% of the data volume respectively; when the data volume is greater than 5000, a third partitioning factor is selected, and the third partitioning factor is that the training set, validation set and test set account for 80%, 10% and 10% of the data volume respectively.
[0012] Furthermore, after the molecular descriptors in the training set were input into the random forest model, the hyperparameters of the random forest model were tuned through the validation set, and the performance of the model was evaluated through cross-validation.
[0013] Furthermore, the hyperparameters of the random forest model are tuned using the validation set, including:
[0014] Define the hyperparameter space and set specific ranges: the number of trees is [100, 200, 300, 400, 500]; the maximum depth is [10, 20, 30, 40, 50]; the minimum number of sample splits is [2, 5, 10]; the minimum number of sample leaf nodes is [1, 2, 4]; the maximum number of features is [0.1, 0.2, 0.5];
[0015] Create parameter grid: List the hyperparameter combinations and create a parameter grid for each combination of hyperparameter values;
[0016] Split the data set: divide the sample data set into training set, validation set and test set according to the division factors at each level;
[0017] Training the model: For each set of hyperparameter combinations in the parameter grid, use the training set to perform model training.
[0018] Furthermore, the performance of the model was evaluated through cross-validation, including:
[0019] Divide the training set into K folds; in each fold, use K-1 folds as training sets to train the random forest model;
[0020] The performance of the random forest model was evaluated on the last fold: the accuracy and mean square error were recorded; the average accuracy and mean square error of all K rounds were calculated respectively, and the hyperparameters of the random forest model were adjusted based on the average accuracy and mean square error.
[0021] Further, when adjusting the hyperparameters of the random forest model based on the average accuracy and the average mean square error, it includes: assigning K a value of 5;
[0022] The evaluation value is calculated based on the average accuracy and the average mean square error, and the evaluation value satisfies the following relationship:
[0023] F = a*X+b*Y;
[0024] Where F is the evaluation value, X is the average accuracy, Y is the average mean square error, a is the weight of the average accuracy, b is the weight of the average mean square error, and a+b=1;
[0025] After the evaluation value is obtained, a set of hyperparameters of the random forest model with the largest evaluation value is selected.
[0026] Further, the perturbation molecular descriptor is obtained by adding or subtracting a constant value from the molecular descriptor, and the constant value added or subtracted from all perturbation molecular descriptors is the same.
[0027] Furthermore, the atomic composition of the molecules in the drilling fluid sample is ionized by a mass spectrometer, and the mass-charge ratio of the ions is analyzed to obtain information on the atomic composition; the atomic bonding relationship is obtained by nuclear magnetic resonance; the bond length and bond angle are obtained by X-ray diffraction to obtain the atomic position, and the distance and angle between atoms are calculated; the relative position in the three-dimensional space is calculated according to the density functional theory DFT, and the three-dimensional spatial position of each atom in the molecule is obtained by simulation.
[0028] On the other hand, the present invention also proposes an automatic analysis system for detecting characteristic contaminants in drilling fluids, the system comprising:
[0029] The pre-processing module collects drilling fluid samples, performs molecular structure analysis on the filtered drilling fluid samples, and obtains the three-dimensional structure data of various chemical molecules in the samples;
[0030] A generation module converts the three-dimensional structure data into molecular descriptors, wherein the molecular descriptors include the atomic composition of molecules in the drilling fluid sample, the bonding relationship between atoms, the bond length, the bond angle and the relative position in the three-dimensional space;
[0031] The model training module divides the molecular descriptors into training set, validation set and test set based on the random forest model; adjusts the proportion of the training set, validation set and test set according to the data volume of the molecular descriptors; inputs the molecular descriptors in the training set into the random forest model for training to learn the relationship between the molecular descriptors and the pollutant concentration;
[0032] The processing module determines the contribution value of the molecular descriptor to the pollutant concentration through SHAP value analysis, pre-sets a baseline contribution threshold, and screens out molecular descriptors with contribution values greater than or equal to the threshold to identify important features;
[0033] The significance assessment module perturbs the molecular descriptors to generate perturbed molecular descriptors, and re-inputs them into the random forest model one by one to obtain the pollutant concentration after perturbation; the standard deviation of the perturbed pollutant concentration is calculated and compared with the pre-set significance threshold to determine whether to remove the current molecular descriptors.
[0034] Furthermore, it also includes:
[0035] The reporting module is configured to select the molecular descriptors, output the pollutant concentration and generate a report.
[0036] Compared with the prior art, the beneficial effect of the present invention is that the method automates the whole process from sample collection, molecular structure analysis, data conversion, model training to result analysis, greatly reducing human intervention and improving detection efficiency. Through the efficient random forest model and automated feature selection mechanism, large-scale data can be processed and analyzed in real time to achieve fast and accurate pollutant detection. Advanced analytical techniques such as mass spectrometer, nuclear magnetic resonance, X-ray diffraction and density functional theory (DFT) are used to accurately obtain the atomic composition, bonding relationship, bond length, bond angle and relative position in three-dimensional space of molecules in drilling fluid samples, ensuring the high accuracy of input data and providing a reliable foundation for the model. Based on large-scale training and verification of random forest models, the complex relationship between molecular descriptors and pollutant concentrations can be accurately captured to achieve high-precision concentration prediction. The contribution of molecular descriptors to pollutant concentrations is analyzed by SHAP values, which provides the interpretability of model predictions, allowing researchers to understand which molecular features have a significant impact on the results, thereby optimizing pollutant detection and control strategies. By performing perturbation analysis and significance evaluation on high-contribution molecular descriptors, we ensure that the model only relies on key features that have a significant impact on the results, remove irrelevant or minor features, and further improve the stability and performance of the model. During the model training process, hyperparameters are tuned through the validation set, and the model performance is evaluated through the cross-validation method to avoid overfitting and improve the robustness and generalization ability of the model. By calculating the weighted evaluation value of the average accuracy and the average mean square error, the prediction accuracy and error size of the model can be comprehensively considered, and the optimal hyperparameter combination can be selected to ensure the best overall performance of the model. This method is not only suitable for the detection of drilling fluid contaminants, but can also be extended to other chemical analysis fields, such as environmental pollutant detection, drug component analysis, etc., and has broad application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0038] Figure 1 This is a flow chart of an automatic analysis method for detecting characteristic contaminants in drilling fluid according to an embodiment of the present invention;
[0039] Figure 2 This is a functional framework diagram of an automatic analysis system for detecting characteristic contaminants in drilling fluid according to an embodiment of the present invention. DETAILED DESCRIPTION
[0040] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art. It should be noted that, in the absence of conflict, the embodiments of the present invention and the features described in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0041] See also Figure 1 As shown, an embodiment of the present invention provides an automatic analysis method for detecting characteristic contaminants in drilling fluid, comprising:
[0042] Collect drilling fluid samples, perform molecular structure analysis on the filtered drilling fluid samples, obtain three-dimensional structural data of various chemical molecules in the drilling fluid samples, and convert the three-dimensional structural data into molecular descriptors;
[0043] Based on the random forest model, the molecular descriptors are divided into training set, validation set and test set, and the proportion of the training set, validation set and test set is adjusted according to the data volume of the molecular descriptors; the molecular descriptors in the training set are input into the random forest model, and the random forest model is trained to learn the relationship between the molecular descriptors and the pollutant concentration;
[0044] The contribution value of the molecular descriptor to the pollutant concentration is determined by SHAP value analysis, a benchmark contribution threshold is pre-set, and molecular descriptors with contribution values greater than or equal to the benchmark contribution threshold are selected respectively, and the molecular descriptors are perturbed to obtain perturbed molecular descriptors and re-input them into the random forest model one by one to obtain the perturbed pollutant concentration; a significance threshold is pre-set, and whether to remove the current molecular descriptor is determined based on the standard deviation of the output perturbed pollutant concentration and the significance threshold;
[0045] Among them, the three-dimensional structural data includes: the atomic composition of molecules in the drilling fluid sample, the bonding relationship between atoms, bond length, bond angle and relative position in three-dimensional space.
[0046] It should be noted that the automatic analysis method provided in the embodiment of the present invention is used to detect characteristic pollutants in drilling fluids, mainly by deeply analyzing and modeling the chemical molecules in the drilling fluid samples, and automatically analyzing the concentration of pollutants and their relationship with molecular characteristics. The role of this method is to provide an efficient, automated and accurate technical means to monitor the chemical composition of drilling fluids, help identify potential pollutants and control their concentrations. By automating sampling, data processing, model training and result analysis, human intervention is reduced and detection efficiency is improved. The pollutant content in the drilling fluid can be detected in real time, and possible pollution problems can be quickly responded to. The molecular structure data is obtained by precise technical means to ensure the accuracy of molecular descriptors, providing a reliable basis for the high-precision prediction of subsequent models. Training with a random forest model can capture complex nonlinear relationships, thereby achieving accurate prediction of pollutant concentrations. Through SHAP value analysis, it is possible to clearly identify which molecular descriptors have a significant impact on pollutant concentrations, providing researchers with an intuitive model explanation. By performing perturbation analysis and significance evaluation on important features, it is ensured that the model only depends on key features, thereby improving the stability and interpretability of the model. The hyperparameters are tuned through the validation set, and the performance of the model is evaluated using the cross-validation method to avoid overfitting and improve the robustness and generalization ability of the model. It is not only suitable for the detection of pollutants in drilling fluids, but can also be extended to other chemical analysis fields, such as environmental monitoring and drug analysis. The modular design of the system allows the functions of each part to be independently improved or expanded to meet different analysis needs. Samples are collected from the drilling site and preliminarily filtered to remove impurities. Advanced technologies such as mass spectrometry, nuclear magnetic resonance (NMR), and X-ray diffraction (XRD) are used to obtain the atomic composition, bonding relationship, bond length, bond angle, and relative position in three-dimensional space of various molecules in the sample. The above molecular structure information is converted into molecular descriptors that can be processed by the machine learning model. The molecular descriptor dataset is divided into training set, validation set, and test set, and the respective proportions are adjusted according to the amount of data to ensure the effectiveness of model training. The training set data is input into the random forest model to learn the relationship between molecular descriptors and pollutant concentrations. The hyperparameters of the model are tuned using the validation set, and the model performance is evaluated through cross-validation to ensure the optimal configuration of the model. Through SHAP value analysis, the contribution of each molecular descriptor to the prediction of pollutant concentration is determined and key features are identified. The important molecular descriptors are perturbed to generate perturbed molecular descriptors and re-enter the model to observe the changes in pollutant concentration. The impact of the perturbation is judged according to the significance threshold and the final key features are screened out. The prediction accuracy and stability of the model are evaluated in the test set to ensure that the model can perform well in practical applications. The selected key molecular descriptors are used for the actual pollutant concentration prediction, and corresponding control measures are formulated based on the results to prevent pollutants from exceeding the standard.
[0047] The present invention provides an efficient, accurate and highly interpretable drilling fluid characteristic contaminant detection method through advanced molecular structure analysis technology, machine learning model and feature screening method. This method has significant technical advantages in improving detection efficiency, prediction accuracy and model interpretability, and can be effectively applied to the actual field of drilling fluid contaminant monitoring and control.
[0048] In some embodiments of the present application, when the molecular descriptors are divided into a training set, a validation set, and a test set, it includes:
[0049] The first partition factor, the second partition factor and the third partition factor are preset, the data volume of the molecular descriptor is obtained, and the partition factor is selected according to the data volume:
[0050] When the data volume is less than or equal to 1000, the first partition factor is selected, and the first partition factor is that the training set, validation set and test set account for 70%, 20% and 10% of the data volume respectively; when the data volume is greater than 1000 and less than or equal to 5000, the second partition factor is selected, and the second partition factor is that the training set, validation set and test set account for 60%, 20% and 20% of the data volume respectively; when the data volume is greater than 5000, the third partition factor is selected, and the third partition factor is that the training set, validation set and test set account for 80%, 10% and 10% of the data volume respectively.
[0051] It should be noted that by setting different partitioning ratios according to the amount of data, it can be ensured that the model can obtain sufficient training data under different data amounts, so as to effectively learn the relationship between molecular descriptors and pollutant concentrations. At the same time, the reasonable allocation of the ratio of the validation set and the test set can help the model maintain good generalization performance under different data amounts and avoid overfitting or underfitting. Dynamically adjusting the ratio of the training set, validation set, and test set according to the amount of data allows the method to flexibly adapt to data sets of different sizes. When the amount of data is small, increase the proportion of the training set to ensure that the model can learn enough feature information; when the amount of data is large, more test and validation data can provide more reliable model evaluation results. By reasonably dividing the data set, computing resources can be effectively allocated. When the amount of data is large, reducing the proportion of training data can reduce the computational burden; when the amount of data is small, increase the proportion of training data to ensure that the model can learn enough feature information with limited data.
[0052] Before processing the molecular descriptor dataset, we first need to count the number of samples in the dataset. This step can be achieved through a simple counting operation to ensure a clear understanding of the size of the entire dataset. According to the amount of data, three partitioning factors are pre-set: the first partitioning factor: applicable to the case where the amount of data is less than or equal to 1000, the proportions of the training set, validation set, and test set are 70%, 20%, and 10%, respectively. The second partitioning factor: applicable to the case where the amount of data is greater than 1000 and less than or equal to 5000, the proportions of the training set, validation set, and test set are 60%, 20%, and 20%, respectively. The third partitioning factor: applicable to the case where the amount of data is greater than 5000, the proportions of the training set, validation set, and test set are 80%, 10%, and 10%, respectively. According to the actual amount of data, the corresponding partitioning factor is automatically selected. This step can be achieved through a conditional judgment statement, that is, judging which interval the amount of data is in, and selecting the first, second, or third partitioning factor accordingly. According to the selected partitioning factor, the molecular descriptor dataset is divided into a training set, a validation set, and a test set. For example, if the first partition factor is selected, 70% of the samples in the data set are allocated to the training set, 20% of the samples are allocated to the validation set, and 10% of the samples are allocated to the test set. You can use functions such as traintestspl it to implement these partitions.
[0053] After the partitioning is completed, the training set is used to train the random forest model, the validation set is used for hyperparameter tuning and model selection, and the test set is used to finally evaluate the model performance. This partitioning method ensures that the model can achieve the best performance under different data volume conditions and ensures the accuracy and reliability of the prediction results.
[0054] The above division method can flexibly adjust the ratio of training, validation and test sets according to the amount of data, and optimize the learning process and performance evaluation of the model. This method can not only ensure the training effect of the model under small data sets, but also achieve efficient model evaluation under large data sets, thereby improving the performance and stability of the overall system.
[0055] In some embodiments of the present application, after the molecular descriptors in the training set are input into the random forest model, the hyperparameters of the random forest model are tuned through the validation set, and the performance of the model is evaluated by cross-validation.
[0056] In some embodiments of the present application, the hyperparameters of the random forest model are tuned by using a validation set, including:
[0057] Define the hyperparameter space and set specific ranges: the number of trees is [100, 200, 300, 400, 500]; the maximum depth is [10, 20, 30, 40, 50]; the minimum number of sample splits is [2, 5, 10]; the minimum number of sample leaf nodes is [1, 2, 4]; the maximum number of features is [0.1, 0.2, 0.5];
[0058] Create parameter grid: List the hyperparameter combinations and create a parameter grid for each combination of hyperparameter values;
[0059] Split the data set: divide the sample data set into training set, validation set and test set according to the division factors at each level;
[0060] Training model: For each set of hyperparameter combinations in the parameter grid, use the training set to train the model.
[0061] It should be noted that to define the hyperparameter space and set the specific range, first, in order to perform hyperparameter tuning, the hyperparameters to be optimized and their candidate value ranges must be defined. In the random forest model, common hyperparameters include: Number of trees (nest imators): determines the total number of trees in the forest. Candidate values are [100, 200, 300, 400, 500]. Maximum depth (max depth): limits the maximum depth of each tree to prevent overfitting. Candidate values are [10, 20, 30, 40, 50]. Minimum sample split number (min sample split): the minimum number of samples required to split an internal node. Candidate values are [2, 5, 10]. Minimum sample leaf node number (min sample leaf): the minimum number of samples required for a leaf node. Candidate values are [1, 2, 4]. Maximum number of features (max features): the maximum number of features considered at each split. Candidate values are [0.1, 0.2, 0.5].
[0062] After defining the hyperparameters and their candidate value ranges, the next step is to create all possible hyperparameter combinations, which can be achieved through the parameter grid. The parameter grid is the Cartesian product of all hyperparameter values. Each hyperparameter combination represents a possible model setting and will be used for subsequent model training and evaluation. Depending on the amount of data, the sample dataset is divided into training set, validation set, and test set using a preset partitioning factor. Taking a small amount of data (such as less than or equal to 1000) as an example, the dataset is divided into:
[0063] Training set: 70%
[0064] Validation set: 20%
[0065] Test set: 10%
[0066] For each set of hyperparameter combinations in the parameter grid, the training set is used to train the random forest model. The specific steps are as follows: For each hyperparameter combination, select from the parameter grid in turn. Use the training set data to train the random forest model to learn the relationship between molecular descriptors and pollutant concentrations. After the model is trained, the trained model is applied to the validation set to evaluate the performance of the model. Common performance evaluation indicators include: Accuracy: the proportion of samples predicted correctly. Mean square error (MSE): the average square difference between the predicted value and the actual value. These performance indicators are used to evaluate the pros and cons of each hyperparameter combination. In order to further ensure the stability and generalization ability of the model, a cross-validation method is usually used. The specific steps are as follows: K-fold cross-validation: Divide the training set into K folds, train the model with K-1 folds each time, and use the remaining 1 fold as the validation set. Calculate the accuracy and mean square error of each validation. Finally, calculate the average of the accuracy and mean square error of all K rounds of validation as the performance indicator of the hyperparameter combination. According to the results of the validation set and cross-validation, select the hyperparameter combination with the highest accuracy and the lowest mean square error. If the combination with the highest accuracy is inconsistent with the combination with the lowest mean square error, the weighted formula (such as F = a*X+b*Y, where X is the average accuracy, Y is the average mean square error, a and b are weight coefficients, and a+b=1) can be used to comprehensively consider the two and select the hyperparameter combination with the highest comprehensive score. After selecting the best hyperparameter combination, use the test set to perform a final evaluation of the model to ensure that the model maintains good predictive performance on unseen data. After hyperparameter tuning and performance evaluation, the final random forest model can be used for actual pollutant concentration prediction.
[0067] In some embodiments of the present application, the performance of the model is evaluated by cross-validation, including:
[0068] The training set is divided into K folds. In each fold, K-1 folds are used as training sets to train the random forest model. The performance of the random forest model is evaluated on the last fold: the accuracy and mean square error are recorded. The average accuracy and mean square error of all K rounds are calculated respectively, and the hyperparameters of the random forest model are adjusted based on the average accuracy and mean square error.
[0069] It should be noted that K-fold cross validation is a commonly used model evaluation method. The basic idea is to divide the training set into K subsets (i.e. folds) of equal size. For example, assuming K=5, the training set will be divided into 5 folds, each containing 1 / 5 of the data.
[0070] For example, if the training set has 1000 samples and K=5, each fold will contain 200 samples.
[0071] The core of cross-validation is to train and validate the model on different data partitions. Specifically, in the i-th validation, K-1 folds of data are selected as training sets for training the random forest model.
[0072] The remaining fold is used as a validation set to evaluate the performance of the model. During each training process, the model learns the relationship between molecular descriptors and pollutant concentrations based on K-1 folds of data.
[0073] After the training is completed, the remaining 1-fold data is input into the trained random forest model to evaluate its performance. The evaluation criteria usually include:
[0074] Accuracy: The proportion of samples predicted correctly, reflecting the performance of the model for classification tasks.
[0075] Mean Squared Error (MSE): reflects the error between the predicted value and the true value, suitable for regression tasks.
[0076] By recording the prediction results of each fold, we can obtain the performance of the model under different data partitions.
[0077] After completing K cross-validation, the accuracy and mean square error of each validation are recorded.
[0078] Calculate the average of these K accuracy rates to get an estimate of the overall accuracy performance.
[0079] Similarly, the average of the K-fold mean square errors is calculated to evaluate the overall error level of the model.
[0080] Based on the average accuracy and mean square error obtained by cross-validation, we can determine whether the current hyperparameter combination is optimal.
[0081] Specific adjustment methods include:
[0082] If the accuracy is high and the mean square error is low, it means that the model performs well under the current hyperparameter settings, and the hyperparameters can be further confirmed or fine-tuned.
[0083] If the accuracy is low or the mean square error is high, you may need to readjust the hyperparameters, such as increasing the number of trees, adjusting the maximum depth of the tree, etc.
[0084] This process is repeated many times until the hyperparameter combination with the highest accuracy and lowest mean square error is found.
[0085] Through the above cross-validation method, the performance of the random forest model can be evaluated more stably and comprehensively. The final selected hyperparameter combination will be based on the evaluation results of multiple data folds, so it has good generalization ability and can show good prediction results on different sample sets.
[0086] In some embodiments of the present application, when adjusting the hyperparameters of the random forest model based on the average accuracy and the average mean square error, it includes: assigning a value of 5 to K;
[0087] The evaluation value is calculated based on the average accuracy and the average mean square error. The evaluation value satisfies the following relationship:
[0088] F = a*X+b*Y;
[0089] Where F is the evaluation value, X is the average accuracy, Y is the average mean square error, a is the weight of the average accuracy, b is the weight of the average mean square error, and a+b=1;
[0090] After obtaining the evaluation values, select a set of hyperparameters of the random forest model with the largest evaluation value.
[0091] It should be noted that by introducing the evaluation value F, combined with the weight coefficients of the average accuracy (X) and the average mean square error (Y), a comprehensive evaluation of the model performance can be achieved. This method not only considers the classification accuracy of the model, but also measures the error of the model prediction, thereby avoiding the deviation that may be caused by a single indicator (such as only considering the accuracy). The setting of weight coefficients a and b makes the trade-off between accuracy and mean square error more flexible. Users can adjust the weights of these two indicators according to the needs of specific application scenarios to optimize the overall performance of the model. For example, in some applications, accuracy may be more important, while in other applications, reducing the prediction error may be the primary goal. This flexibility improves the adaptability of the model. The average accuracy and mean square error calculated by K-fold cross validation can effectively prevent the local optimal problem caused by the accidental division of the data set. The use of cross validation ensures the stability and reliability of the hyperparameter selection, so that the model can perform consistently on different data sets. When adjusting the hyperparameter combination, considering the accuracy and mean square error comprehensively helps to enhance the generalization ability of the model. This means that the model can maintain high accuracy while reducing prediction errors when processing new data, thereby improving the performance of the model in practical applications. By calculating the evaluation value F and selecting the maximum value, the decision-making process for hyperparameter selection is simplified. This process is clear and intuitive, which can effectively reduce the time and effort of manual tuning in multiple hyperparameter combinations and improve the efficiency of model tuning. The hyperparameter tuning process is quantified through the formula F=a*X+b*Y, making the tuning process more transparent and controllable. Users can clearly understand and adjust the impact of hyperparameters on model performance, and can further verify and optimize through experimental data.
[0092] In addition, K is assigned a value of 5: this means that in cross validation, the training set is divided into 5 folds, each with the same amount of data. The model will be evaluated in 5 training and validation processes.
[0093] After completing the cross-validation, the average accuracy (X) and the average mean square error (Y) of the model will be obtained.
[0094] These two metrics represent the classification accuracy and prediction error of the model, respectively measuring the performance of the model.
[0095] F = a*X+b*Y: This formula is used to comprehensively evaluate model performance, combining the weighted results of accuracy and mean square error.
[0096] X (average accuracy): reflects the accuracy of the model.
[0097] Y (mean square error): reflects the difference between the model prediction results and the actual results.
[0098] a and b: are weight coefficients, indicating the relative importance of accuracy and mean square error in the final evaluation value.
[0099] a+b=1: This means that the sum of the two weights is 1, ensuring that the evaluation value F is a comprehensive consideration of the accuracy and mean square error, which can be adjusted according to actual conditions.
[0100] Get the evaluation value (F): Among all candidate hyperparameter combinations, calculate the F value of each combination through cross-validation.
[0101] Select the combination with the largest F value: The set of hyperparameter combinations with the largest evaluation value F is considered to be the current optimal hyperparameter settings.
[0102] This means that under the comprehensive evaluation of accuracy and mean square error, this set of hyperparameter combinations makes the overall performance of the model the best.
[0103] The choice of weights a and b can be adjusted according to the priority of the actual task. For example, if classification accuracy is more important than prediction error, the value of a can be increased and the value of b can be reduced.
[0104] According to the change of F value, further fine-tuning can be performed to find a possibly better hyperparameter combination.
[0105] If the F value still does not reach the expected value after multiple iterations, you can consider changing the cross-validation parameter K value or adjusting other parameters of the model.
[0106] Through this method, accuracy and mean square error are taken into consideration to find the hyperparameter combination that achieves the best balance between classification accuracy and prediction error. This approach can help to more comprehensively evaluate and optimize model performance under different weights.
[0107] In some embodiments of the present application, the perturbed molecular descriptor is obtained by adding or subtracting a constant value from the molecular descriptor, and the constant value added or subtracted from all perturbed molecular descriptors is the same.
[0108] In some embodiments of the present application, the atomic composition of the molecules in the drilling fluid sample is ionized by a mass spectrometer, and the mass-charge ratio of the ions is analyzed to obtain information on the atomic composition; the atomic bonding relationship is obtained by nuclear magnetic resonance; the bond length and bond angle are obtained by X-ray diffraction to obtain the atomic position, and the distance and angle between atoms are calculated; the relative position in three-dimensional space is calculated according to density functional theory DFT, and the three-dimensional spatial position of each atom in the molecule is obtained by simulation.
[0109] It is understood that a mass spectrometer can accurately determine the composition of each element in a sample by ionizing the sample and analyzing the mass-to-charge ratio of the ions. This information, including the type and relative abundance of the elements, is the basis for identifying and analyzing the chemical composition of the sample. It provides quantitative and qualitative data for each element in the sample, which helps to understand the chemical composition of the sample. It allows different chemicals to be identified and quantitatively tracked in complex chemical mixtures. It is fast and accurate, suitable for processing a large number of samples and high-throughput analysis needs.
[0110] Nuclear magnetic resonance technology can obtain information about the bonding relationship between atoms, including information about the chemical environment and molecular structure, by measuring the interaction between the spin of the atomic nucleus and the external magnetic field. It accurately reveals the bonding relationship and structural information between atoms in the molecule. It provides detailed chemical shift data, which helps to understand the environment and interactions within the molecule. It is particularly important for determining the molecular structure, especially when the molecule is large or complex. Through X-ray diffraction technology, the precise arrangement information of atoms in the crystal can be obtained, so as to calculate the distance between atoms (bond length) and the angle between atoms (bond angle). It provides high-resolution three-dimensional crystal structure information. Accurately measuring bond lengths and bond angles helps to understand the geometric shape and structural characteristics of molecules. The ability to determine the spatial structure and arrangement of molecules is of great significance to molecular modeling and materials science.
[0111] Density functional theory (DFT) is a quantum mechanical method that simulates the three-dimensional spatial position of atoms in a molecule by calculating the electron density of each atom in the molecule. This theoretical calculation provides a detailed three-dimensional structure of the molecule. It provides molecular three-dimensional structural information with high computational accuracy, which helps to predict and understand the behavior of molecules. It can handle complex molecular systems and predict molecular structures under different chemical environments. It is particularly important for theoretical research and prediction of the properties of new molecules, and helps with molecular design and optimization.
[0112] Through the comprehensive application of the above methods, the detailed characteristics of the molecules in the drilling fluid samples can be fully obtained, including atomic composition, atomic bonding relationship, bond length, bond angle and relative position in three-dimensional space. This information is important for the accurate detection and analysis of pollutants. Combining multiple analytical techniques can provide more comprehensive and accurate molecular characteristic information, reduce the limitations and errors that may be caused by a single method, and improve the reliability and accuracy of the overall detection. These methods provide strong technical support for the processing of complex drilling fluid samples, especially when processing samples containing multiple chemical substances, and can accurately distinguish and analyze different components.
[0113] It should be pointed out that the contribution value of the molecular descriptor to the pollutant concentration is determined by SHAP value analysis, a benchmark contribution threshold is pre-set, and molecular descriptors whose contribution values are greater than or equal to the benchmark contribution threshold are selected respectively, and the molecular descriptors are perturbed to obtain perturbed molecular descriptors and re-input them into the random forest model one by one to obtain the perturbed pollutant concentration; in this process:
[0114] SHAP value analysis is a method for explaining the predictions of machine learning models. Based on the Shap l ey value of cooperative game theory, it can assign an importance score to each feature to measure the contribution of the feature to the model prediction. Through SHAP value analysis, it is possible to identify which molecular descriptors (features) have a significant impact on the prediction of pollutant concentrations. SHAP values provide a specific contribution measure for each feature, making the model's prediction results more transparent and explainable.
[0115] Pre-set baseline contribution threshold: The baseline contribution threshold is a pre-set value used to determine whether the contribution of a molecular descriptor is significant enough. Only when the SHAP value of a molecular descriptor is greater than or equal to the threshold can it be considered to have made an important contribution to the prediction. This threshold helps to screen out descriptors that have a greater impact on the prediction of pollutant concentrations, avoiding attention to features that have little impact on the results, thereby improving the efficiency and interpretability of the model. The selection of this value can be determined according to actual conditions.
[0116] Select molecular descriptors whose contribution values are greater than or equal to the benchmark contribution threshold: Select those molecular descriptors whose SHAP values are greater than or equal to the benchmark contribution threshold, indicating that these descriptors are considered to have a significant impact on the prediction of pollutant concentrations. By focusing only on these important descriptors, the computational complexity can be effectively reduced, and resources can be concentrated on analyzing and optimizing the features that have a significant impact on the prediction.
[0117] Perturb the molecular descriptors: Perturbation refers to modifying or scrambling molecular descriptors to observe the impact of these changes on the model prediction results. For example, perturbed molecular descriptors can be generated by adding or subtracting a constant value. Perturbation helps evaluate the stability and importance of molecular descriptors to model predictions under different conditions. If the results after perturbation change greatly, it means that the descriptor has a significant impact on the prediction.
[0118] Re-input into the random forest model one by one: The perturbed molecular descriptors are input into the random forest model one by one and re-predicted to obtain the perturbed pollutant concentration. By testing these perturbed molecular descriptors in the model, the stability of each descriptor for predicting pollutant concentration can be evaluated. It is possible to identify which descriptors remain important for the prediction results under perturbation and which descriptors cause significant changes in the prediction results under perturbation.
[0119] Obtaining perturbed pollutant concentrations: This refers to using the perturbed molecular descriptors to make model predictions and obtain new pollutant concentration values. These new predictions can be used to calculate the impact of the perturbation and help determine which descriptors contribute significantly to pollutant concentrations and which descriptors may be redundant or unimportant.
[0120] In the above content, the standard deviation of the disturbing pollutant concentration satisfies the following relationship:
[0121]
[0122] in, It represents the standard deviation of the predicted changes caused by the perturbation of the molecular descriptor; the standard deviation reflects the discreteness of the predicted results caused by the perturbation, that is, the variability of the predicted changes. |S| represents the number of perturbation samples, that is, the number of samples generated by the perturbation process. Specifically, this number is the total number of predicted values after all perturbations. It represents the predicted change of the jth perturbation sample. In the jth perturbation sample, the change in the predicted result caused by the perturbation. It is usually the difference between the predicted value of the model under the perturbed molecular descriptor input and the baseline predicted value. Represents the variance of the disturbance prediction change. The variance is calculated as the average of the squared differences between the predicted change value of each disturbance sample and the mean of the predicted change. Here, |S|-1 is used as the denominator to calculate the sample variance (rather than the overall variance), because in sample data, the denominator usually uses |S|-1 for unbiased estimation. It represents the mean of the predicted change of disturbance, that is, the average of the predicted changes of all disturbance samples. The calculation formula is:
[0123]
[0124] See also Figure 2 As shown, an embodiment of the present invention provides an automatic analysis system for detecting characteristic contaminants in drilling fluid, comprising:
[0125] The pre-processing module collects drilling fluid samples, performs molecular structure analysis on the filtered drilling fluid samples, and obtains the three-dimensional structure data of various chemical molecules in the samples;
[0126] A generation module converts the three-dimensional structure data into molecular descriptors, which include the atomic composition of the molecules in the drilling fluid sample, the bonding relationship between atoms, the bond length, the bond angle and the relative position in three-dimensional space;
[0127] The model training module divides the molecular descriptors into training set, validation set and test set based on the random forest model; adjusts the proportion of the training set, validation set and test set according to the data volume of the molecular descriptors; inputs the molecular descriptors in the training set into the random forest model for training to learn the relationship between the molecular descriptors and the pollutant concentration;
[0128] The processing module determines the contribution value of the molecular descriptor to the pollutant concentration through SHAP value analysis, pre-sets a baseline contribution threshold, and screens out molecular descriptors with contribution values greater than or equal to the threshold to identify important features;
[0129] The significance assessment module perturbs the molecular descriptors to generate perturbed molecular descriptors, and re-inputs them into the random forest model one by one to obtain the pollutant concentration after perturbation; the standard deviation of the perturbed pollutant concentration is calculated and compared with the pre-set significance threshold to determine whether to remove the current molecular descriptors.
[0130] In some embodiments of the present application, it also includes:
[0131] The reporting module is configured to select molecular descriptors, output pollutant concentrations and generate reports.
[0132] It is understandable that the pre-processing module collects drilling fluid samples and filters and analyzes their molecular structure to obtain the three-dimensional structural data of various chemical molecules in the sample. Ensuring that the sample is properly processed before analysis and obtaining high-quality raw data will help the accuracy of subsequent analysis. By obtaining three-dimensional structural data, the molecular structural characteristics in the sample can be understood in detail, providing a sufficient information basis for subsequent processing.
[0133] The generation module converts the 3D structure data into molecular descriptors, including atomic composition, bonding relationships between atoms, bond lengths, bond angles, and relative positions in 3D space. The generated molecular descriptors standardize the molecular data and provide a consistent data format for model training and analysis. They cover multiple important features of molecules, allowing the model to be trained and predicted based on comprehensive information, thereby improving the accuracy and reliability of detection.
[0134] The model training module uses the random forest model to train molecular descriptors and learn the relationship between descriptors and pollutant concentrations. The ratio of training set, validation set, and test set is adjusted according to the amount of data. By adjusting the data set division ratio, the model can be effectively trained on data sets of different sizes to improve the generalization ability of the model. By training the random forest model, a relationship model between molecular descriptors and pollutant concentrations can be established to accurately predict pollutant concentrations.
[0135] The processing module determines the contribution of molecular descriptors to pollutant concentrations through SHAP value analysis, screens out descriptors with significant contributions, and evaluates their importance through perturbation processing. Identify molecular descriptors that have a significant impact on pollutant concentrations to improve the interpretability and effectiveness of the model. Through perturbation processing and significance evaluation, ensure that the model takes into account the features that have the greatest impact on the results during the processing process, and reduce the impact of noise and irrelevant information.
[0136] The significance assessment module perturbs the molecular descriptors, obtains the pollutant concentration after perturbation, calculates its standard deviation, and compares it with the significance threshold to determine whether to remove the current descriptor. Through perturbation processing and significance assessment, the stability and importance of the molecular descriptors are further verified, and the stability and reliability of the model are improved. It ensures that only molecular descriptors that actually contribute to the results are retained, thereby optimizing model performance.
[0137] The reporting module selects molecular descriptors, outputs pollutant concentrations, and generates reports. By generating reports, the system can clearly display the test results for users to view and understand. Providing structured data and analysis results helps users make more accurate decisions, especially in drilling fluid quality control and pollutant management.
[0138] The system's automated processing reduces manual intervention and improves detection efficiency and accuracy. By combining multiple analytical techniques and model optimization methods, the system is able to provide high-precision contaminant detection results. Based on detailed molecular data and model analysis results, the system supports data-based decision-making processes, which helps to improve the scientificity and effectiveness of drilling fluid treatment and management. The system is able to comprehensively consider various molecular features in the sample and conduct comprehensive and in-depth analysis to better identify and quantify contaminants.
[0139] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents. Any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. An automatic analysis method for detecting characteristic contaminants in drilling fluids, characterized in that: include: Collecting drilling fluid samples, performing molecular structure analysis on the filtered drilling fluid samples, obtaining three-dimensional structural data of various chemical molecules in the drilling fluid samples, and converting the three-dimensional structural data into molecular descriptors; Based on the random forest model, the molecular descriptors are divided into a training set, a validation set and a test set, and the proportions of the training set, the validation set and the test set are adjusted according to the data volume of the molecular descriptors; the molecular descriptors in the training set are input into the random forest model, and the random forest model is trained to learn the relationship between the molecular descriptors and the pollutant concentration; Determine the contribution value of the molecular descriptor to the pollutant concentration by SHAP value analysis, pre-set a benchmark contribution threshold, select molecular descriptors whose contribution values are greater than or equal to the benchmark contribution threshold, perturb the molecular descriptors, obtain perturbed molecular descriptors, and re-input them into the random forest model one by one to obtain perturbed pollutant concentration; Presetting a significance threshold, and judging whether to remove the current molecular descriptor according to the output standard deviation of the disturbing pollutant concentration and the significance threshold; The three-dimensional structure data includes: the atomic composition of the molecules in the drilling fluid sample, the bonding relationship between atoms, the bond length, the bond angle and the relative position in the three-dimensional space.
2. The automatic analysis method for detecting characteristic contaminants in drilling fluid according to claim 1, characterized in that: When the molecular descriptor is divided into a training set, a validation set and a test set, it includes: Preset a first partition factor, a second partition factor, and a third partition factor, obtain the data volume of the molecular descriptor, and select a partition factor according to the data volume: When the data volume is less than or equal to 1000, a first partitioning factor is selected, and the first partitioning factor is that the training set, validation set and test set account for 70%, 20% and 10% of the data volume respectively; when the data volume is greater than 1000 and less than or equal to 5000, a second partitioning factor is selected, and the second partitioning factor is that the training set, validation set and test set account for 60%, 20% and 20% of the data volume respectively; when the data volume is greater than 5000, a third partitioning factor is selected, and the third partitioning factor is that the training set, validation set and test set account for 80%, 10% and 10% of the data volume respectively.
3. The automatic analysis method for detecting characteristic contaminants in drilling fluid according to claim 2, characterized in that: After the molecular descriptors in the training set were input into the random forest model, the hyperparameters of the random forest model were tuned through the validation set, and the performance of the model was evaluated by cross-validation.
4. The automatic analysis method for detecting characteristic contaminants in drilling fluid according to claim 3, characterized in that: The hyperparameters of the random forest model are tuned using the validation set, including: Define the hyperparameter space and set specific ranges: the number of trees is [100, 200, 300, 400, 500]; the maximum depth is [10, 20, 30, 40, 50]; the minimum number of sample splits is [2, 5, 10]; the minimum number of sample leaf nodes is [1, 2, 4]; the maximum number of features is [0.1, 0.2, 0.5]; Create parameter grid: List the hyperparameter combinations and create a parameter grid for each combination of hyperparameter values; Split the data set: divide the sample data set into training set, validation set and test set according to the division factors at each level; Training the model: For each set of hyperparameter combinations in the parameter grid, use the training set to perform model training.
5. The automatic analysis method for detecting characteristic contaminants in drilling fluid according to claim 4, characterized in that: The performance of the model was evaluated through cross-validation, including: Divide the training set into K folds; in each fold, use K-1 folds as training sets to train the random forest model; The performance of the random forest model was evaluated on the last fold: the accuracy and mean square error were recorded; the average accuracy and mean square error of all K rounds were calculated respectively, and the hyperparameters of the random forest model were adjusted based on the average accuracy and mean square error.
6. The automatic analysis method for detecting characteristic contaminants in drilling fluid according to claim 5, characterized in that: When adjusting the hyperparameters of the random forest model based on the average accuracy and the average mean square error, it includes: assigning K a value of 5; The evaluation value is calculated based on the average accuracy and the average mean square error, and the evaluation value satisfies the following relationship: F = a*X+b*Y; Where F is the evaluation value, X is the average accuracy, Y is the average mean square error, a is the weight of the average accuracy, b is the weight of the average mean square error, and a+b=1; After the evaluation value is obtained, a set of hyperparameters of the random forest model with the largest evaluation value is selected.
7. The automatic analysis method for detecting characteristic contaminants in drilling fluid according to claim 6, characterized in that: The perturbation molecular descriptor is obtained by adding or subtracting a constant value from the molecular descriptor, and the constant value added or subtracted from all perturbation molecular descriptors is the same.
8. The automatic analysis method for detecting characteristic contaminants in drilling fluid according to claim 7, characterized in that: The atomic composition of the molecules in the drilling fluid sample is ionized by a mass spectrometer, and the mass-charge ratio of the ions is analyzed to obtain the atomic composition information; the atomic bonding relationship is obtained by nuclear magnetic resonance; the bond length and bond angle are obtained by X-ray diffraction to obtain the atomic position, and the distance and angle between atoms are calculated; the relative position in the three-dimensional space is calculated according to the density functional theory DFT, and the three-dimensional spatial position of each atom in the molecule is obtained by simulation.
9. An automatic analysis system for detecting characteristic contaminants in drilling fluid, applied to the automatic analysis method for detecting characteristic contaminants in drilling fluid according to any one of claims 1 to 8, characterized in that: The system comprises: The pre-processing module collects drilling fluid samples, performs molecular structure analysis on the filtered drilling fluid samples, and obtains the three-dimensional structure data of various chemical molecules in the samples; A generation module converts the three-dimensional structure data into molecular descriptors, wherein the molecular descriptors include the atomic composition of molecules in the drilling fluid sample, the bonding relationship between atoms, the bond length, the bond angle and the relative position in the three-dimensional space; The model training module divides the molecular descriptors into training set, validation set and test set based on the random forest model; adjusts the proportion of the training set, validation set and test set according to the data volume of the molecular descriptors; inputs the molecular descriptors in the training set into the random forest model for training to learn the relationship between the molecular descriptors and the pollutant concentration; The processing module determines the contribution value of the molecular descriptor to the pollutant concentration through SHAP value analysis, pre-sets a baseline contribution threshold, and screens out molecular descriptors with contribution values greater than or equal to the threshold to identify important features; The significance assessment module perturbs the molecular descriptors to generate perturbed molecular descriptors, and re-inputs them into the random forest model one by one to obtain the pollutant concentration after perturbation; the standard deviation of the perturbed pollutant concentration is calculated and compared with the pre-set significance threshold to determine whether to remove the current molecular descriptors.
10. The automatic analysis system for detecting characteristic contaminants in drilling fluid according to claim 9, characterized in that: Also includes: The reporting module is configured to select the molecular descriptors, output the pollutant concentration and generate a report.
Citation Information
Patent Citations
Method for predicting organic matter PDMS film-air distribution coefficient through quantitative structure-activity relationship model
CN113722988A
Quantitative method for non-targeted screening of perfluorinated and polyfluoroalkyl compounds
CN115308319A
Interpreting machine learning outputs in industrial applications
CN116034321A