Insomnia health state identification method based on magnetocardiogram data and ensemble learning
By extracting multi-dimensional features from magnetocardiogram data and constructing an integrated learning framework, the limitations of traditional insomnia diagnosis methods are overcome, achieving more accurate and stable insomnia identification and improving identification accuracy and model generalization ability.
Patent Information
- Application Number
- CN202511007342.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-22
- Publication Date
- 2025-11-04
AI Technical Summary
Existing methods for diagnosing insomnia rely on subjective reports and complex polysomnography, which suffer from problems such as high subjectivity, complex equipment, and high cost. While magnetocardiography (MCG) technology has potential, it lacks effective feature extraction and classification methods, making it difficult to fully utilize MCG data for accurate identification.
By extracting multi-dimensional features such as time domain, frequency domain, isomagnetic maps, and pseudo current density maps from magnetocardiogram data, the LASSO regression algorithm is used to filter features, the SMOTE algorithm is combined to handle data imbalance, support vector machine and logistic regression models are used for training, and probabilistic fusion is performed through logistic regression meta-model to build an ensemble learning framework.
It significantly improves the comprehensiveness and reliability of feature representation for insomnia identification, enhances the model's generalization ability and robustness, and improves identification accuracy and stability, solving the problems of insufficient single-feature identification accuracy and data imbalance in traditional methods.
Smart Images

