Matrix sketching for supervised classification with imbalanced classes

Matrix sketching is a recently developed data compression technique. An input matrix A is efficiently approximated with a smaller matrix B, so that B preserves most of the properties of A up to some guaranteed approximation ratio. In so doing numerical operations on big data sets become faster. Sketching algorithms generally use random projections to compress the original dataset and this stochastic generation process makes them amenable to statistical analysis. The statistical properties of sketching algorithms have been widely studied in the context of multiple linear regression. In this paper we propose matrix sketching as a tool for rebalancing class sizes in supervised classification with imbalanced classes. It is well-known in fact that class imbalance may lead to poor classification performances especially as far as the minority class is concerned.


Introduction
In many practical contexts, observations have to be classified into two classes of remarkably distinct size.
In such cases, many established classifiers often trivially classify instances into the majority class achieving an optimal overall misclassification error rate.This leads to poor performance in classifying the minority class, the correct identification of which is usually of more practical interest.
The presence of imbalanced classes in the big data context also poses relevant computational issues.If the dataset contains thousands or millions of observations from the majority class for each example from the minority one, many of the majority class observations are redundant.Their presence increases the computational cost with no advantage in terms of classification accuracy.
The problem of imbalanced classes is very common in modern classification problems and has received a great attention in the machine learning literature (Chawla et al., 2004).
The error rate (or its complement, the accuracy) is the most widely used measure of classifier performance.However, it inevitably favors the majority class when the misclassification error has the same importance for the two classes.On the contrary, when the error in the minority class is more important than the one of the majority class, the receiver operating characteristic (ROC) curve and the corresponding area under the curve (AUC) are commonly suggested.
The ROC curve is a plot of the true positive rate (sensitivity) versus the false positive rate (1 −specificity) and hence a higher AUC generally indicates a better classifier.The ROC is obtained by varying the discriminant threshold, while the error rate is obtained at an optimal discriminant threshold.Therefore, AUC is independent of the discriminant threshold, while the accuracy is not.
The literature on the problem of supervised classification is very broad and methodological solutions follow two main streams.People either suggest to modify the loss function used in the construction of the classification rule or propose to re-balance the data.
The first solution requires, in most of the cases, the definition of a loss function that is specific for the case at hand and therefore not easily generalizable to different empirical problems.Re-balancing strategies are more general and not problem specific.That explains their great success in applied research and the focus on explaining their performances and on improving them.
Re-balancing the class sizes in the training dataset, is usually obtained either by oversampling the minority class or by under-sampling the majority class, or by a combination of both.The rebalanced data are then used to train the classifiers.
As far as two-class linear discriminant analysis is concerned, the problem has been addressed, among others, by Xie and Qiu (2007), Xue and Titterington (2008), Xue and Hall (2014).
Through a wide simulation study supported by theoretical considerations, Xue and Titterington (2008) show that AUC generally favors balanced data but the increase in the median AUC for LDA after rebalancing is relatively small.On the contrary, error rate favors the original data and re-balancing causes a sharp increase in the median error rate.They also stress that re-balancing affects the performances of LDA in both the equal and unequal covariance case.Xue and Hall (2014) prove that, in the Gaussian case, using the rebalanced training data can often increase the area under the ROC curve (AUC) for the original, imbalanced test data.In particular they demonstrate that, at least for LDA, there is an intrinsic, positive relationship between the re-balancing of class sizes and the improvement of AUC and the largest improvement in AUC can be achieved, asymptotically, when the two classes are fully rebalanced to be of equal sizes.
However, when the two Gaussian classes have similar covariance matrices, re-balancing class sizes only provides a little improvement in AUC for LDA.Moreover, re-balancing class sizes may not improve AUC when LDA is applied to non-Gaussian data.
In both the above mentioned papers re-balancing is obtained either by randomly undersampling the largest class or by randomly oversampling the smallest one.
It has however been argued that random undersampling may lose some relevant information while randomly oversampling with replacement the smallest class may lead to overfitting.
To avoid these drawbacks, solutions focusing on the border between the classes have been suggested.Mani and Zhang (2003) proposed selecting majority class examples whose average distance to its three nearest minority class examples is smallest.A similar approach is suggested by Fithian and Hastie (2014) in the context of logistic regression.They propose a method of efficient subsampling by adjusting the class balance locally in the feature space via an acceptance-rejection scheme.The proposal generalizes case-control sampling, using a pilot estimate to preferentially select examples whose responses (i.e.class membership identifiers) are conditionally rare given their features.
With special reference to classification trees and naive-Bayes classifiers Chawla et al. (2002) propose a strategy that combines random undersampling of the majority class with a special kind of oversampling for the minority one.They try to improve upon literature results according to which undersampling the majority class leads to better classifier performance than oversampling and combining the two does not produce much improvement with respect to simple undersampling.The synthetic examples allow to create larger and less specific decision regions, thus overcoming the overfitting effect inherent in random oversampling.SMOTE oversampling is combined with majority class undersampling.
The idea of creating synthetic examples has been followed also by Menardi and Torelli (2014) who proposed a method they called ROSE-Random OverSampling Examples (see, for a description of the corresponding R package, Lunardon et al., 2014).In this solution, units from both classes are generated by resorting to a smoothed bootstrap approach.A unimodal density is centered on randomly selected observations and new artificial data are randomly generated from it.
The key parameter of the procedure is the dispersion matrix of the chosen unimodal density which plays the role of smoothing parameter.The full dataset size is often kept fixed while allowing half of the units to be generated from the minority class and of half from the majority one.The method is applied to classification trees and logit models.

