{'fraction_non_alphanumeric': 0.02686631130635095, 'fraction_numerical': 0.01609835802105376, 'mean_word_length': 4.767650239456203, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Deep Metric Learning Model for Imbalanced Fault Diagnosis

Intelligent diagnosis method based on data-driven and deep learning is an attractive and meaningful field in recent years. However, in practical application scenarios, the imbalance of time-series fault is an urgent problem to be solved. This paper proposes a novel deep metric learning model, where imbalanced fault data and a quadruplet data pair design manner are considered. Based on such data pair, a quadruplet loss function which takes into account the inter-class distance and the intra-class data distribution are proposed. This quadruplet loss pays special attention to imbalanced sample pair. The reasonable combination of quadruplet loss and softmax loss function can reduce the impact of imbalance. Experiment results on two open-source datasets show that the proposed method can effectively and robustly improve the performance of imbalanced fault diagnosis.


Introduction
With the rapid development of modern industry and intelligent manufacturing, fault diagnosis of key equipment and production processes in smart factory is becoming more important for production safety and economic benefits [1,2]. To ensure that faults can be diagnosed accurately and timely, it is necessary to mine useful information from large number of sensor signals. In recent years, data-driven methods have been extensively studied since they can perform effective process monitoring and fault diagnosis in automated equipment or systems where it is difficult to build a specific model [3,4].
Deep learning is widely used in the fields of computer vision, natural language processing, biological information [5,6,7,8,9] and so on because it can process a large amount of data and obtain effective features from these data. As sensing technology and data storage technology promoting, massive data are recorded in production process. Therefore, in the field of fault diagnosis, many classical and effective models in deep learning were verified to have good performance such as Deep Belief Network (DBN) [10,11,12], Autoencoders (AE) [13,14,15], Convolutional Neural Network (CNN) [16,17,18]. Considering the fault signals are not independent of each other, recurrent neural network (RNN)-based methods were proposed and achieve performance improvement on dynamic time-series fault signals. Yuan et al. [19] used standard LSTM methods to predict the remaining life of aero engine in complex and strong noise interference environments. Cabrera et al. [20] iteratively trained a group of LSTM models from a time series representation and the hyperparameter search is guided by a Bayesian approach. Lu et al. [21] used LSTM to make use of previous context information and made the distribution estimator more robust to warp along the time axis.
Although deep learning methods have achieved certain accomplishment in fault diagnosis task, there still exits some challenges. As is known to all, sufficient high-quality data is the primary requirement to ensure the performance of deep learning-based fault diagnosis methods. When it comes to class imbalance, models will typically over-classify the majority group due to its higher prior probability. As a result, the instances belonging to the minority group are misclassified more often than those belonging to the majority group [22]. However, during practical production process, arXiv:2107.03786v2 [cs.LG] 14 Jul 2021 it is difficult to collect sufficient and balanced data because it is time-consuming and costly to obtain sufficient fault samples and the occurrence of each fault is also different. Current methods dealing with imbalanced data are often based on oversampling [23], but these methods do not provide additional information for the model. With the development of generative model, GAN is widely used in fault diagnosis and able to deal with imbalanced scenarios [24,25,26]. However, the most methods based on data generation are two-stage.
To better model the edge and distribution of imbalanced class, deep metric learning (DML) has been applied in imbalanced data classification [27,28]. Classical DML model such as siamese network [29] project data into a new metric space where the distance between different classes increases, and the dispersion within a class decreases. The triplet network inspired by siamese network contains three objects, called anchor, positive sample and negative sample [30]. Triplet network simultaneously considers intra-class and inter-class relationships to provide higher discrimination capabilities. Recently, DML-based model for fault diagnosis has been researched. Li et al. [31] proposed a representation clustering algorithm to minimize the distance of intra-class variations and maximize the distance of inter-class variations simultaneously. Wang et al. [32] introduced a novel loss function called normalized softmax loss with adaptive angle margin (NSL-AAM) based on DML which can supervise neural networks learning imbalanced data without altering the original data distribution.
DML consists of three main parts which are informative input samples, the structure of network and metric loss [33]. Although imbalanced fault diagnosis model based on DML has been researched, there is no optimization strategy considering input sample pair. DML, as pair-based model, by adding a 'minor sample' selected from imbalanced class in data pair besides positive sample and negative sample, will pay attention to the distance between anchor and positive, negative sample, imbalanced class data simultaneously. Based on such data pair, a quadruplet loss function referring to contrastive loss can be designed. By adjusting weight, the model pays more attention to the compactness of balanced class and distance between the imbalanced class and other classes. Making use of the powerful feature learning ability of deep learning, the distance between imbalanced and balanced class is as large as possible in the new mapping space, while maintaining the density of balanced class.
Based on the inspiration of above research, this paper proposed a quadruplet deep metric learning time-series fault diagnosis model (LSTM-QDM) under the condition of class imbalance. This model utilizes LSTM to extract feature from time series data and embeds the extracted feature into a low-dimensional space where the distance of intra-class decreases and the distance of inter-class increases. Simultaneously, this model makes the distance between imbalanced class and other classes even bigger and balanced class more compact to reduce the effect of imbalance.
The main contributions of this paper are summarized as follows.
• Based on traditional DML model, propose a new data pair design manner. In addition to positive and negative samples, select sample from imbalanced classes to increase the attention to imbalanced class. And the data pair initialization process considers single-class and multi-class imbalance scenarios simultaneously. • A quadruplet loss based on new data pair is developed to optimize deep model. The quadruplet loss considers distance relationship of anchor with postive, negative and minor samples. By setting discriminative weight for data pair, pays special attention on imbalanced class. • Design a new loss function combined softmax loss and quadruplet loss for imbalanced classification and conduct diverse imbalanced fault diagnosis experiments on Tennessee East-man process dataset and CWRU bearing fault dataset to prove the robustness and effectiveness of proposed method.
Where x t ∈ R Ni , h t ∈ R N h , o t ∈ R No are respectively the input vector, the hidden state vector and output vector.
are respectively the weight matrix of input x t and hidden state h t , weight matrix of previous time hidden state h t−1 and current time hidden state h t and weight matrix of hidden state h t and output o t . Function σ(•) and f (•) are respectively non-linear activation function of hidden layer and output layer. The hidden state at time t, h t is affected by hidden state h t−1 and input data x t . In the training process, three weight matrices, W hx , W hh and W oh , are updated with back propagation iteratively. During the optimization, RNN often has the risk of gradient vanishing and gradient exploding so it is unable to capture long-term sequence information [34].
In order to improve these problem, long short-term memory (LSTM) was proposed on the basis of RNN [35]. Compared with RNN, the hidden state in LSTM is controlled by complex control gate signal and memory signal to optionally forget or update time series information. The forward propagation of LSTM at time t are as follows.
Where x t and h t are same as those in RNN, and the cell state,c t is added in the model which is applied to store long-time information. f t , r t and o t are respectively forget gate, update gate and output gate. These gate signals are calculated with different weight matrix, current input vector and last time hidden state vector and embedded into interval of (0,1) to reflect the gates' state. c t represents temporary memory information at time t and c t is obtained by forgetting c t−1 and updating c t to some degree. represents Hadamard product operator. Finally, the hidden state at time t is calculated by output gate and c t . The activation function used in LSTM, σ and tanh, are sigmoid function and hyperbolic tangent function respectively.

Deep metric learning
Deep metric learning (DML) is a method of metric learning [33], and its goal is to learn a map from original feature space to a low-dimensional dense embedding space where the samples from same class are closer, and the distance between different classes is farther. The distance is usually calculated by distance function such as Euclidean distance or Cosine distance. In embedding space, the ideal data distribution is shown in Figure 1. Loss function plays an important role in DML and many of them is designed based on data pairs. Siamese network is a DML model widely used in different fileds [36,37,38]. Siamese network is a symmetrical network consisting of two identical neural networks in parallel, whose structure and parameters are shared. It maps two input data into embedding space to obtain feature vector, and then uses the distance function to measure the similarity. As shown in Figure 2 left, x 1 and x 2 are fed into the symmetrical network and the loss function called contrastive loss is shown in Eq.3. Y represents whether the two input data are from same class and equals 1 if from same class and 0 if from different classes.
Triplet network is also applied widely [39,40,41]. Similar to the siamese network, it consists of three identical neural networks in parallel, sharing all parameters as shown in the Figure 2 right, where x 1 from class C is called anchor and x 2 , x 3 come from class C and other classes respectively called positive sample and negative sample. The loss function of triplet network is shown in Eq.4. Generally, triplet network has a better performance than siamese network because it considers the relationship between anchor, positive sample and negative sample simultaneously.

Time series fault diagnosis based on DML
In actual production process, imbalanced fault diagnosis data exits commonly which make it difficult to build an accurate fault classifier based on traditional deep learning model. This paper proposed LSTM-quadruplet deep metric model (LSTM-QDM) based on the powerful time series feature extraction capability of LSTM and the ability of DML to adjust the distance between classes and within a class. The whole architecture of LSTM-QDM is shown in Figure  3. The proposed model consists of three main parts: data pair design and generate, feature extract and embed, loss function design.

Quadruplet time series data pair design
To provide more attention to imbalanced class samples, referring to the data pair design of triplet network, in addition to anchor sample, positive sample and negative sample, minor sample is proposed based on imbalanced classes. As shown in Figure 3 blue part, positive sample is from the same class as anchor and negative is from the different and balanced classes, while minor sample is from imbalanced classes. QDM model considers scenarios of one-fault imbalance and multi-fault imbalance. When there exits one-imbalanced class, if anchor's class is imbalanced, then minor sample is randomly selected from negative classes while in multi-imbalanced classes condition, if anchor's class is imbalanced, then minor sample is selected from a different class in imbalanced classes subset. The data pair consists of four sample including anchor is shown in Eq.5.
Where C(x n ) is the class of x n , C imbalance is the imbalanced classes subset. The time series data are obtained by applying sliding window method. Set original data matrixX = [x 1 ;x 2 ;x 3 ; . . . ; x n ] ∈ R n×m where n is the sample number and m is the feature number. Suppose the start sampling time is t and sampling duration is L, then time series data input data can be written as: Sliding window is used between time series samples, and suppose the step length of the sliding window is s: The label of time series sample is set corresponding to the last sample point in the time series:

Feature extract and embedding
LSTM-QDM utilizes LSTM to make time series feature extraction and a one-layer fully-connected layer to embed the feature and obtain a low-dimensional embedding space. According to the description of LSTM in Section 2.1, suppose LSTM is N L and the extracted feature pair is as follow: Where N L (x) ∈ R N h , means that feature extract layer obtains the last hidden state vector in LSTM. The extracted feature dimension is usually high where Euclidean distance may degenerate and makes it difficult for model to converge at the optimal. So QDM applies a one-layer fully-connected layer to map a high-dimensional space to a low-dimensional space. Suppose the weight of fully-connected layer is W f e and the mapping vector is p.
The weights of feature extract part (LSTM) and feature embedding part (fully-connected layer) are weight-sharing.

Quadruplet loss design
The design of quadruplet loss refers to contrastive loss. The main intention of quadruplet loss is shown in Figure 4. The optimization goal of the proposed loss is to reduce the distance within a class and increase the distance between different classes. Moreover, for imbalanced class, it is ideal that the distance between anchor and imbalanced sample is larger which can improve the performance of imbalanced classification.
Quadruplet loss is composed of three distance from data pair proposed in Section 3.1. For sample pair from same class, the distance between samples should be as small as possible which means D n,pos should be small. Meanwhile, since sample number of balanced class is sufficient, model ought to pay more attention to the data distribution within the balanced class and mine high-quality features from balanced class sample pairs. In such feature space, compact data distribution can improve the negative effect of imbalance. Therefore, a parameter γ is defined which equals 1 if anchor x n belongs to balanced classes and the positive sample part loss is expressed as Where λ pos > 1 and is used to emphasize the compactness within balanced class.
For samples from different classes, the distance between samples is hoped to be as large as possible, which means D n,neg and D n,minor is large. Moreover, as shown in Figure 4, D n,minor is larger than D n,neg since farther distance between classes means higher degree of discrimination and reduce the impact of imbalance. Therefore, the loss of negative sample part and minor sample part are as follows: Where λ minor > 1 and M 2 > M . M is the expected margin between anchor and negative sample, and M 2 is the one between anchor and minor sample. These two formula both pull negative sample and minor sample away from anchor, however, the different margin determines the distance from anchor. For minor sample part loss, the margin is larger so that the distance between anchor and imbalanced class sample is larger. And by adding a hyperparameter λ minor , the model pays more attention to the minor data pair to reduce the impact of imbalance.
According to aforementioned three part loss functions and considering a batch input data pairs, the overall quadruplet loss function is:

Softmax loss
Softmax loss is the most widely used classification loss function in deep learning [42,43] because of its simplicity and excellent performance in many classification tasks and the formula is: Where y i is the true label of i th sample, a k is the k th logits corresponding to the k th class, C is the class number and e a i C k=1 e a k is the normalized predict probability. In QDM model, the embedding vector of anchor will be mapped into a C-dimension vector by a fully-connected layer. Suppose the weight of layer is W f c , and the mapped vector is Because of the existence of y i in the formula, the sample number of each class will affect the loss and the model tends to pay attention to the balanced classes and despise the imbalanced classes. Therefore, softmax loss is not suitable for dealing with imbalanced classification problem.

Combination of quadruplet loss and softmax loss
From the above introduction of the two losses, softmax loss optimizes the model classification performance, while quadruplet loss optimizes the data distribution in embedding space. Even though the goals of the two losses are different, the optimization of quadruplet loss is positive to softmax loss.
As shown in Figure 5, the left shows the classification result using softmax loss in the imbalanced classification task and the imbalanced class samples are represented by orange dots. The darker ones are training set and the lighter ones are test set. Because the training set is imbalanced, the model does not fit the decision boundary well and performs unsatisfactorily on the test set. But for the right figure, better performance on both the training set and the test set shows up. Compared with the left, distance between classes in the right figure is larger, and the data distribution of balanced class is more compact. Look back to those two loss functions, with label information y i in softmax, the model explicitly considers the number of different class. However, y i does not directly appear in quadruplet loss. Moreover, samples belonging to an imbalanced class will structure into data pairs with multiple other classes data which reduces the imbalance influence.
According to above analysis, the loss function of LSTM-QDM combines quadruplet loss and softmax loss with a hyperparameter. The parameters of feature extract and feature embedding part are jointly optimized by these two losses, while the parameters of classifier layer is optimized by softmax loss. The loss function of QDM is as follows.

Offline Training & Online Diagnosis
This paper proposes an intelligent diagnosis method based on LSTM-QDM to solve the problem of imbalance fault diagnosis. The method is divided into two stages: offline training and online diagnosis. The specific flow chart is shown in Figure 6.

Experiment
To verify the effectiveness of the proposed model, an industrial process fault diagnosis dataset and a bearing fault diagnosis dataset are used to conduct diverse experiments. Detailed experimental analysis will be described in this section.
Two evaluation index, recall rate and F1, are used to evaluate the proposed fault diagnosis model. The fault diagnosis task belongs to multi classification problem and when calculating the evaluation index of class i, class i is regarded as positive class and other classes as negative class. The specific calculation of the two evaluation indexes are Eq.18 and Eq.19 respectively. Recall rate calculates the proportion of the number of correctly predicted positive samples in the total positive sample and F 1 is the comprehensive index of accuracy rate and recall rate which reflecting comprehensive recognition ability and stability of the response model. The higher the two indexes, the better the diagnostic ability of the model.
Recall rate = T P T P + F N

Case 1: TE process fault dataset
The first case study is based on Tennessee-Eastman (TE) process data. TE process is a process control case based on actual industrial processes. It first appeared at the American Chemical Society Annual Conference in Chicago in 1990. The TE process was created by Eastman Chemical Company [44] and it has been widely used to research fault diagnosis methods [45,46,47].

Data description
The TE process consists of five primary units: a reactor, a condenser, a compressor, a separator and a stripper. The whole TE process consists of 22 continuous process measurements, 19 composition measurements and 12 operation variables, and it can generate normal condition and 20 kinds of faults condition. The description of faults is shown in Table 1 and the flow chart of TE process is shown in Figure 7. The data used in this experiment can be downloaded from https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/6C3JR1

Imbalanced experiments analysis
To demonstrate the performance of the proposed model for imbalanced classification, several methods are used to compare, including baseline method(LSTM), Siamese network, GAN and Oversample. Note that the neural network architecture and training hyperparameters of those methods are the same as the proposed model which are shown in Table 2. Each method is repeat 10 times to measure average evaluation index. Moveover, experiments are conducted on the TE data set under the conditions of single-fault imbalance, multiple-fault imbalance, and different imbalance ratios to prove the robustness of the model.
Considering single-fault imbalance scenario, fault 8 is selected as imbalanced fault. The number of balanced fault is 4800 and the number of fault 8 is 480 in the training set, and the imbalance ratio is 10:1 (scenario 1). The experiment result is shown in Table 3.
It can be seen from Table1 that the recall rate of fault 8 of the baseline method is 56.07%, and the F1 score is 71.77%. The recall rates of methods based on GAN and Oversample are 65.01%, 64.81%, with about 9% increasing, and F1 scores are 78.66%, 78.38% with about 7% increasing, respectively. The recall rate and F1 score of LSTM-Siamese are 61.50% and 75.95% respectively, which are only slightly improved compared to the baseline method. The recall rate and F1 score of LSTM-QDM are 66.74% and 79.85%, respectively, which is the best performance among all methods. Similarly, the average indicators of proposed method also has best performance and an improvement of about 2% compared with the baseline method.
To prove the effect of the model on other fault, fault 6 is selected as the imbalanced fault. Similarly, the number of fault 6 is 480 (scenario 2). The result is shown in Table 4. It can be seen that the the recall rate of fault 6 is 80.26%, and F1 is 87.86%. Compared with scenario 1, the two evaluation indexes are both higher, indicating that fault 6 is less affected by imbalance. The recall rate of GAN is as high as 93.17%, with about nearly 13% increasing compared to the baseline. And the recall rate of LSTM-QDM is 83.60%, with about nearly 3% increasing. Even though the performanc of proposed method is not as good as GAN, it is also effective. Similarly, in terms of the average evaluations, the proposed method is lower than GAN, but has a improvement relative to the baseline method.
Aforementioned two scenarios show that the selected generator and discriminator parameters of GAN are better for fault 6 which means it is greatly affected by different fault scenarios. Although GAN method has a highlight, the shortcomings of GAN is the need of optimizing parameters for different faults. However, The proposed LSTM-QDM has stable improvement compared with baseline method in both scenarios.
To verify the performance of the proposed model under different imbalance ratios, two experiments on fault 8 with imbalance ratio of 5:1 and 20:1(scenario 3 and 4) are conducted where the number of fault 8 is 960 and 240 respectively. The experimental results are shown in Table 5 and Table 6.
Tabel 5 shows that when the imbalance ratio is 5:1, the recall rate and F1 of baseline method are 63.63% and 77.66%, with a increases about 6% compared with scenario 1 respectively which means that reducing the imbalance ratio can effectively improve the classification performance. Similar to scenario 1, compared with the baseline method, LSTM-QDM improves recall and F1 by 10% and 7% respectively, and achieves the best results in all indicators among all methods.
In scenario 4, the 20:1 imbalance ratio can be regarded as severe imbalance. The recall rate and F1 of imbalance fault 8 of baseline method are only 28.54% and 44.15% , which are far lower than scenario 1, indicating such severe imbalance will greatly damage the classification ability of the model. However, although the recall rate and F1 of the proposed LSTM-QDM model are only 52.24% and 68.46%, there is still a big improvement compared with the baseline method and similarly, the proposed method has the best performance.
The above four scenarios show that the recall rate and F1 of different imbalanced faults under different imbalance ratios will be greatly affected, as well as the average index of all faults. The method based on GAN and Oversample effectively improves the performance by re-balancing the number of different classes. The method based on LSTM-Siamese has a certain improvement compared to the baseline, because it can improve the sample distribution and class distance in the mapping space to a certain extent. However, the model does not pay special attention to the imbalance class, so the overall effect is worse than the re-balancing method. The proposed LSTM-QDM model deliberately adds a data pair of anchor and minor sample. For all input quadruplet data pairs, the distance between imbalanced sample and other samples is modeled, and utilizing hyperparameters, M 1 ,M 2 , λ pos , λ minor to better fit the intra-class distribution and inter-class distance so the performance is greatly improved.
When there are multiple faults in imbalanced scenario, faults 6, 8, and 16 are considered as imbalanced classes. Similarly, considering two imbalance ratios, 10:1 and 5:1. The number of balanced faults is 4800 and the number of imbalanced faults are 480, 960 respectively. In addition, in these two experiments, the baseline method performance under balanced conditions are also shown. The experiment results are shown in Table 7 and Table 8.
The rightmost column of the two tables shows the result of LSTM method under balanced conditions. It can be seen that all index are close to 100%, indicating that the settings of the general hyperparameters in Table 2 are reasonable. From Table 7, it can be seen that the recall rates of fault 6, fault 8 and fault 16 of baseline method are 73.04%, 46.59%, and 87.12% respectively, and the F1 scores are 83.01%, 54.91%, and 88.67% respectively. This shows that fault 8 is the most severely affected class by imbalance, fault 6 is the second, and fault 16 is the least. Compared with the baseline method, the recall rate of these three imbalanced fault of LSTM-QDM are with about nearly 6%, 16%, 10% increase and the F1 are with about 5%, 19% and 4% increase respectively and have best performance in all evaluation indicators, including fault average index, except for fault 6 where the result of GAN far exceeds other methods.The performance of GAN method in this scenario and scenario 2 is consistent, which shows that the current hyperparameters of GAN are suitable for fault 6.However, in terms of overall performance, LSTM-QDM is stable. Table 8 shows the results of scenario 6 where the imbalance ratio reaches 5:1. It can be seen that almost all indexes are improved compared to Table 7, except for the GAN method on fault 6, which indicating that GAN is unstable and more complex data may make optimization performance of GAN not ideal under current hyperparameters. The recall rate of LSTM-QDM on fault 6 and fault 16 reach 97.36% and 99.38%, and the F1 score reach 98.14% and 93.63%, which are close to the performance under the balanced scenario. Compared with the baseline method, the performance of fault 8 is also improved by nearly 10%. In terms of overall average performance, LSTM-QDM also has an excellent performance.
In the above experiments of TE dataset, the diverse scenarios include different fault classes, imbalanced ratios, and single-fault or multi-fault imbalance are conducted for comparison. The experimental results show that the proposed LSTM-QDM method has good performance under different experimental conditions, which proves the effectiveness and robustness of the model on this dataset.

Case 2: CWRU bearing fault dataset
The second case study is based on CWRU bearing data. CWRU bearing dataset was collected from an experiment platform provided by Case Western Reserve University and has been widely used in the field of mechanical fault detection and fault diagnosis. [48,49,50]

Data description
On the CWRU bearing experiment platform, experiments were conducted using an electric motor, and vibration data were measured from the motor bearings. The main components of this experimental facility consist of a 2 hp motor, a torque transduce and a dynamometer. The test bearing support the motor shaft. The rolling bearing is tested under different loads (0, 1, and 2 HP). The location of the fault mainly includes ball defect (BD), outer race defect (OR) and inner race defect (IR) and the defect diameter includes 0.007, 0.014, 0.021 inches. The vibration signals are collected by the accelerometer sensor with 12 kHz.
The collected accelerometer signals of the drive end under 0 HP loads are used for method validation in this case which is a one-dimensional time-series data. There are one class of normal data and nine classes of fault data. Each type of fault uses a sliding window method to construct time series data. The window size used here is 400, and the sliding step size is 32. The rolling bearings fault information are shown in Table 9.  Table 10. Each method is also repeated ten times and the average performance is taken as the result. The number of samples for each class is 1800 in the training set and 200 in the test set and the number of imbalance classes in the training set is adjusted according to different imbalance ratios. Fault 3, 5, and 9 are used as imbalanced classes for experiments which come from different fault locations.
Considering 10:1 imbalance ratio and the imbalance class is fault 3 as scenario 1 which means the number of fault 3 in training set is 180. The result is shown in Table 11. It can be seen that the recall rate and F1 of fault 3 of the baseline method are only 11.23% and 18.22% respectively, which are greatly affected by the imbalance. The two indexs of LSTM-QDM are 48.05% and 63.70% with about 37% and 45% increase respectively. Among all the methods, GAN has the best effect, and the two indexes of which are about 4% larger than LSTM-QDM. Under the current parameter settings, the re-balancing effect of GAN on imbalance is better than the proposed method. However, LSTM-QDM still improves the impact of imbalance to a certain extent.
Considering the performance of proposed model on other faults, the imbalanced class is adjusted to fault 5 and fault 9 for experiments in scenario 2 and scenario 3. The experimental results are shown in Table 12 and ??. The recall rates of baseline on imbalanced faults are 90.68%, 90.22%, and F1 are 93.76%, 93.57% respectively, indicating that the impact of imbalance is relatively slight. And the recall rates of LSTM-QDM on unbalanced faults are 95.64%, 96.00%, and F1 In order to verify the effectiveness of LSTM-QDM under different imbalance ratios, imbalance ratio of different faults is adjusted. Because fault 3 is seriously affected by imbalance, while fault 5 and fault 9 are slightly affected by imbalance, the imbalance ratio of fault 3 is adjusted to 5:1, and the imbalance ratio of fault 5 and fault 9 is adjusted to 20:1. The experimental results are shown in Table 14,15,16.
By reducing the imbalance ratio of fault 3, it can be seen that the performance of the baseline method has been significantly improved. In this scenario, the recall rate and F1 of LSTM-QDM have increased by about 14% and 18% compared with baseline respectively. It can be seen from Table 15 and Table 16 that the increase of imbalance ratio will destroy the classification performance, however, even if the imbalance ratio reaches 20:1, the recall rate of baseline method of fault 5 and fault 9 are about 86% indicating the great distinction between these two faults and other faults. Similarly, the proposed method has a obvious improvement in all indicators.
In order to verify the performance of LSTM-QDM under multiple imbalanced faults situation, faults 3, 6, 9 are selected as imbalanced classes, with 10:1 imbalance ratio. The experimental results are shown in Table 17. Similarly, the rightmost column of the table shows the performance under balanced conditions, and the results show that the general parameter settings are reasonable. From the above seven scenarios, even if the overall performance of the re-balancing method is better than that of LSTM-QDM, LSTM-QDM still shows a relatively good ability to improve classification performance under imbalance. Combined with 6 different experimental settings in Case 1, these experimental results show that LSTM-QDM effectively improves the classification effect of imbalanced classes and overall performance in imbalanced multi-classification tasks.

Analysis of the hyperparameters in LSTM-QDM
In this section, some analysis and discussion on some hyperparameters in the LSTM-QDM model are conducted including the parameters in quadruplet loss and the weight of the quadruplet loss.

Analysis of the hyperparameters in quadruplet loss
Looking back at the quadruplet loss, the hyperparameters include a margin M 2 larger than M in traditional siamese network which is used to push imbalance sample further, and the weight parameter λ pos , λ minor that provides different weights for different sample pairs. Different parameters in scenario 1 experiment in the TE data set are set, which are        class in the embedding space is farther from other classes, and the recall rate of the imbalanced class is improved. When considering M 2 and weight simultaneously which is (D), the model has the best results, indicating that more attention paid to minor sample pairs and balanced positive samples makes the distribution of balanced data more compact and the distance between classes larger. It should be noted that these parameters need to be adjusted according to different data conditions like the different settings in Case 1 and Case 2.

Analysis of the hyperparameter β
The loss function of LSTM-QDM model is the weighted summation of softmax and quadruplet loss, where the parameter β controls the weight of quadruplet loss. Similarly, in this section, through the expansion of scenario 1 experiment in TE data set, parameter β is adjusted and the result is shown in Figure 9.
The experimental results show that the β greatly affects the performance of LSTM-QDM. When β is large, although the model has a high recall rate of imbalanced faults, the overall average recall rate is extremely low, indicating that the proportion of quadrupelet loss is too large and the attention on imbalanced class is too high. As a result, the model can not fit other classes well and have unsatisfactory overall performance. However, when β is small, although the recall rate of imbalanced faults is slightly reduced, the average recall rate reaches a higher level which is an ideal phenomenon and indicating that a good balance is achieved between the two losses. Therefore, in the previous experiments, the hyperparameter β was adjusted between 0.001 and 0.0001.

Conclusion
In this paper, a time series fault diagnosis model is proposed based on deep metric learning for class imbalance in fault diagnosis task. The proposed model designs a new data pair referring to traditional deep metric method especially considering the imbalanced fault class and proposes a quadruplet loss function. Combined with softmax loss function, the distance between classes and the data distribution within a class are adjusted to improve the imbalance classification performance.
The method proposed in this paper considers multiple-class imbalance and one-class imbalance scenarios simultaneously and designs different data pair construction methods. A large number of experiments on two public datasets (TE, CWRU) are conducted to prove the effectiveness and robustness of the model, and discusses some hyperparameters of the model in depth. This method provides a new perspective to solve the problem of unbalanced classification and further research on deep metric learning in imbalanced classification tasks will be interesting.