## 3 The Proposed HSDW-MI Algorithm
### Two Phases of the HSDW-MI Algorithm  
#### 3.2.1 Hybrid Sampling Phase of HSDW-MI Algorithm  
This section describes the workflow of the proposed hybrid sampling method based on adaptive spectral clustering, sample safety factor, and sample storage pool. Firstly, adaptive spectral clustering clusters each class, and by sampling based on the clusters of each class, the original data distribution is better maintained. Next, the sample safety factor is introduced for oversampling or under-sampling samples, allowing for better distinction between majority and minority classes. Finally, a sample storage pool is proposed for storing samples with high safety factors, addressing variable and extremely imbalanced data streams. Initially, a class ratio-based sampling method is proposed to determine the number of samples to be sampled for each class. The class ratio is determined by the number of classes in the current chunk. After sampling, the number of samples of each class in the data chunk needs to be equal to the class ratio, as is shown in Equation (1). \[n_{c_{i}}^{\prime}=\left(\frac{1}{c}-\frac{n_{c_{i}}}{d}\right)d \tag{1}\]  
where \(d\) denotes the total number of samples in the current chunk, \(c\) denotes the number of classes, \(\frac{1}{c}\) is the class ratio, \(\frac{n_{c_{i}}}{d}\) is the proportion of the sample size \(n_{c_{i}}\) of class \(c_{i}\) in the total sample size \(d\), and the calculation result \(n_{c_{i}}^{\prime}\) is the number of samples that need to be sampled for class \(c_{i}\). Then, adaptive spectral clustering is proposed to cluster and divide the clusters for each class in the data chunk. Sampling based on clusters after clustering can better maintain the original data distribution. Compared to other clustering methods, spectral clustering has better clustering performance on complex data distributions, is less susceptible to local optima, and can handle high-dimensional data. Due to the varying samples distributions in each data chunk, the number of clusters for spectral clustering must be adjusted to achieve the best clustering results as new data chunks arrive. This allows clustering to adaptively conform to the current data distribution. In this paper, the Calinski-Harabasz index is employed to determine the optimal number of clusters for each class [29], and the score of the Calinski-Harabasz index is calculated within the range of [2; 10]. The Calinski-Harabasz index evaluates the inter-class variance and the intra-class variance, where higher values indicate greater effectiveness, as illustrated in Equation (2). \[s=\frac{SS_{B}}{p-1}\bigg{/}\frac{SS_{W}}{n_{c_{i}}-p}=\frac{tr(B_{p})}{tr(W_{p })}\times\frac{n_{c_{i}}-p}{p-1} \tag{2}\]  
where \(p\) denotes the number of clusters, \(SS_{B}\) is the inter-class variance, \(SS_{W}\) is the intra-class variance, \(B_{p}\) is the inter-class distance, \(W_{p}\) is the intra-class distance, and \(s\) is the Calinski-Harabasz index score. Afterwards, according to the obtained number of clusters of class \(c_{i}\), the number of samples in the clusters and the number of samples to be sampled \(n_{c_{i}}^{\prime}\), the number of samples to be sampled in each cluster of class \(c_{i}\) is calculated, as shown in Equation (3). \[n_{p}^{\prime}=\left(n_{p}/n_{c_{i}}\right)\times n_{c_{i}}^{\prime} \tag{3}\]  
where \(n_{p}\) is the number of samples of cluster \(p\), \(n_{p}/n_{c_{i}}\) is the proportion of cluster \(p\) in the total number of samples of class \(c_{i}\), and \(n_{p}^{\prime}\) is the number of samples that need to be sampled for cluster \(p\). Next, a sampling method based on sample safety factor is proposed, in which the safety factor of each sample is calculated for each cluster obtained from each class. The safety factor of samples is determined based on the class labels of their neighboring instances. In this paper, the \(k\)-NN is used to find the \(k\) samples near to sample \(x_{i}\), and the safety level of \(x_{i}\) is determined by the similarity between these \(k\) samples and sample \(x_{i}\).