Matrix Sketching
Matrix sketching is a probabilistic data compression technique.Its goal is to reduce the number of rows in a data set and the task is accomplished by linearly combining the rows of the original data set through randomly generated coefficients.The analysis can then be performed on the reduced matrix, thus saving time and space.
The theoretical justification for this approach to data compression is given by Johnson-Lindenstrauss lemma (Johnson and Lindenstrauss, 1984).
Lemma 1 . Johnson Lindenstrauss (1984).Let Q be a subset of p points in R n , then for any ǫ ∈ (0, 1/2) and for k = 20 logp ǫ 2 there exists a Lipschitz mapping f : R n −→ R k such that for all u, v ∈ Q: The Lemma says that any p−point subset of the Euclidean space can be embedded in k dimensions without distorting the distances between any pair of points by more than a factor of 1 ± ǫ, for any ǫ in (0, 1/2).
Moreover, it also gives an explicit bound on the dimensionality required for a projection to ensure that it will approximately preserve distances.This bound depends on the dimension of the data matrix that is not sketched, i.e. p in this case.
The original proof by Johnson and Lindenstrauss is probabilistic, showing that projecting the p-point subset onto a random k-dimensional subspace only changes the inter point distances by 1 ± ǫ with positive probability.
In order to apply Johnson and Lindenstrauss lemma, the concept of ǫ−subspace embedding is useful.
Definition 1. ǫ−subspace embedding.For a given n × p matrix X, we call a k × n random matrix S an ǫ-subspace for X, if for all vectors z ∈ R p S is usually called Sketching Matrix.It reduces the sample size from n to k whilst preserving much of the linear information in the full dataset.As a consequence of Johnson and Lindenstrauss Lemma the scalar product too is preserved after random projections.
The original proof by Johnson and Lindenstrauss required S to have orthogonal rows; subsequent proofs relaxed the orthogonality requirement and assumed the entries of S to be independently randomly generated from a Gaussian distribution with 0 mean and variance equal to 1/k.This approach to sketching is known as Gaussian sketching and it is largely used in statistical applications as it allows for statistical analysis of the results obtained after sketching.
Although appealing from a theoretical point of view, Gaussian sketching is computationally demanding as the associated sketching matrix is full.Therefore research has been oriented towards developing more efficient algorithms still satisfying the ǫ-subspace embedding property.Another efficient method for generating ǫ−subspace embeddings is the so-called Clarkson-Woodruff sketch (Clarkson and Woodruff, 2017).The sketching matrix is a sparse random matrix S =Γ D, where Γ(k × n) and D(n × n) are two independent random matrices.The matrix Γ is a random matrix with only one element for each column set to +1.The matrix D is the same as above.This results in a sparse random matrix S with only one nonzero entry per column.The sparsity speeds up matrix multiplication, dropping the complexity of generating the sketched dataset to O(np).
It is worth noticing that the rows of the Gaussian and Clarkson-Woodruff sketching matrices are not orthogonal and this implies that the geometry of the original space is not preserved after sketching.The Gaussian sketching matrix is sometimes orthogonalized according to Gram-Schmidt procedure thus leading to what are known as Haar projections.This operation inevitably increases the computational load.
Hadamard sketching matrices on the contrary are orthogonal by construction.
Sketching methods have mainly been used as a data compression technique in the context of multiple linear regression, where the computation of the Gram matrix may become especially demanding for large n (Ahfock et al., 2017;Woodruff, 2014).In Falcone (2019) the use of the method has been extended to supervised classification.

