# Hyperspectral Image Classification with Imbalanced Data Based on Semi-Supervised Learning
## 2 Proposed Method  
We propose an oversampling approach, NearPseudo, in which the minority class is oversampled from unlabeled samples instead of creating samples from the training data. This approach is designed to use a large amount of unlabeled data, which contains rich, useful information. It may be essential to overcome the limitation of a few new features being added to the training process by only combining existing training samples. Our algorithm constantly iterates and oversamples until it obtains a balanced dataset, in which the number of selected training samples in each class is equal. During each loop, new samples from unlabeled data and their manufactured pseudo-labels are added to a single minority class. The pseudocode for NearPseudo is shown in Algorithm 1. Suppose we have an imbalanced training dataset \(\mathbf{T}_{t}\) and an unlabeled dataset \(\mathbf{T}_{u}\). \(\mathbf{T}_{r}=\{(\mathbf{x}^{(1)},y^{(1)}),(\mathbf{x}^{(2)},y^{(2)}),\)\(\ldots,(\mathbf{x}^{(n)},y^{(n)})\}\), where \(y^{(i)}\in\{1,2,3,\ldots,m\}\) is the label corresponding to \(\mathbf{T}_{r}\), \(m\) is the number of classes, \(n\) is the number of samples, and \(v\) is the number of features/bands. \(\mathbf{T}_{u}=\{\mathbf{x}^{(n+1)},\mathbf{x}^{(n+2)},\ldots,\mathbf{x}^{(n+2)}\}\), where \(z\) is the number of unlabeled samples. During each loop, a subset \(\mathbf{S}_{u}\in\mathbf{R}^{q\times v}\) is randomly extracted from the unlabeled samples \(\mathbf{T}_{u}\), where \(q\) is the number of samples in the random subset \(\mathbf{S}_{u}\). Simultaneously, a random sample \(\mathbf{x}^{(i)}\) is taken from \(\mathbf{T}_{r}\) with the label \(y^{(i)}\). Then, the algorithm computes the distance between \(\mathbf{x}^{(i)}\) and each sample in \(\mathbf{S}_{u}\) as follows:  
\[D^{(e)}=\sum_{j=1}^{v}\left|\mathbf{x}^{(i)}_{j}-\mathbf{x}^{(e)}_{j}\right|, \tag{1}\]  
where \(D^{(e)}\) is the distance between \(\mathbf{x}^{(i)}\) and \(\mathbf{x}^{(e)}\) in \(\mathbf{S}_{u}\). The algorithm then identified a group of \(k\) objects in \(\mathbf{S}_{u}\) that were closet to \(\mathbf{x}^{(i)}\). These objects also need to simultaneously undergo a consistency check. In this process, the training dataset \(\mathbf{T}_{r}\), which labels \(\mathbf{y}\), was utilized to model multi-classifier \(G(\mathbf{x};\mathbf{\theta})\), as shown in (2). Then, the consistency check model \(F(y^{(i)},\mathbf{x}^{(e)})\) was constructed by using (3). When \(F(y^{(i)},\mathbf{x}^{(e)})=0\), \(\mathbf{x}^{(e)}\) passes the conformance check, and vice versa,  
\[\mathbf{y}=G(\mathbf{x};\mathbf{\theta}) \tag{2}\]  
\[F(y^{(i)},\mathbf{x}^{(e)})=y^{(i)}-G(\mathbf{x}^{(e)};\mathbf{\theta}). \tag{3}\]  
When \(\mathbf{x}^{(e)}\) belongs to \(k\) objects and also passes the consistency check, \(\mathbf{x}^{(e)}\) is added to the training dataset with the pseudo-label \(y^{(e)}\). The algorithm was recirculated until the training sample was balanced. ```
0:\(\mathbf{T}_{r}\), imbalance training set with known labels, where \(v\) is the number of bands, \(n\) is the number of training samples. 0:\(\mathbf{T}_{u}\), unlabeled set, where \(z\) is the size of the unlabeled set. 0:\(q\), the number of samples in a random subset. 0:\(k\), the number of the nearest neighbour samples we obtain for each iteration. 1:\(G(\mathbf{x};\mathbf{\theta})\leftarrow\mathbf{T}_{r}\)\(\triangleright\) initialization classifier
2:\(\mathbf{Repeat}:\)
3:\(\mathbf{S}_{u}\in\mathbf{R}^{q\times p}\leftarrow\mathbf{T}_{u}\)\(\triangleright\) select a random subset
4:\((\mathbf{x}^{(i)},y^{(i)})\leftarrow\mathbf{T}_{r}\)\(\triangleright\) select a random sample in minority classes
5: compute distances between \(\mathbf{x}^{(i)}\) and each sample in \(\mathbf{S}_{u}\), search \(k\) closet samples.