Figure CN120895237A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of magnetocardiogram data processing, and more particularly, to an insomnia health state recognition method based on magnetocardiogram data and ensemble learning. BACKGROUND
[0002] Insomnia is a common sleep disorder in modern life, which seriously affects people's physical and mental health and quality of life. At present, the diagnosis of insomnia mainly depends on the subjective report of patients, clinical interview and some traditional physiological signal monitoring, such as polysomnography (PSG). However, these methods have certain limitations. Subjective report and clinical interview are easily affected by subjective factors of patients, while polysomnography can provide more comprehensive sleep physiological information, but its equipment is complex, the monitoring process is cumbersome, and the cost is high, which is difficult to popularize in large-scale population.
[0003] In recent years, with the development of biomedical engineering technology, magnetocardiogram (MCG) as a new non-invasive detection technology has gradually attracted attention. Magnetocardiogram can detect the tiny changes of human heart magnetic field, which is closely related to the electrical physiological activity of the heart, and has high time and space resolution. By analyzing magnetocardiogram data, more information about heart function and autonomic nervous system activity can be obtained, thereby providing new ideas and methods for the diagnosis of insomnia. However, the complexity of magnetocardiogram data is high, containing a large amount of feature information, how to extract effective features related to insomnia from these data and build an accurate and reliable classification model is an important direction of current research.
[0004] In the implementation process of the embodiments of the present application, there are at least the following problems or defects in the prior art: On the one hand, the traditional insomnia diagnosis method depends on subjective report and complex polysomnography, which has the problems of strong subjectivity, complex equipment, high cost, etc.; on the other hand, although the magnetocardiogram technology has potential, there is currently a lack of effective feature extraction and classification methods, making it difficult to fully utilize magnetocardiogram data for accurate identification of insomnia. SUMMARY
[0005] The present application provides an insomnia health state recognition method based on magnetocardiogram data and ensemble learning, comprising:
[0006] S1. Feature extraction: extracting time domain features, frequency domain features, isomagnetic map features, pseudo-current density map features and heart rate variability features from magnetocardiogram data;
[0007] S2. Feature selection: using LASSO regression algorithm to screen the extracted features, and retaining an important feature subset;
[0008] S3. Data division and balancing: divide the screened feature dataset into a training set and a test set, and use the SMOTE algorithm to oversample the training set;
[0009] S4. Model construction and prediction:
[0010] S4.1 Use support vector machine model and logistic regression model as base model, train the training set respectively and output prediction probability;
[0011] S4.2 Combine the prediction probability of the base model into a new feature matrix, input the logistic regression meta-model for final prediction.
[0012] Further, the step S1 comprises:
[0013] S1.1 Extract time domain features: based on P wave, QRS wave, T wave and full segment signal of magnetocardiogram signal, calculate variance, root mean square value, average absolute value, waveform factor, kurtosis and skewness;
[0014] S1.2 Extract frequency domain features: perform fast Fourier transform on each channel signal, calculate median, maximum value, average power frequency and wavelet singular entropy in power spectrum;
[0015] S1.3 Extract isomagnetic map features and pseudo current density map features: calculate amplitude, angle and distance parameters of isomagnetic map, and total current vector and maximum current vector angle of pseudo current density map;
[0016] S1.4 Extract heart rate variability features: calculate time domain, geometric and frequency domain features based on RR interval data.
[0017] Further, the step S2 comprises:
[0018] S2.1 Data preprocessing: process infinite value and missing value in feature data, and normalize the feature data;
[0019] S2.2 Train LASSO regression model, and the objective function is:
[0020]
[0021] Wherein, n is the sample number, i is the sample index, and the value range is from 1 to n; y i is the true label of the i-th sample; β0 is the intercept term; p is the number of features, j is the feature index, and the value range is from 1 to p; x ij is the j-th feature value of the i-th sample; β j is the regression coefficient corresponding to the j-th feature; and α is the regularization parameter, and α = 0.01;
[0022] S2.3Screening coefficients with absolute value greater than the mean, forming an important feature subset.
[0023] Further, the step S3 comprises:
[0024] S3.1Divide the training set and test set in the proportion of 7:3, and use stratified sampling to keep the category proportion consistent.
[0025] S3.2Over-sampling the training set using SMOTE algorithm.
[0026] Further, the step S4.1 comprises:
[0027] S4.1.1Hyperparameter optimization of the support vector machine model, including: C∈[0.1, 1, 10], and the kernel function is linear kernel or radial basis kernel; wherein C is the penalty parameter, used to control the degree of punishment for misclassified samples;
[0028] S4.1.2Hyperparameter optimization of the logistic regression model, including: C∈[0.1, 1, 10], and the regularization type is L1 regularization or L2 regularization; wherein C is the inverse of the regularization strength, and the smaller the value, the greater the regularization strength.
[0029] Further, the support vector machine model outputs the prediction probability P1 by Platt scaling method, and the formula is:
[0030]
[0031] Wherein, i is the sample index; P1 i is the prediction probability of the i-th sample after Platt scaling by the support vector machine model; A, B are fitting parameters; f(x i ) is the output value of the support vector machine model for the i-th sample x i .
[0032] Further, the step S4.2 comprises:
[0033] S4.2.1Combining the prediction probability P1 of the support vector machine model and the prediction probability P2 of the logistic regression model into an m×2 new feature matrix X new :
[0034]
[0035] Wherein, m is the sample number; P1 i is the prediction probability of the i-th sample of the support vector machine model; P2 i is the prediction probability of the i-th sample of the logistic regression model.
[0036] S4.2.2 trains and predicts the new feature matrix by using a logistic regression meta-model, and the final prediction probability P final The calculation formula is as follows:
[0037]
[0038] Wherein, Y is the predicted category, Y = 1 represents the insomnia category; X new is the new feature matrix; X new1 and X new2 correspond to the feature values in the P1 and P2 columns of the new feature matrix respectively; β0 is the intercept term of the logistic regression meta-model; β1 and β2 are the regression coefficients corresponding to X new1 and X new2 .
[0039] Further, the final prediction category determination rule is as follows:
[0040] If P final ≥ 0.5, it is determined as the insomnia category, otherwise it is determined as the healthy category; wherein P final is the final prediction probability output by the logistic regression meta-model.
[0041] Further, the training of the base model and the meta-model in the step S4 adopts 5-fold cross-validation for hyperparameter optimization.
[0042] Further, it further comprises:
[0043] S5. Model evaluation: the model performance is evaluated by using 10-fold cross-validation, and the accuracy, precision, sensitivity, specificity, F1 value and ROC-AUC index are calculated.
[0044] The above embodiments of the present application have at least the following beneficial effects:
[0045] 1. By comprehensively extracting the multi-dimensional features of the magnetocardiogram signal such as time domain, frequency domain, magnetogram, pseudo-current density map and heart rate variability, the problem of insufficient recognition accuracy caused by the dependence of the traditional insomnia diagnosis method on single feature is solved, and the comprehensiveness and reliability of feature representation are significantly improved, providing more abundant biomarker information for accurate recognition of insomnia state.
[0046] 2. LASSO regression is used for feature selection, and SMOTE algorithm is used to process the data imbalance problem, which effectively eliminates redundant features and enhances the weight of minority class samples, overcomes the overfitting risk brought by high-dimensional features and the influence of sample distribution on model performance, and makes the model have better generalization ability and robustness.
[0047] 3. A high-efficiency ensemble learning framework is constructed by using support vector machines and logistic regression as base models and performing probability fusion through a logistic regression meta-model, which not only retains the complementary advantages of different base models but also optimizes the final decision through probability weighting, thereby improving the accuracy of insomnia recognition while enhancing the stability and interpretability of the model. BRIEF DESCRIPTION OF DRAWINGS
[0048] The above and other objects, features and advantages of the present application will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings in which a number of embodiments of the application are shown by way of illustration, now embodying the principle of the present application. In the drawings:
[0049] Figure 1 A flowchart of an insomnia health state recognition method based on magnetocardiographic data and ensemble learning is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0050] The principles and spirits of the present application will be described below with reference to a number of exemplary embodiments. It should be understood that these embodiments are given only so that those skilled in the art can better understand and implement the present application, and do not limit the scope of the present application in any way. On the contrary, these embodiments are provided so that the present application is more thorough and complete, and the scope of the present application is fully conveyed to those skilled in the art.
[0051] Those skilled in the art will appreciate that embodiments of the present application can be implemented as a system, device, apparatus, method or computer program product. Therefore, the present application can be embodied in the form of entire hardware, entire software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0052] It should be noted that any number of elements in the accompanying drawings are used for illustration only and not limitation, and any naming is only for distinction and does not have any limiting meaning.
[0053] Reference will now be made to Figure 1 , Figure 1 A flowchart of an insomnia health state recognition method based on magnetocardiographic data and ensemble learning is provided for an embodiment of the present application. As shown in Figure 1 , an insomnia health state recognition method based on magnetocardiographic data and ensemble learning includes:
[0054] S1. Feature extraction: extracting time domain features, frequency domain features, magnetocardiogram features, pseudo-current density map features and heart rate variability features from magnetocardiographic data;
[0055] S2. Feature selection: using LASSO regression algorithm to screen the extracted features and retaining an important feature subset;
[0056] S3. Data division and balancing: Divide the screened feature dataset into training set and test set, and use SMOTE algorithm to oversample the training set;
[0057] S4. Model construction and prediction:
[0058] S4.1 Use support vector machine model and logistic regression model as base model, train the training set respectively and output prediction probability;
[0059] S4.2 Combine the prediction probability of base model into new feature matrix, input logistic regression meta-model for final prediction.
[0060] It should be noted that the core of the method is to realize the recognition of insomnia health status through multi-dimensional feature extraction of magnetocardiogram data and ensemble learning algorithm. Magnetocardiogram data refers to the human heart magnetic field signals detected by magnetocardiogram (MCG) device, which can reflect the electrical physiological activity of heart and the regulation state of autonomic nervous system. Feature extraction is the process of obtaining effective information related to insomnia from original magnetocardiogram data, including time domain features, frequency domain features, etc. These features can describe the characteristics of magnetocardiogram signals from different angles. LASSO regression algorithm is a linear regression analysis method, which introduces a regularization term to select important feature subsets, thereby reducing feature dimension and improving model generalization ability. Data division and balancing is to ensure the effectiveness and reliability of model training and testing, by dividing the training set and test set, and using oversampling algorithm to handle the class imbalance problem in training set. Model construction and prediction is to use machine learning models such as support vector machine and logistic regression to learn the training set, and integrate the prediction results of base model through meta-model, finally realize the accurate recognition of insomnia health status.
[0061] Specifically, in the feature extraction step, the time-domain features refer to the statistical features calculated based on the P-wave, QRS-wave, T-wave, and full segment signal of the magnetocardiogram, such as variance, root mean square value, etc., which can reflect the amplitude variation and stability of the signal. The frequency-domain features are the power spectrum features obtained by performing fast Fourier transform on the magnetocardiogram, such as the median and maximum value of the power spectrum, etc., which are used to describe the frequency components of the signal. The magnetocardiogram features and pseudo-current density map features are extracted from the spatial distribution of the magnetocardiogram data, which can reflect the spatial characteristics of the cardiac magnetic field. The heart rate variability features are calculated based on the RR interval data, which reflect the regulation function of the autonomic nervous system. In the feature selection step, the objective function of the LASSO regression algorithm selects features by minimizing the prediction error and the regularization term, where the regularization parameter λ controls the sparsity of feature selection. In the data division and balancing step, the training set and test set are divided according to the 7:3 ratio, and stratified sampling is used to maintain consistent class proportions to ensure the representativeness of the training set and test set. The SMOTE algorithm is an oversampling technique that generates new minority class samples to solve the class imbalance problem. In the model construction and prediction step, the support vector machine model is trained by selecting appropriate hyperparameters (such as penalty parameter C and kernel function), and the logistic regression model is optimized by adjusting the regularization strength and other parameters. The prediction probability of the base model is converted into a new feature matrix by a specific method, which is input into the logistic regression meta-model for final prediction.
[0062] Preferably, in the feature extraction step, for the time domain features, the variance, root mean square, mean absolute value, etc. of the magnetocardiogram signal can be calculated, which can describe the amplitude variation and stability of the signal from different angles. For example, the variance reflects the fluctuation degree of the signal, and the root mean square value represents the effective amplitude of the signal. In the extraction of frequency domain features, the median, maximum value, average power frequency, etc. of the power spectrum are calculated by performing fast Fourier transform on the magnetocardiogram signal, which can reflect the frequency component distribution of the signal. The extraction of magnetogram features and pseudo-current density map features involves calculating the amplitude, angle, distance parameters of the magnetogram, and the total current vector and maximum current vector angle of the pseudo-current density map, which can reflect the spatial distribution characteristics of the cardiac magnetic field. In the feature selection step, the objective function of the LASSO regression algorithm filters the features by minimizing the prediction error and the regularization term, and the regularization parameter λ is set to 0.01. By training the LASSO regression model, the features with absolute value greater than the mean are selected to form the important feature subset. In the data division and balancing step, the training set and the test set are divided in the ratio of 7:3 to ensure that the class proportions of the training set and the test set are consistent. For the class imbalance problem in the training set, the SMOTE algorithm is used for oversampling to balance the class distribution by generating new minority class samples. In the model construction and prediction step, in the hyperparameter tuning of the support vector machine model, the penalty parameter C can be set to [0.1, 1, 10], and the kernel function can be selected as linear kernel or radial basis kernel. The optimal combination of hyperparameters is selected by cross-validation. In the hyperparameter tuning of the logistic regression model, the inverse of the regularization strength C can be set to [0.1, 1, 10], and the regularization type can be selected as L1 regularization or L2 regularization. The optimal hyperparameters are also selected by cross-validation. The prediction probability of the base model is converted to probability value by Platt scaling method, and then the prediction probabilities of the support vector machine model and the logistic regression model are combined into a new feature matrix, which is input into the logistic regression meta-model for final prediction. In the training process of the logistic regression meta-model, the model parameters are optimized by minimizing the prediction error, and the final output prediction probability is used to determine the insomnia class. If the prediction probability is greater than or equal to 0.5, it is determined as the insomnia class, otherwise it is determined as the healthy class.
[0063] In some embodiments, the step S1 comprises:
[0064] S1.1 Extracting time domain features: calculating variance, root mean square, mean absolute value, waveform factor, kurtosis, skewness based on P wave, QRS wave, T wave and full segment signal of magnetocardiogram;
[0065] S1.2 Extracting frequency domain features: performing fast Fourier transform on each channel signal to calculate median, maximum value, average power frequency and wavelet singular entropy of power spectrum;
[0066] S1.3 Extracting isomagnetic map features and pseudo-current density map features: calculating the amplitude, angle, and distance parameters of the isomagnetic map, and the total current vector and maximum current vector angle of the pseudo-current density map;
[0067] S1.4 Extracting heart rate variability features: calculating time domain, geometric, and frequency domain features based on RR interval data.
[0068] It should be noted that the feature extraction step of the method is one of the key steps for identifying the insomnia health status. By extracting multiple features from the magnetocardiogram data, the characteristics of the magnetocardiogram signal can be comprehensively reflected, thereby providing rich information for subsequent insomnia state recognition. Time domain features are statistical quantities calculated based on the waveform characteristics of the magnetocardiogram signal, which can reflect the amplitude variation and stability of the signal. Frequency domain features are obtained by performing fast Fourier transform (FFT) on the magnetocardiogram signal, which can reflect the frequency component distribution of the signal. Isomagnetic map features and pseudo-current density map features are features extracted from the spatial distribution of magnetocardiogram data, which can reflect the spatial characteristics of the cardiac magnetic field. Heart rate variability features are features calculated based on RR interval data, which reflect the regulation function of the autonomic nervous system. The extraction of these features provides a basis for subsequent feature selection and model construction.
[0069] Specifically, the extraction of time domain features includes analyzing the P wave, QRS wave, T wave, and full segment signal of the magnetocardiogram signal, and calculating statistical quantities such as variance, root mean square value, average absolute value, waveform factor, kurtosis, and skewness. Variance is used to measure the degree of fluctuation of the signal, root mean square value represents the effective amplitude of the signal, average absolute value reflects the average intensity of the signal, and waveform factor, kurtosis, and skewness are used to describe the shape characteristics of the signal. The extraction of frequency domain features is performed by performing fast Fourier transform on each channel signal to calculate the median, maximum value, average power frequency, and wavelet singular entropy of the power spectrum. The median and maximum value of the power spectrum reflect the main frequency components of the signal, the average power frequency represents the average frequency distribution of the signal, and the wavelet singular entropy is used to describe the complexity of the signal. The extraction of isomagnetic map features and pseudo-current density map features includes calculating the amplitude, angle, and distance parameters of the isomagnetic map, and the total current vector and maximum current vector angle of the pseudo-current density map. These parameters can reflect the spatial distribution and intensity variation of the cardiac magnetic field. The extraction of heart rate variability features is based on RR interval data, and time domain, geometric, and frequency domain features are calculated, such as the standard deviation of RR interval, the root mean square value of adjacent RR interval difference, etc. These features can reflect the regulation function of the autonomic nervous system.
[0070] Preferably, in the time domain feature extraction, the variance, root mean square value and other statistical quantities of the P wave, QRS wave and T wave of the magnetocardiogram signal can be calculated respectively. For example, for the variance calculation of the P wave, the P wave signal can be extracted first, and then the difference between the average of the square values and the square of the average can be calculated. In the frequency domain feature extraction, the fast Fourier transform converts the time domain signal into the frequency domain signal, and by calculating the median and maximum of the power spectrum, the main frequency component of the signal can be determined. For example, the median of the power spectrum can be obtained by sorting the power spectrum values and taking the middle value, and the maximum of the power spectrum is the maximum value in the power spectrum. In the extraction of magnetocardiogram features, the amplitude of the magnetocardiogram can be obtained by calculating the absolute value of the magnetic field strength, and the angle and distance parameters can be calculated by the geometric method to calculate the angle and distance between the magnetic field vectors. In the extraction of pseudo-current density map features, the total current vector can be obtained by summing all the current vectors, and the maximum current vector angle can be obtained by calculating the angle between the maximum current vector and other vectors. In the extraction of heart rate variability features, when calculating the time domain features based on the RR interval data, the standard deviation of the RR interval can be calculated, and the square root of the average of the sum of the squares of the differences between all RR interval values and the average value can be obtained. The extraction process of these features provides accurate input data for subsequent feature selection and model construction.
[0071] In some embodiments, the step S2 comprises:
[0072] S2.1 Data preprocessing: processing infinite values and missing values in the feature data, and normalizing the feature data;
[0073] S2.2 Training LASSO regression model, the objective function is:
[0074]
[0075] where n is the number of samples, i is the sample index, and the value range is from 1 to n; y i is the true label of the i-th sample; β0is the intercept term; p is the number of features, j is the feature index, and the value range is from 1 to p; x ij is the j-th feature value of the i-th sample; β j is the regression coefficient corresponding to the j-th feature; and α is the regularization parameter, and α = 0.01;
[0076] S2.3 Selecting features with absolute value greater than the mean to form an important feature subset.
[0077] It is worth noting that feature selection is a key step in this method for optimizing the feature set and improving the performance of the model. By using the LASSO regression algorithm to screen the extracted features, redundant features can be removed, and a subset of features that contribute significantly to the identification of insomnia health status can be retained. LASSO regression is a linear regression analysis method that achieves feature selection by introducing a regularization term. The regularization parameter controls the sparsity of feature selection, and the smaller the value, the stronger the compression of the model on the features. In this method, the regularization parameter is set to 0.01 to balance the strictness of feature selection and the complexity of the model. By screening features with absolute values greater than the mean, a simplified and efficient feature subset can be constructed, providing high-quality input data for subsequent model training.
[0078] Specifically, the goal of the LASSO regression algorithm is to optimize the model by minimizing the prediction error and the regularization term. The prediction error is used to measure the fitting degree of the model to the training data, while the regularization term is used to achieve the sparsity of the features. During the data preprocessing stage, it is necessary to handle the outliers and missing values in the feature data. Outliers can be replaced by setting a reasonable threshold, such as replacing infinite values with twice the maximum value of the feature. For missing values, mean filling or median filling methods can be used for processing. Normalization is to scale all feature values to the [0, 1] interval, and the specific method is to subtract the minimum value of each feature from the feature value, and then divide by the difference between the maximum and minimum values of the feature. Normalized data can eliminate the dimension difference between different features, and improve the training efficiency and stability of the LASSO regression model. By training the LASSO regression model, the regression coefficients of each feature can be obtained, and then the features with absolute values greater than their mean can be screened to form an important feature subset.
[0079] Preferably, in the feature selection step, data preprocessing is a key pre-operation. First, handle outliers in feature data, such as replacing infinite values with twice the maximum value of the feature, to avoid the impact of outliers on model training. For missing values, use mean filling or median filling methods to ensure data integrity. Next, normalize the feature data to scale all feature values to the [0, 1] interval to eliminate the dimension difference between different features. When training the LASSO regression model, the model parameters are optimized by minimizing the prediction error and the regularization term. The regularization parameter is set to 0.01, and by adjusting this parameter, the sparsity of feature selection can be controlled. Finally, by screening features with absolute values greater than the mean, a simplified and effective feature subset is obtained. This process not only reduces the feature dimension, but also improves the generalization ability of the model, providing high-quality input data for subsequent model training.
[0080] In some embodiments, the step S3 comprises:
[0081] S3.1 Divide the training set and test set in a 7:3 ratio, and use stratified sampling to keep the class ratio consistent;
[0082] S3.2 Use SMOTE algorithm for oversampling processing on the training set.
[0083] It should be noted that data division and balancing are key steps in this method to ensure the effectiveness and reliability of model training and testing process. Data division refers to dividing the screened feature dataset into training set and test set, so as to train the model on the training set and evaluate the performance of the model on the test set. Stratified sampling method can keep the proportion of each class in the training set and test set consistent, so as to avoid the model bias caused by uneven class distribution. Data balancing is to deal with the class imbalance problem in the training set by oversampling algorithm (such as SMOTE) to improve the recognition ability of the model to the minority class. In this method, the division ratio of training set and test set is 7:3, which aims to ensure that the training set has enough data for model learning, and the test set also has enough data for model evaluation.
[0084] Specifically, in the data division step, the division ratio of training set and test set is 7:3, which means that 70% of the data is used for training the model and 30% of the data is used for testing the model. Stratified sampling is a sampling method that ensures that the class ratio in the training set and test set is consistent with the ratio in the original dataset. For example, if the ratio of insomnia class and healthy class in the original dataset is 1:2, then the ratio of the two classes in the divided training set and test set should also be 1:2. In the data balancing step, SMOTE algorithm is an oversampling technique that increases the number of minority class samples by inserting new synthetic samples between minority class samples, so as to balance the class distribution in the dataset. The purpose of oversampling processing is to improve the recognition ability of the model to the minority class, and to avoid the model bias to the majority class caused by class imbalance.
[0085] Preferably, in the data division step, stratified sampling method can be used to divide the dataset into training set and test set. The specific operation is to stratify according to the class labels in the dataset, and then extract samples from each class in the ratio of 7:3 to ensure that the class ratio of the training set and the test set is consistent with the original dataset. For example, if there are 100 insomnia class samples and 200 healthy class samples in the original dataset, then after division, the training set should contain 70 insomnia class samples and 140 healthy class samples, and the test set should contain 30 insomnia class samples and 60 healthy class samples. In the data balancing step, the specific operation of the SMOTE algorithm is to select the nearest neighbor samples of the minority class samples, and generate new synthetic samples between them. For example, for a minority class sample, the algorithm will find its nearest several samples of the same class, and then interpolate between these samples to generate new samples until the number of minority class samples is equal to the number of majority class samples or reaches the preset balancing ratio. In this way, the class imbalance problem can be effectively solved, and the recognition ability of the model for the minority class can be improved.
[0086] In some embodiments, the step S4.1 comprises:
[0087] S4.1.1 hyperparameter tuning of the support vector machine model, the hyperparameters including: C∈[0.1, 1, 10], the kernel function being linear kernel or radial basis kernel; wherein C is a penalty parameter for controlling the degree of punishment for misclassified samples;
[0088] S4.1.2 hyperparameter tuning of the logistic regression model, the hyperparameters including: C∈[0.1, 1, 10], the regularization type being L1 regularization or L2 regularization; wherein C is the inverse of the regularization strength, and the smaller the value, the greater the regularization strength.
[0089] It should be noted that model construction and prediction are the core steps of the method for recognizing insomnia health status. In this step, first, the support vector machine (SVM) model and the logistic regression (LR) model are used as base models to train the training set and output prediction probabilities. Support vector machine is a classification model based on statistical learning theory, which maximizes the interval between different classes by finding the optimal hyperplane, thereby realizing classification. Logistic regression is a generalized linear model for handling binary classification problems, which predicts the probability of a sample belonging to a certain class by fitting a logistic function. The prediction probabilities of the base models are then combined into a new feature matrix and input into the logistic regression meta-model for final prediction. This ensemble learning method can effectively improve the generalization ability and prediction accuracy of the model.
[0090] Specifically, the hyperparameter tuning of the support vector machine model involves the selection of the penalty parameter C and the kernel function. The penalty parameter C is used to control the degree of punishment for misclassified samples, and the larger the value, the more stringent the model's punishment for misclassification. The kernel function is used to map the data to a high-dimensional space in order to find the optimal hyperplane in the high-dimensional space. Common kernel functions include linear kernel and radial basis kernel. Linear kernel is suitable for linearly separable data, while radial basis kernel is suitable for non-linearly separable data. The hyperparameter tuning of the logistic regression model involves the selection of the inverse of the regularization strength C and the regularization type. The smaller the inverse of the regularization strength C, the greater the regularization strength, and the stronger the compression of the model on the features. The regularization type includes L1 regularization and L2 regularization, L1 regularization can achieve feature sparsity, while L2 regularization can prevent model overfitting. In this method, the penalty parameter C of the support vector machine model can be set to [0.1, 1, 10], and the kernel function can be selected as linear kernel or radial basis kernel; the inverse of the regularization strength C of the logistic regression model can be set to [0.1, 1, 10], and the regularization type can be selected as L1 or L2.
[0091] Preferably, in the construction of the support vector machine model, cross-validation can be performed on the training set to determine the optimal penalty parameter C and kernel function type. For example, the training set can be divided into several subsets, and different C values and kernel functions are used for training and validation, and finally the parameter combination that makes the validation set accuracy the highest is selected. For the logistic regression model, the optimal inverse of the regularization strength C and the regularization type can also be selected through cross-validation. In the output of the prediction probability, the support vector machine model can convert the output of its decision function into a probability value through the Platt scaling method. Specifically, Platt scaling maps the output of the support vector machine to the [0, 1] interval by fitting a logistic function, thereby obtaining the prediction probability of the sample belonging to a certain class. The logistic regression model directly outputs the probability of the sample belonging to a certain class. Finally, the prediction probabilities of the two base models are combined into a new feature matrix, which is input into the logistic regression meta-model for final prediction. The training process of the meta-model optimizes the model parameters by minimizing the prediction error, thereby obtaining the final prediction result.
[0092] In some embodiments, the support vector machine model outputs a prediction probability P1 through the Platt scaling method, and the formula is:
[0093]
[0094] where i is the sample index; P1 i is the prediction probability of the i-th sample after Platt scaling by the support vector machine model; A, B are fitting parameters; f(x i is the output value of the support vector machine model for the i-th sample x i .
[0095] It should be noted that the support vector machine model outputs prediction probabilities through the Platt scaling method in order to convert the support vector machine output into a more understandable and usable probability form. The support vector machine is a powerful classification model, but it itself outputs a decision function value rather than a probability. Platt scaling is a post-processing method that maps the support vector machine output value into the probability interval [0, 1] by fitting a logistic function, so as to obtain the prediction probability of the sample belonging to a certain category. This method makes the output of the support vector machine more interpretable and can be integrated with other probability-based models.
[0096] Specifically, the output value of the support vector machine is the decision function value of the model for the input sample, which is a real number value representing the distance of the sample from the classification hyperplane. The larger the value, the more the sample tends to belong to a certain category. The Platt scaling method converts the support vector machine output value into a probability value by introducing two fitting parameters. These two parameters are obtained by fitting a logistic function on the training set. The role of the logistic function is to map the support vector machine output value into the interval [0, 1], so as to obtain the prediction probability of the sample belonging to a certain category. In practical applications, the Platt scaling method optimizes these two parameters by minimizing the error of the logistic function, so that the converted probability value is closer to the true label distribution of the sample. The core of this method is to convert the decision function output value of the support vector machine into a probability value, thereby improving the interpretability of the model output.
[0097] Preferably, when implementing the Platt scaling of the support vector machine model, the training set can be divided into two parts: one part is used to train the support vector machine model, and the other part is used to fit the parameters of the Platt scaling. The specific steps are as follows: first, use the support vector machine model to train the training set to obtain the decision function of the model. Then, use the decision function to predict the samples in the fitting set to obtain the output value of each sample. Next, the fitting parameters are optimized by minimizing the error of the logistic function, so that the difference between the output value of the logistic function and the true label of the sample is minimized. Finally, the output value of the support vector machine is converted into a probability value through the optimized parameters, so as to estimate the prediction probability of the sample belonging to a certain category. This method not only improves the interpretability of the support vector machine output, but also facilitates the integration of its output with other models, thereby improving the performance of the overall model.
[0098] In some embodiments, the step S4.2 comprises:
[0099] S4.2.1 Combining the prediction probability P1 of the support vector machine model and the prediction probability P2 of the logistic regression model into an m x 2 new feature matrix X new :
[0100]
[0101] where m is the number of samples; P1 i is the prediction probability of the i-th sample support vector machine model; P2 i is the prediction probability of the i-th sample logistic regression model;
[0102] S4.2.2 uses the logistic regression meta-model to train and predict the new feature matrix, and the final prediction probability P final is calculated by the formula:
[0103]
[0104] where Y is the predicted category, Y = 1 represents the insomnia category; X new is the new feature matrix; X new1 , X new2 correspond to the feature values in the P1 and P2 columns of the new feature matrix, respectively; β0 is the intercept term of the logistic regression meta-model; β1 and β2 are the regression coefficients corresponding to X new1 and X new2 , respectively.
[0105] It should be noted that in this method, the prediction probability of the support vector machine model and the prediction probability of the logistic regression model are combined into a new feature matrix, and input into the logistic regression meta-model for final prediction, which is a typical ensemble learning strategy. Ensemble learning improves the overall prediction performance by combining the prediction results of multiple models. The support vector machine model and the logistic regression model are base models that learn and predict data from different perspectives, while the logistic regression meta-model integrates the prediction results of the base models to obtain a more accurate final prediction result. This method can fully utilize the advantages of each base model, while compensating for the shortcomings of individual models, thereby improving the generalization ability and prediction accuracy of the overall model.
[0106] Specifically, the prediction probability of the support vector machine model refers to the estimated probability of each sample belonging to a certain category, which reflects the confidence of the model in classifying samples. The prediction probability of the logistic regression model is the probability value of the sample belonging to a certain category calculated by the logistic function inside the model. The new feature matrix is a matrix composed of the prediction probabilities of the two base models, where each row corresponds to a sample and each column corresponds to the prediction probability of a base model. The logistic regression meta-model is a new logistic regression model that takes the new feature matrix as input, learns the relationship between the prediction probabilities of the base models and the true labels, and outputs the final prediction probability. The final prediction probability is the estimated probability of the sample belonging to the insomnia category, and the sample category is determined by setting a threshold (such as 0.5).
[0107] Preferably, when constructing the new feature matrix, the prediction probabilities of the support vector machine model and the prediction probabilities of the logistic regression model can be combined as two features respectively into a two-dimensional feature matrix. For example, if there are n samples, the size of the new feature matrix is 2n, where the first column is the prediction probability of the support vector machine model and the second column is the prediction probability of the logistic regression model. When training the logistic regression meta-model, cross-validation can be used to select the optimal regularization parameter to prevent overfitting. For example, different regularization strength values (such as 0.1, 1, 10) can be tried, and the performance of the model is evaluated by cross-validation to select the best parameter. Finally, the logistic regression meta-model will output the prediction probability of each sample belonging to the insomnia category, and if the probability is greater than or equal to 0.5, the sample is determined to be in the insomnia category, otherwise it is determined to be in the healthy category. This method can effectively improve the accuracy and reliability of insomnia health status recognition by integrating the prediction results of multiple models.
[0108] In some embodiments, the final prediction category determination rule is:
[0109] If P final ≥ 0.5, it is determined to be in the insomnia category, otherwise it is determined to be in the healthy category; wherein P final is the final prediction probability output by the logistic regression meta-model.
[0110] It should be noted that the final prediction category determination rule in this method is based on the final prediction probability output by the logistic regression meta-model to determine the health status of the sample. The logistic regression meta-model integrates the prediction probabilities of the base models to output a probability value of each sample belonging to the insomnia category. By setting a threshold (such as 0.5), it can be determined whether the sample belongs to the insomnia category according to the probability value. This method makes the decision-making process of the model more clear and interpretable, and also provides a flexible adjustment method, which can balance the sensitivity and specificity of the model by changing the threshold.
[0111] Specifically, the output probability of the logistic regression meta-model refers to the estimated probability of each sample belonging to the insomnia category. This probability value is obtained by weighting and processing the prediction probabilities of the base models by the meta-model. The prediction probabilities of the base models are the prediction results of the support vector machine model and the logistic regression model for the sample, which are combined into a new feature matrix input to the meta-model. The meta-model learns the relationship between these prediction probabilities and the true labels to output the final prediction probability. The final prediction probability is a value between 0 and 1, representing the confidence of the sample belonging to the insomnia category. The threshold value of 0.5 is a commonly used decision boundary, when the prediction probability is greater than or equal to 0.5, the sample is determined to be in the insomnia category; otherwise, the sample is determined to be in the healthy category.
[0112] Preferably, further analysis and adjustment can be made on the output of the logistic regression meta-model when making the final prediction class decision. For example, the performance of the model can be evaluated by plotting the receiver operating characteristic curve (ROC curve), and the optimal threshold can be selected. The ROC curve shows the sensitivity and specificity of the model at different thresholds, and by selecting the threshold that maximizes the area under the curve (AUC), the classification performance of the model can be improved. In addition, in practical applications, the threshold can be adjusted according to specific needs to balance the sensitivity and specificity of the model to the insomnia class. For example, in the screening of insomnia, it may be more desirable to improve the sensitivity to reduce missed diagnoses; while in the diagnosis stage, more attention may be paid to the specificity to reduce misdiagnosis. By flexibly adjusting the threshold, the method can better adapt to different application scenarios and needs.
[0113] In some embodiments, the training of the base model and the meta-model in step S4 is performed using 5-fold cross-validation for hyperparameter tuning.
[0114] It should be noted that the training of the base model and the meta-model mentioned in this method is performed using 5-fold cross-validation for hyperparameter tuning, which is a widely used technique in machine learning model optimization. The purpose of cross-validation is to evaluate the performance of the model and select the optimal hyperparameters by dividing the dataset into multiple small parts and then training and validating on different subsets. 5-fold cross-validation means that the dataset is divided into 5 subsets, 4 of which are used for training and 1 for validation, and this process is repeated 5 times, each time selecting a different subset as the validation set. This method can effectively prevent overfitting of the model and ensure the generalization ability of the model on unseen data.
[0115] Specifically, the process of 5-fold cross-validation includes: first, randomly divide the dataset into 5 subsets of similar size. In each iteration, one of the subsets is selected as the validation set and the remaining 4 subsets are combined as the training set. Then, the model is trained using the training set and the performance of the model is evaluated on the validation set, such as by calculating accuracy, recall, etc. This process is repeated 5 times, each time selecting a different subset as the validation set, and the average of the 5 validation results is taken as the evaluation indicator of the model performance. Hyperparameter tuning refers to optimizing the performance of the model by adjusting the parameters and kernel function types of the model, the regularization strength of the logistic regression, etc. In each cross-validation, different combinations of hyperparameters are tried, and the parameter combination that best optimizes the performance of the validation set is selected.
[0116] Preferably, when implementing 5-fold cross-validation for hyperparameter tuning, the following steps can be taken: First, randomly shuffle the dataset to ensure the uniformity of data distribution. Then, divide the dataset into 5 subsets, each containing approximately 20% of the data. In each iteration, select one subset as the validation set and the remaining 4 subsets as the training set. For the support vector machine model, perform a grid search within the pre-set hyperparameter range (such as the penalty parameter from 0.1 to 10 and the kernel function selection linear kernel or radial basis kernel), try all possible parameter combinations, and record the performance indicators of each validation. For the logistic regression model, also search within the pre-set regularization strength range (such as from 0.1 to 10) and record the performance indicators. After completing 5 iterations, calculate the average performance indicators of each parameter combination, and select the parameter combination with the best average performance as the final hyperparameters. In this way, the model can fully utilize all the data during training, and through multiple validations, it avoids performance fluctuations caused by different data divisions, thereby improving the stability and reliability of the model.
[0117] In some embodiments, further comprising:
[0118] S5. Model evaluation: Evaluate model performance using 10-fold cross-validation, calculate accuracy, precision, sensitivity, specificity, F1 value, ROC-AUC indicators.
[0119] It should be noted that the model evaluation mentioned in the present application is completed by 10-fold cross-validation, which is a commonly used model performance evaluation method. 10-fold cross-validation divides the dataset into 10 subsets, 9 of which are used for training and 1 for testing, and this process is repeated 10 times, each time selecting a different subset as the test set. This method can fully utilize all the data in the dataset, while avoiding the randomness of performance evaluation results caused by different data divisions. By calculating accuracy, precision, sensitivity, specificity, F1 value, ROC-AUC and other indicators, the performance of the model can be comprehensively evaluated. These indicators reflect the classification ability and generalization ability of the model from different angles.
[0120] Specifically, the process of 10-fold cross-validation is as follows: first, randomly divide the dataset into 10 subsets of similar size. In each iteration, select one subset as the test set and the remaining 9 subsets as the training set. Then, train the model using the training set and evaluate the model's performance on the test set. Performance indicators include accuracy (the proportion of samples correctly classified by the model), precision (the proportion of samples predicted as positive by the model that are actually positive), sensitivity (the proportion of samples correctly predicted as positive by the model relative to the actual positive samples), specificity (the proportion of samples correctly predicted as negative by the model relative to the actual negative samples), F1 value (the harmonic mean of precision and sensitivity), and ROC-AUC (the area under the receiver operating characteristic curve, reflecting the classification performance of the model at different thresholds). These indicators can comprehensively evaluate the performance of the model and help select the optimal model.
[0121] Preferably, when implementing 10-fold cross-validation for model evaluation, the following steps can be taken: first, randomly shuffle the dataset to ensure the uniformity of data distribution. Then, divide the dataset into 10 subsets, each containing approximately 10% of the data. In each iteration, select one subset as the test set and the remaining 9 subsets as the training set. For support vector machine models and logistic regression models, train on the training set and evaluate performance on the test set. For example, for support vector machine models, a grid search can be performed within a pre-set range of hyperparameters, trying all possible combinations of parameters and recording the performance indicators for each validation. For logistic regression models, similarly search within a pre-set range of regularization strength (e.g. from 0.1 to 10) and record the performance indicators. After completing 10 iterations, calculate the average value of each performance indicator as the final evaluation result of the model. In this way, the model can make full use of all data during training, and through multiple validations, avoid performance fluctuations due to different data divisions, thereby improving the stability and reliability of the model.
[0122] Table 1
[0123]
[0124] As shown in Table 1, the performance indicators of the model are summarized in a data frame format for intuitive comparison and analysis of model performance. SHAP analysis is performed to understand the model decision-making process and the contribution of each feature to model prediction. The top 20 features that contribute most to the model are calculated and obtained, and a SHAP summary plot is drawn to clearly present the importance of different features and their influence direction on the model output.
[0125] The above-mentioned various embodiments of the present application have the following beneficial effects:
[0126] 1. By comprehensively extracting the multi-dimensional features of the time domain, frequency domain, isomagnetic map, pseudo-current density map and heart rate variability of the magnetocardiogram signal, the problem of insufficient recognition accuracy caused by the dependence of traditional insomnia diagnosis methods on single features is solved, and the comprehensiveness and reliability of feature representation are significantly improved, providing more abundant biomarker information for accurate recognition of insomnia state.
[0127] 2. LASSO regression is used for feature selection, and SMOTE algorithm is used to process data imbalance problem, effectively eliminating redundant features and enhancing the weight of minority class samples, overcoming the overfitting risk brought by high-dimensional features and the influence of sample distribution on model performance, making the model have better generalization ability and robustness.
[0128] 3. An efficient ensemble learning framework is constructed by using support vector machine and logistic regression as base model and combining with logistic regression meta-model for probability fusion, which not only retains the complementary advantages of different base models, but also optimizes the final decision through probability weighting, thereby improving the accuracy of insomnia recognition while enhancing the stability and interpretability of the model.
[0129] Further, the storage medium of the embodiments of the present application stores program instructions capable of implementing all the above methods, wherein the program instructions can be stored in the above storage medium in the form of a software product, including a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods described in various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, etc. Various media that can store program codes, or computer, server, mobile phone, tablet terminal device.
[0130] The above description is only some of the preferred embodiments of the present application and the explanation of the technical principles applied. Those skilled in the art should understand that the scope of the application involved in the embodiments of the present application is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above inventive concept. For example, the above features are replaced with technical features with similar functions disclosed in the embodiments of the present application (but not limited to) to form technical solutions.
Claims
1. A method for identifying insomnia health status based on magnetocardiographic data and ensemble learning, characterized in that, Includes the following steps: S1. Feature Extraction: Extract time-domain features, frequency-domain features, isomagnetic features, pseudo-current density map features, and heart rate variability features from magnetocardiogram data; S2. Feature selection: The extracted features are screened using the LASSO regression algorithm, retaining an important subset of features; S3. Data partitioning and balancing: The filtered feature dataset is divided into a training set and a test set, and the SMOTE algorithm is used to oversample the training set. S4. Model Building and Prediction: S4.1 uses support vector machine and logistic regression models as base models, trains the training set respectively, and outputs the predicted probabilities. S4.2 combines the predicted probabilities of the base model into a new feature matrix, which is then input into the logistic regression meta-model for final prediction.
2. The method according to claim 1, characterized in that, Step S1 includes: S1.1 Extracting time-domain features: Based on the P wave, QRS wave, T wave and full-segment signal of the magnetocardiogram, calculate the variance, root mean square value, mean absolute value, waveform factor, kurtosis and skewness; S1.2 Extracting frequency domain features: Performing fast Fourier transform on the signals of each channel to calculate the median, maximum value, average power frequency and wavelet singular entropy of the power spectrum; S1.3 Extract features of isomagnetic maps and pseudo current density maps: Calculate the amplitude, angle, and distance parameters of the isomagnetic map, as well as the total current vector and the angle of the maximum current vector of the pseudo current density map; S1.4 Extracting Heart Rate Variability Features: Calculating time-domain, geometric, and frequency-domain features based on RR interval data.
3. The method according to claim 1, characterized in that, Step S2 includes: S2.1 Data Preprocessing: Processing infinity and missing values in the feature data, and normalizing the feature data; S2.2 Train the LASSO regression model, with the objective function as follows: Where n is the number of samples, i is the sample index, and its value ranges from 1 to n; y i Let be the true label of the i-th sample; β0 is the intercept term; p is the number of features, j is the feature index, and its value ranges from 1 to p; x ij β is the j-th feature value of the i-th sample; j Let be the regression coefficient corresponding to the j-th feature; α is the regularization parameter, and α = 0.01; S2.3 Features whose absolute values of the selection coefficients are greater than the mean are selected to form an important feature subset.
4. The method according to claim 1, characterized in that, Step S3 includes: S3.1 The training set and the test set are divided in a 7:3 ratio, and stratified sampling is used to maintain a consistent class ratio. S3.2 The training set is oversampled using the SMOTE algorithm.
5. The method according to claim 1, characterized in that, Step S4.1 includes: S4.1.1 Perform hyperparameter tuning on the support vector machine model. The hyperparameters include: C∈[0.1, 1, 10], and the kernel function is either a linear kernel or a radial basis kernel; where C is the penalty parameter, used to control the degree of penalty for misclassified samples. S4.1.2 Perform hyperparameter tuning on the logistic regression model. The hyperparameters include: C∈[0.1, 1, 10], and the regularization type is L1 regularization or L2 regularization; where C is the reciprocal of the regularization strength, and the smaller the value, the stronger the regularization strength.
6. The method according to claim 5, characterized in that, The support vector machine model outputs the predicted probability P1 using the Platt scaling method, as shown in the formula: Where i is the sample index; P1 i f(x) represents the predicted probability of the i-th sample after Platt scaling using a support vector machine model; A and B are the fitting parameters; i For the support vector machine model, the i-th sample x i The output value.
7. The method according to claim 1, characterized in that, Step S4.2 includes: S4.2.1 Combine the prediction probabilities P1 from the support vector machine model and P2 from the logistic regression model into a new m×2 feature matrix X. new : Where m is the sample size; P1 i P2 represents the predicted probability of the support vector machine model for the i-th sample. i Let be the predicted probability of the logistic regression model for the i-th sample; S4.2.2 A logistic regression meta-model is used to train and predict the new feature matrix, and the final predicted probability P is obtained. final The calculation formula is: Where Y is the predicted category, Y=1 represents the insomnia category; X new For the new feature matrix; X new1 X new2 These correspond to the eigenvalues of columns P1 and P2 in the new feature matrix, respectively; β0 is the intercept term of the logistic regression meta-model; β1 and β2 are the eigenvalues corresponding to X. new1 X new2 The regression coefficients.
8. The method according to claim 7, characterized in that, The final predicted category determination rule is as follows: If P final A value ≥0.5 indicates insomnia; otherwise, it indicates a healthy condition. Where P... final This represents the final predicted probability output by the logistic regression meta-model.
9. The method according to claim 1, characterized in that, In step S4, both the base model and the meta-model are trained using 5-fold cross-validation for hyperparameter tuning.
10. The method according to claim 1, characterized in that, Also includes: S5. Model Evaluation: The model performance is evaluated using 10-fold cross-validation, and the accuracy, precision, sensitivity, specificity, F1 score, and ROC-AUC are calculated.