Rebalancing through Sketching
Linear Discriminant Analysis (LDA) can be seen as a particular regression problem, therefore the same computational load inherent in the computation of the Gram matrix involved in multiple linear regression also affects LDA.
Given two groups G 0 and G 1 , of size n 0 and n 1 , coming from two omoschedastic populations with common covariance matrix Σ, let X 0 and X 1 denote the mean centered data matrices of population null and one, respectively, and x0 , x1 the corresponding mean vectors, where the subscript 1 identifies the minority class.
It is well known (Fisher, 1936;Anderson, 1962;McLachlan, 2004), the only linear discriminant direction is: where W, the within group covariance matrix, is After sketching the two groups separately, the sketched discriminant direction can be written as: Sketching preserves the scalar product while reducing the data set size.As the sketched data are obtained through random linear combinations of the original ones, most of the linear information is preserved after sketching.This means that, in the imbalanced data case, the size of the majority class can be reduced through sketching without incurring the risk of losing (too much) linear information.
Sketching the majority class can therefore be considered as a theoretically sound alternative to majority class undersampling.The sketched majority class data matrix reduced to the size of the minority class will then be X 0 (n 1 × p) and the corresponding covariance matrix will be Var( X 0 ) = ( X ⊤ 0 X 0 )/(n 0 − 1).
Sketching has been proposed as a data compression technique but, as a consequence of Johnson Linden-strauss lemma, the scalar product preservation also holds when the sketching matrix has a number of rows that is larger than the number of original data points.This allows to think of this unconventional way of using sketching as an alternative to random oversampling that generates synthetic new examples from the minority class (through random linear combination of all of them) while preserving the linear structure in the data.This allows to enlarge the decision area and thus to avoid overfitting.For example, in case it is desired to increase the size of the minority class so that it equals the one of the majority class the "oversketched" minority class data matrix will be X 1 (n 0 × p) and the corresponding covariance matrix will therefore be: The rebalanced covariance matrices can then be plugged into the within group covariance matrix and used for the computation of a new linear discriminant direction.
Sketching the majority class and oversketching the minority one can also be used in a combined way.
The use of matrix sketching is undoubtedly coherent with linear discriminant analysis which is based on the Gram matrix.Its performance in combination with other classification methods is not supported by the same strong theoretical motivation and can only be assessed through empirical analysis.This will be the topic of the next section in which different sketching methods are compared.
All the different sketching methods preserve the Gram matrix even if with a different goodness of approximation for different degrees of sketching.The different sketching methods can however change the data distribution.For instance Gaussian sketching tends to "gaussianize" the data and can therefore strongly distort skew data distributions.Moreover, as each linear combination is a function of all the units, potentially outlying observations impact on all the sketched data values and their effect is amplified.This effect is less evident for instance for Clarkson-Woodruff sketching which, being a sparse sketching method, only selects a few units for each random linear combination.

Empirical Results
The properties of sketching as a re-balancing method have been tested on many real datasets which differ in terms of imbalance degree.Here we report the results on the two most significant ones (spine and mammography) which have been classified both by linear discriminant analysis (see Tables 1 and 2) and C4.5 classification tree (Quinlan, 2014) (see Tables 3 and 4).The data set mammography (Woods et al., 1993)  Gaussian, Hadamard and Clarkson-Woodruff sketching have been applied in order to reduce the size of the majority class to the one of the minority class and in order to increase the size of the minority class so that it is as large as the majority class one.They have also been jointly used so that the size of both classes is twice the minority class size.For this last case re-balancing through SMOTE is also performed.For comparison, ROSE with its default option of preserving the total size is considered too.
Each data set has been randomly split in two parts: 75% of the units for both classes constituted the training set and the remaining 25% formed the test set.The procedure was repeated 200 times.The values in the tables represent the median of the quantity of interest over the 200 replicates.
The performance of the classifiers has been measured in terms of accuracy, sensitivity, specificity and area under the ROC curve (AUC).
The code implementing our procedure is available on request; ROSE and SMOTE have been applied using the corresponding R packages ROSE and DMwR.
They design an oversampling approach which creates synthetic examples (SMOTE -Synthetic Minority Over-sampling Technique) rather than oversampling with replacement.The minority class is over-sampled by taking each minority class sample and introducing synthetic examples along the line segments joining any/all of the k minority class nearest neighbors.Depending upon the amount of over-sampling required, neighbors from the k nearest neighbors are randomly chosen.
Ailon and Chazelle (2009)have proposed what is known as Hadamard sketch.The sketching matrix is formed as S = ΦHD/ √ k where Φ is a k × n matrix and H and D are both n × n matrices.The fixed matrix H is a Hadamard matrix of order n.A Hadamard matrix is a square matrix with elements that are either +1 or −1 and orthogonal rows.Hadamard matrices do not exist for all integers n, the source dataset can be padded with zeros so that a conformable Hadamard matrix is available.The random matrix D is a diagonal matrix where each nonzero element is an independent Rademacher random variable.The random matrix Φ subsamples k rows of H with replacement.The structure of the Hadamard sketch allows for fast matrix multiplication, reducing calculation of the sketched dataset from O(npk) of the gaussian sketch to O(np log k) operations.

Table 2 :
mammography, n=11,183, π 1 =2.32% -Median values (over 200 replications) Table1and 2 show that, coherently with the findings in Xue and Titterington and Xue and Hall, when combined with LDA, rebalancing causes a strong decrease in the accuracy which is combined with a little