Skip to main content

A comparison of random forest and its Gini importance with standard chemometric methods for the feature selection and classification of spectral data



Regularized regression methods such as principal component or partial least squares regression perform well in learning tasks on high dimensional spectral data, but cannot explicitly eliminate irrelevant features. The random forest classifier with its associated Gini feature importance, on the other hand, allows for an explicit feature elimination, but may not be optimally adapted to spectral data due to the topology of its constituent classification trees which are based on orthogonal splits in feature space.


We propose to combine the best of both approaches, and evaluated the joint use of a feature selection based on a recursive feature elimination using the Gini importance of random forests' together with regularized classification methods on spectral data sets from medical diagnostics, chemotaxonomy, biomedical analytics, food science, and synthetically modified spectral data. Here, a feature selection using the Gini feature importance with a regularized classification by discriminant partial least squares regression performed as well as or better than a filtering according to different univariate statistical tests, or using regression coefficients in a backward feature elimination. It outperformed the direct application of the random forest classifier, or the direct application of the regularized classifiers on the full set of features.


The Gini importance of the random forest provided superior means for measuring feature relevance on spectral data, but – on an optimal subset of features – the regularized classifiers might be preferable over the random forest classifier, in spite of their limitation to model linear dependencies only. A feature selection based on Gini importance, however, may precede a regularized linear classification to identify this optimal subset of features, and to earn a double benefit of both dimensionality reduction and the elimination of noise from the classification task.


The high dimensionality of the feature space is a characteristic of learning problems involving spectral data. In many applications with a biological or biomedical background addressed by, for example, nuclear magnetic resonance or infrared spectroscopy, also the number of available samples N is lower than the number of features in the spectral vector P. The intrinsic dimensionality P intr of spectral data, however, is often much lower than the nominal dimensionality P – sometimes even below N.

Dimension reduction and feature selection in the classification of spectral data

Most methods popular in chemometrics exploit this relation P intr < P and aim at regularizing the learning problem by implicitly restricting its free dimensionality to P intr .

(Here, and in the following we will adhere to the algorithmic classification of feature selection approaches from [1], referring to regularization approaches which explicitly calculate a subset of input features – in a preprocessing, for example – as explicit feature selection methods, and to approaches performing a feature selection or dimension reduction without calculating these subsets as implicit feature selection methods.) Popular methods in chemometrics, such as principal component regression (PCR) or partial least squares regression (PLS) directly seek for solutions in a space spanned by ~P intr principal components (PCR) – assumed to approximate the intrinsic subspace of the learning problem – or by biasing projections of least squares solutions towards this subspace [2, 3], down-weighting irrelevant features in a constrained regression (PLS). It is observed, however, that although both PCR and PLS are capable learning methods on spectral data – used for example for in [4] – they still have a need to eliminate useless predictors [5, 6]. Thus, often an additional explicit feature selection is pursued in a preceding step to eliminate spectral regions which do not provide any relevant signal at all, showing resonances or absorption bands that can clearly be linked to artefacts, or features which are unrelated to the learning task. Discarding irrelevant feature dimensions, though, raises the question of how to choose such an appropriate subset of features [68].

Different univariate and multivariate importance measures can be used to rank features and to select them accordingly [1]. Univariate tests marginalize over all but one feature and rank them in accordance to their discriminative power [9, 10]. In contrast, multivariate approaches consider several or all features simultaneously, evaluating the joint distribution of some or all features and estimating their relevance to the overall learning task. Multivariate tests are often used in wrapper schemes in combination with a subsequent classifier (e.g. a global optimization of feature subset and classifier coefficients [11]), or by statistical tests on the outcome of a learning algorithm (e.g. an iterative regression with test for robustness [12, 13]). While univariate approaches are sometimes deemed too simplistic, the other group of multivariate feature selection methods often comes at unacceptably high computational costs.

Gini feature importance

A feature selection based on the random forest classifier [14] has been found to provide multivariate feature importance scores which are relatively cheap to obtain, and which have been successfully applied to high dimensional data, arising from microarrays [1520], time series [21], even on spectra [22, 23]. Random forest is an ensemble learner based on randomized decision trees (see [24] for a review of random forests in chemometrics, [14] for the original publication, and [2528] for methodological aspects), and provides different feature important measures. One measure is motivated from statistical permutation tests, the other is derived from the training of the random forest classifier. Both measures have been found to correlate reasonably well [28]. While the majority of the prior studies focused on the first, we will focus on the second in the following.

As a classifier, random forest performs an implicit feature selection, using a small subset of "strong variables" for the classification only [27], leading to its superior performance on high dimensional data. The outcome of this implicit feature selection of the random forest can be visualized by the "Gini importance" [14], and can be used as a general indicator of feature relevance. This feature importance score provides a relative ranking of the spectral features, and is – technically – a by-product in the training of the random forest classifier: At each node τ within the binary trees T of the random forest, the optimal split is sought using the Gini impurity i(τ) – a computationally efficient approximation to the entropy – measuring how well a potential split is separating the samples of the two classes in this particular node.

With being the fraction of the n k samples from class k = {0,1} out of the total of n samples at node τ, the Gini impurity i(τ) is calculated as

Its decrease Δi that results from splitting and sending the samples to two sub-nodes τ l and τ r (with respective sample fractions and ) by a threshold t θ on variable θ is defined as

In an exhaustive search over all variables θ available at the node (a property of the random forest is to restrict this search to a random subset of the available features [14]), and over all possible thresholds t θ , the pair {θ, t θ } leading to a maximal Δi is determined. The decrease in Gini impurity resulting from this optimal split Δi θ (τ, T) is recorded and accumulated for all nodes τ in all trees T in the forest, individually for all variables θ:

This quantity – the Gini importance I G – finally indicates how often a particular feature θ was selected for a split, and how large its overall discriminative value was for the classification problem under study.

When used as an indicator of feature importance for an explicit feature selection in a recursive elimination scheme [1] and combined with the random forest itself as classifier in the final step, the feature importance measures of the random forest have been found to reduce the amount of features. Most studies using the Gini importance [22, 29] and the related permutation-based feature importance of random forests [16, 18, 20, 21, 23] together with random forests in a recursive feature elimination scheme, also showed an increases in prediction performance. (Only [17] reports a constant performance, but with greatly reduced amount of features.) While these experiments indicate the efficiency of the Gini importance in an explicit feature selection [24] one might raise the question whether a random forest – the "native" classifier of Gini importance – with its orthogonal splits of feature space is optimal also for the classification of spectra with correlated features and data-specific noise (Fig. 1), or if other classification models may be a better match with properties of spectral data.

Figure 1

Decision trees separating two classes: Classification problem with uncorrelated features (left), and a distorted version resulting from an additive noise process (right). The said process induces correlation by adding a random value to both features, thus mimicking the acquisition process of many absorption, reflectance or resonance spectra (see Methods section). Growing orthogonal decision trees on such a data set – shown on the right – results in deeply nested trees with complex decision boundaries. (Both trees not grown to full depth for visualization purposes).

Objective of this study

Thus, in the present work, we were interested in evaluating the combination of a feature selection by Gini importance together with standard chemometric classification approaches, such as discriminant PCR and PLS classification (D-PCR and D-PLS, respectively) which are known to be well adapted to spectra, and in studying their performance in dependence of specific characteristics of spectral data. In a first experiment we evaluated the joint application of explicit and implicit dimension reduction, using uni- and multivariate feature selection strategies in combination with random forest, D-PLS and D-PCR classification in an explicit recursive feature elimination (Table 1). In a second experiment, we studied the influence of different noise processes on random forest and D-PLS classification to identify optimal conditions for explicit and implicit dimension reduction. In both experiments we were interested in identifying general properties and differences of the methods employed in the classification of spectral data.

Table 1 Recursive feature selection.

Results and discussion

Visualizing feature importance

Measuring feature relevance using the Gini importance is subject to selection bias on factorial data [30]. Splits are more often sought on variables with a higher number of different factors, and a correction of the Gini importance is necessary in such cases [3032]. Spectral data, except for count data, represent continuous signals, with a distribution of N different values for each spectral channel or feature. Each feature will allow the same number of distinct splits in a random forest classification, and, hence, a measurement of the relevance of spectral regions for a specific classification problem will be unaffected by this potential source of bias.

Both univariate tests for significant class differences returned smooth importance vectors when employed on the spectral data (Fig. 2, top). The smoothness of the Gini importance was dependent on the size of the random forest (Fig. 2, bottom) – small forests resulted in "noisy" importance vectors, only converging towards smooth vectors when increasing the overall number of trees in the forest or the overall number of splits. As such changes influence the absolute value of this measure, the Gini importance could not be interpreted in absolute terms – like the p-values of the univariate tests – but only allowed for a relative comparison. For such a comparison between different variables and between different measures, the features were ranked according to their importance score (Fig. 3A). Here, univariate importance measures and Gini importance agreed well in many, although not all, spectral regions (Fig. 3A, rows 2 and 3). An example of the most prominent differences between univariate feature importance and multivariate Gini importance are highlighted in Fig. 3B. Spectral regions deemed unimportant by the univariate measures – with complete overlap of the marginal distributions as shown in Fig. 3B – may be attributed high importance by the multivariate importance measure (Fig. 4), indicating spectral regions with features of higher order interaction.

Figure 2

Importance measures on NMR candida data. in the range from 0.35 to 4 ppm (indicated in the upper figure) for all 1500 spectral channels (indicated in the lower figure). Top: p-values of a t-test (black) and Wilcoxon test (gray). Below: Gini importance of a random forest with 3000 trees (gray) and 6000 trees (black). Compare t ranked measures in Fig. 3.

Figure 3

Comparison of the different feature selection measures applied to the NMR candida 2 data (3A). Multivariate feature importance measures can select variables that are discarded by univariate measures (3B). Fig. 3A, from top to bottom: Gini importance, absolute values; Gini importance, ranked values, p-values from t-test, ranked values. Fig. 3B: Feature importance scores below (black: Gini importance, gray: t-test). Perhaps surprisingly, regions with complete overlap of the marginal distributions (3B bottom, indicated by vertical lines), are assigned importance by the multivariate measure (3B top). This is indicative of higher-order interaction effects which can be exploited when used as a feature importance measure with a subsequent classifier.

Figure 4

Tukey mean-difference plot of univariate and multivariate feature importance (left) and correlation of the importance measures shown in Fig. 3A. Horizontal lines in the left Fig. indicate differences of more than two sigma, the vertical line in the right Fig. indicates a threshold on the univariate P-value of 0.05 (with relevant features being to the right of the vertical line). -. The importances assigned by univariate and multivariate measures are generally highly correlated; many of the features marked in red (corresponding to the spectral channels indicated in Fig. 3B), however, are flagged as uninformative by a univariate measure and as relevant by a multivariate measure.

Inspecting the Gini feature importance we observed – similar to [32] – that some spectral regions were selected as a whole, suggesting that correlated variables were assigned similar importance. Thus, the importance measure may be interpreted like a spectrum, where neighbouring channels of similar importance may be considered as representatives of the same peak, absorbance or resonance line. This can be used in an exploratory visualization of feature relevance (Figs. 2 and 3A, top row). As the random forest prefers splits on correlated variable over splits on uncorrelated ones [28] it should be noted, however, that this "importance spectrum" may be somewhat biased towards overestimating the importance of major peaks spanning over many spectral channels.

Feature selection and classification

The classification accuracies provided by the first experiment based on the real data allowed for a quantitative comparison of the methods applied and for testing for statistically significant differences between results on the full set of features in comparison to the subselected data sets (Table 2, "stars"). On one half of the data, the feature selection hardly changed the classification performance at all (Tables 2 and 3, tumor and candida data), while on the other half a feature selection improved the final result significantly (Tables 2 and 3, wine and BSE data), almost independently of the subsequent classifier. In the latter group optimally subselected data typically comprised about 1–10% of the initial features (Table 3, Fig. 5). Such a data dependence in the benefit of a preceding feature selection is well known (e.g. [33]). Different from [33], however, we did not see a relation to the apparent degree of ill-posedness of the classification problem (i.e., a low ratio N/P of the length of the spectral vector P and the number of available samples N leading to an underdetermined estimation problem – he BSE and candida data, for example, are nearly identical in dimensionality – P BSE = 1209, P candida = 1500 – and number of training samples – N BSE = 2 * 96, N candida = 2 * 101).

Table 2 Average cross-validated prediction accuracy.
Figure 5

Classification accuracy (left column) and standard error (right column) during the course of recursive feature elimination for PLS regression (black), PC regression (dark gray) and random forest (light gray), in combination with different feature selection criteria: univariate (dotted), PLS/PC regression (dashed) and Gini importance (solid).

Table 3 Benefit from feature selection.

Random forest, the only nonlinear classifier applied, performed slightly better than the linear classifiers on the unselected data sets (BSE and wine data, Fig. 5), but improved only moderately in the course of the feature selection (Fig. 5, Table 3: p-value > 10-3). Given that random forest performs well on the unselected data sets, and that little or no benefit is incurred by an additional explicit feature selection (Table 2, Fig. 5), it is apparent that an implicit feature selection is at work and performs well when training the random forest classifier. Ultimately, however, the random forest classifier was surpassed in performance by any of the regularized linear methods on all data sets (Table 2: column 9 vs. column 7–8). This rather weak classification performance of the random forest may be seen in line with [20], but contrasts results of e.g. [10, 18] using random forest in the classification of microarrays, similar to spectra in their high dimensionality of their feature vectors. Few differences could be observed between D-PLS and D-PCR classification. Among the different feature selection strategies, the Wilcoxon-test and the Gini importance performed better on average than the iterated selection based on the regression coefficients (Fig. 5, Table 2), with slightly better classification results for the Gini importance (Table 2). Overall, while the Gini importance was preferable in feature selection, the chemometric methods performed better than random forest in classification, in spite of their limitation to model linear dependencies only.

The two linear classifiers of this study generally seek for subspaces c k maximizing the variance Var of the explanatory variables X in the subspace c

in case of PCR or the product of variance and the (squared) correlation Corr

with the response y in case of PLS [2, 3]. Thus, for a better understanding of D-PCR and D-PLS, both Corr(x, y) and Var(x) were plotted for individual channels and for individual learning tasks in Fig. 6 (with the absolute value of the coefficients of c encoded by the size of the circles in Fig. 6). On data sets which did not benefit greatly from the feature selection, we observed variance and correlation to be maximal in those variables which were finally assigned the largest coefficients in the regression (indicated by the size of the black circles in Fig. 6). Conversely, in data sets where a feature selection was required, features with high variance but only moderate relevance to the classification problem (as indicated by a low univariate correlation or multivariate Gini importance) were frequently present in the unselected data (Fig. 6, black dots). This might be seen as a likely reason for the bad performance of D-PCR and D-PLS when used without preceding feature selection on the BSE and wine data: Here the selection process allowed to identify those features where variance coincided with class-label correlation (Fig. 6, red circles), leading to a similar situation in the subsequent regression as for those data sets where a feature selection was not required (Fig. 6, compare subselected features indicated red in the left and central row with features in the right row).

Figure 6

Channel-wise variance of each feature (horizontal axis) and its correlation with the dependent variable (vertical axis). For the data sets of the left and the central column, a feature selection was not required for optimal performance, while the data sets shown in the right columns benefitted from a feature selection. Circle diameter indicates magnitude of the coefficient in the PLS regression. In the right column selected features are shown by red circles, while (the original values of) eliminated features are indicated by black dots. Relevant features show both a high variance and correlation with the class labels.

In summary, observing that the degree of ill-posedness is not in itself an indicator for a required feature selection preceding a constrained classification, it might be argued that non-discriminative variance – hindering the identification of the optimal subspace in PCR, and disturbing the optimal trade-off between correlation and variation in PLS – may be a reason for the constrained classifiers' failing on the unselected data and, consequently, a requirement for a feature selection in the first place.

Feature selection and noise processes

The first experiment advocated the use of the Gini importance for a feature selection preceding a constrained regression for some data sets. Thus, and in the light of the unexpectedly weak performance of the random forest classifier, we studied the performance of the D-PLS and the random forest classifier as a function of noise processes which can be observed in spectral data (see Methods section for details) to identify optimal situations for the joint use of explicit and implicit feature selection.

In this second experiment, random forest proved to be highly robust against the introduction of "local" noise, i.e. against noise processes affecting few spectral channels only, corresponding to spurious peaks or variant spectral regions which are irrelevant to the classification task (both on the synthetic bivariate classification problem, Figs. 1 left, 7A; and the modified real data, Fig. 7CE). The random forest classifier was, however, unable to cope with additive global noise: Already random offsets that were fractions of the amplitude S of the spectra (Fig. 7DF; S = 10-2) resulted in a useless classification by the random forest. As global additive noise stretches the data along the high dimensional equivalent of the bisecting line (Fig. 1), the topology of its base learners may be a disadvantage for the random forest in classification problems as shown in Fig. 1. Single decision trees, which split feature space in a box-like manner orthogonal to the feature direction are known to be inferior to single decision trees splitting the feature space by oblique splits [34] (although they have a considerable computational advantage). Random offsets often occur in spectral data, for example resulting from broad underlying peaks or baselines, or from the normalization to spectral regions that turn out to be irrelevant to the classification problem. Thus, one might argue that the "natural" presence of a small amount of such noise may lead to the rather weak overall performance of the random forest observed in the first experiment (Table 2, Fig. 5).

Figure 7

The effect of different noise processes on the performance of a random forest (green triangles) and a PLS classification (red circles). In the left column, feature vectors are augmented by a random variable, which is subsequently rescaled according to a factor S (horizontal axis), thus introducing non-discriminatory variance to the classification problem. In the right column, a random variable scaled by factor S is added as constant offset to the feature vectors, increasing the correlation between features (see text for details). Shown are results on the basis of the bivariate classification problem of Fig. 1 (top row), the NMR candida 2 data (middle), and the BSE binned data (below).

Partial least squares performed slightly better than random forests on all three data sets at the outset (Fig. 7). In contrast to the random forest, PLS was highly robust against global additive noise: On the synthetic classification problem – being symmetric around the bisecting line – the random offsets did not influence the classification performance at all (Fig. 7B). On the real data – with more complex classification tasks – the D-PLS classification still showed to be more robust against random offsets than the random forest classifier (Fig. 7DF). Conversely, local noise degraded the performance of the D-PLS classification (Fig. 6ACE, although for rather large values of S only). The D-PLS classifier seemed to be perfectly adapted to additive noise – splitting classes at arbitrary oblique directions – but its performance was degraded by a large contribution of non-discriminatory variance to the classification problem (Figs. 6 &7ACE).

In the presence of increasing additive noise, both univariate and multivariate (i.e., the Gini importance) feature importance measures lost their power to discriminate between relevant and random variables at the end (Fig. 8DF), with the Gini importance retaining discriminative power somewhat longer finally converging to a similar value for all three variables correlating well with a random classification and an (equally) random assignment of feature importance (Fig. 8D). When introducing a source of local random noise and normalizing the data accordingly, the univariate tests degraded to random output (Fig. 8E), while the Gini importance measure (Fig. 8CE) virtually ignored the presence and upscaling of the non-discriminatory variable (as did the random forest classifier in Fig. 7ACE).

Figure 8

The effect of different noise processes on the performance of the feature selection methods in the synthetic bivariate classification problem illustrated in Fig. 1. In the left column feature vectors are extended by a random variable scaled by S, in the right column a random offset of size S is added to the feature vectors. Top row: classification accuracy of the synthetic two-class problem (as in Fig. 7, for comparison); second row: multivariate Gini importance, bottom row: p-values of univariate t-test. The black lines correspond to the values of the two features spanning the bivariate classification task (Fig. 1), the blue dotted line corresponds to the third feature in the synthetic data set, the random variable. The performance of the random forest remains nearly unchanged even under the presence of a strong source of "local" noise for high values of S.

Feature selection using the Gini importance

Overall, we observed that the random forest classifier – with the non-oblique splits of its base learner – may not be the optimal choice in the classification of spectral data. For feature selection, however, its Gini importance allowed to rank non-discriminatory features low and to remove them early on in a recursive feature elimination. This desirable property is due to the Gini importance being based on a rank order measure which is invariant to the scaling of individual variables and unaffected by non-discriminatory variance that does disturb D-PCR and D-PLS. Thus, for a constrained classifier requiring a feature selection due to the specificities of the classification problem (Table 2, Fig. 5), the Gini feature importance might be a preferable ranking criterion: as a multivariate feature importance, it is considering conditional higher-order interactions between the variables when measuring the importance of certain spectral regions, providing a better ranking criterion than a univariate measure used here and in similar tasks elsewhere [9, 10].

A comparison of the computing times of the different feature selection and classification approaches (Table 4) shows that the computational costs for using the Gini importance is comparable to the cost of using the other multivariate feature selection criterion tested in this study. On average the computing time was no more than twice as long as for the more basic univariate importance measures.

Table 4 Computing times.


In the joint application of the feature selection and classification methods on spectral data neither the random forests classifier using the Gini importance in a recursive feature selection, nor a constrained regression without feature selection were the optimal choice for classification. Random forest showed to be robust against single noisy features with a large amount of non-discriminatory variance. Unfortunately it also showed to be highly sensible to random offsets in the feature vector, a common artefact in spectral data. D-PLS was capable of dealing with such offsets, although it failed in the presence of non-discriminatory variance in single, highly variable features. The removal of such irrelevant – or even misleading – predictors was crucial in the application of the constrained classifiers tested in this study. Overall, the combined application of Gini importance in a recursive feature elimination together with a D-PLS classification was either the best approach or – in terms of statistical significance – comparable to the best in all classification tasks, and may be recommended for the separation of binary, linearly separable data.

The results also suggest that when using a constrained learning method – such as the D-PLS or D-PCR classifier as in this study – the main purpose of a feature selection is the removal of few "noisy" features with a large amount of variance, but little importance to the classification problem. Then, the feature elimination is a first step in the regularization of a classification task, removing features with non-discriminatory variance, and allowing for a better regularization and implicit dimension reduction by the subsequent classifier. Considering the similarity of PLS, ridge regression and continuum regression [2, 3, 35] – all of them trading correlation with class labels, and variance of the data for a regularization – one might expect this to be a general feature for these constrained regression methods.

Only binary classifications tasks were studied here, but one may expect that results generalize to multi-class problems as well when using, for example, penalized mixture models in place of a D-PLS classification. It might be worthwhile to test whether using a constrained classifier in the final classification step of a recursive feature selection is able to increase the classification performance on other data as well, for example on microarrays where a recent study [20] reported of a general advantage of support vector machines with RBF-kernel over the random forest classifier.

Of course, rather than advocating a hybrid method using random forest for feature selection and a constrained linear classifier to predict class membership, it might be advantageous to adapt the random forest classifier itself to fit the properties of spectral data in an optimal fashion. For individual tree-like classifiers, a large body of literature about trees using such non-orthogonal, linear splits in their nodes is available [34] and may be used for such an adaption of the random forest classifier.


In a first experiment, we systematically evaluated the joint use of different feature selection and classification methods, on a number of different spectral data sets. In a second, we looked into the behaviour of the random forest and D-PLS classifier on synthetically modified data, to understand specific properties of these methods when applied to spectra.

Experiment 1: Joint feature selection and classification

In general, feature selection is a concern in both regression (prediction of a continuous response) and in classification (prediction of two or more categories). Here, we confined ourselves to binary classification tasks. Our experiments were based on four different data sets available to us from different studies [3639], providing – with different preprocessing, labels, or dichotomous sub-problems – eleven binary classification tasks (Table 2).

Classification and feature selection methods

Three different feature selection approaches were applied to the data in an explicit recursive feature elimination (Table 1), together with the three following classifiers: linear discriminant principal component (D-PCR) and partial least squares (D-PLS) classification (using [40]) and the nonlinear random forest classifier (RF) (using [41]). While trees in the random forest allow for a classification via majority votes and a binary decision, D-PCR and D-PLS classification were used with a predefined and fixed threshold, i.e. a score of 0.5 intermediate to the trained class values 0 and 1, using balanced classes during training and for the test (see below).

As univariate feature selection measure, the p-values of channel-wise Wilcoxon-tests for class differences were used to rank the features and to allow for a filtering of features prior to the D-PLS and D-PCR classification. In the two multivariate feature selection procedures applied, variables were recursively eliminated either according to smallest PLS or PC regression coefficient (as in [5], although without stability test), or according to smallest Gini importance value. In the latter case the actual classification in the selected subspace was performed not only by a RF as in [1518], but also by the linear classifiers. In total, seven different combinations of feature selection and classification methods were applied to the data (Table 2). The classification of the data without any feature selection was tested as well. For the results shown in the last column of Tables 2 and 3 – i.e. the combination of feature selection using regression coefficients and a subsequent classification by RF – PLS was used in feature selection. For the sake of computational simplicity, all multivariate feature selection measures were optimized using their own cost function and not in a joint loop with the subsequent classifier (using a cross-validated least-squares-error for PLS and PCR regression coefficients and the out-of-bag classification error of the RF for Gini importance, optimized over the same parameter spaces as the respective classifiers). For both univariate filters and multivariate wrappers, 20% of the remaining features were removed in each iteration step. Prior to classification all data was subject to L1 normalization, i.e. to a normalization of the area under the spectrum in a predefined spectral region.


Data set one, the BSE data set, originates from a study concerning a conceivable ante-mortem test for bovine spongiform encephalopathy (BSE). Mid-infrared spectra of N = 200 dried bovine serum samples (N pos = 95, N neg = 105) were recorded in the spectral range of 400–4000 cm-1 with P = 3629 data points per spectrum. Details of the sample preparation and of the acquisition of spectra are reported in Refs. [14, 31]. The same spectra were used in a second binary classification task after a smoothing and downsampling ("binning"), and thus by reducing the number of data points per spectrum to P red = 1209.

Data set two, the wine data set, comprised N = 71 mid-infrared spectra with a length of P = 3445 data points from the spectral region of 899–7496 cm-1, sampled at a resolution of approx. 4 cm-1 interpolated to 2 cm-1, originating from the analysis of 63 different wines using an automated MIRALAB analyzer with AquaSpec flow cell. In the preprocessing a polynomial filter (Savitzky-Golay, length 9) of second order was applied to the spectra. Labels assigned to these data were the type of grape (N red = 30, N white = 41) in a first learning task and an indicator of the geographic origin of the wine (N French = 26, N World = 45) in a second.

Data set three, the tumor data set, comprised N = 278 in vivo 1H-NMR spectra with a length of P = 101 data points from the spectral region between approximately 1.0 ppm and 3.5 ppm, originating from 31 magnetic resonance spectroscopic images of 31 patients, acquired at 1.5 T with an echo time of 135 ms in the pre-therapeutic and post-operative diagnostics of (recurrent) brain tumor (N healthy = 153, N tumor border = 72, N tumor center = 53) [31, 32]. Two binary groupings were tested, either discriminating healthy vs. both tumor groups (tumor all), or the spectral signature of the tumor center vs. the remaining spectra (tumor center).

Data set four, the candida data set, comprised N = 581 1H-NMR spectra of cell suspensions with a length of P = 1500 data points in between 0.35–4 ppm, originating from a chemotaxonomic classification of yeast species (Candida albicans, C. glabrata, C. krusei, C. parapsilosis, and C. tropicalis). A subset of the data was originally published in [34]. Its five different subgroups of sizes N = {175, 109, 101, 111, 85} allowed to define five different binary subproblems ("one-against-all").


In the evaluation, 100 training and 100 test sets were sampled from each of the available data sets, in a ten times repeated ten-fold cross validation [42, 43], following the overall test design in [19]. In order to obtain equal class priors both in training and testing, the larger of the two groups of the binary problems was subsampled to the size of the smaller if necessary. Where dependence between observations was suspected, e.g. in the tumor data where more than one spectrum originated for each patient, the cross-validation was stratified to guarantee that all spectra of a correlated subset were exclusively assigned to either the training or the test data [42, 43].

The random forest parameters were optimized in logarithmic steps around their default values [41] (using 300 trees, and a random subspace with dimensionality equal to the rounded value of the square of the number of features) according to the out-of-bag error of the random forest, while the number of latent variables γ in the linear classifiers was determined by an internal five-fold cross-validation for each subset, following the 1σ rule for choosing the γ at the intersection between the least error (at γ opt ) plus an interval corresponding to the 1σ standard deviation at γ opt , and the mean accuracy.

The classification accuracy was averaged over all 100 test results and used as performance measure in the comparison of the different methods. While all feature selection and all optimization steps in the classification were performed utilizing the training data only, test result were recorded for all feature subsets obtained during the course of feature selection (Fig. 4). To verify significant differences between the test results, a paired Cox-Wilcoxon test was used on the accuracies of the 100 test sets as proposed in [42, 43]. Such paired comparisons were performed for each classifier between the classification result obtained for the full set of features, and the best result when applied in conjunction with a selection method (i.e. the results with highest classification accuracy in the course of feature selection). Feature selection approaches leading to a significant increase in classification performance were indicated accordingly (Table 2, indicated by stars). Once the best feature selection and classification approach had been identified for a data set (as defined by the highest classification accuracy in a row in Table 2), it was compared against all other results on the same data set. Results which were indistinguishable from this best approach (no statistical difference at a 5% level) were indicated as well (Table 2, indicated by bold values).

Experiment 2: PLS and RF classification as a function of specific data properties

D-PLS reportedly benefits from an explicit feature selection on some data sets [33]. Random forest reportedly performed well in classification tasks with many features and few samples [1518], but was outperformed by standard chemometrical learning algorithms when used to classify spectral data. Thus, to identify reasons for these differences and to corroborate findings from experiment one, we decided to study the performance of both methods in dependence of two noise processes which are specific to spectral data.

Noise processes

We identified two sources of unwanted variation (noise processes) which can be observed in spectral data, and which can jeopardize the performance of a classifier.

First, there are processes affecting few, possibly adjacent, spectral channels only. Examples for such changes in the spectral pattern are insufficiently removed peaks and slight peak shifts (magnetic resonance spectroscopy), the presence of additional peaks from traces of unremoved components in the analyte, or from vapour in the light beam during acquisition (infrared spectroscopy). Identifying and removing spectral channels affected by such processes is often the purpose of explicit feature selection. We refer to this kind of noise as "local noise" in the following, where the locality refers to the adjacency of channels along the spectral axis.

Second, there are processes affecting the spectrum as a whole. Examples for such noise processes may be the presence (or absence) of broad baselines, resulting in a random additional offset in the spectrum. Variation may also result from differences in the signal intensities due to changes in the concentration of the analyte, variation in reflectance or transmission properties of the sample (infrared spectroscopy), or the general signal amplitude from voxel bleeding and partial volume effects (magnetic resonance spectroscopy), leading to a scaling of the spectrum as a whole, and – after normalization – to random offsets in the spectrum. Such processes increase the nominal correlation between features and are the main reason for the frequent use of high-pass filters in the preprocessing of spectral data (Savitzky-Golay filter, see above). It might be noted that this noise does not have to offset the spectrum as a whole to affect the classification performance significantly, but may only modify those spectral regions which turn out to be relevant to the classification task. Nevertheless, we refer to this kind of noise as "global noise" here.

Modified and synthetic data sets

For visualization (Fig 1, left), we modelled a synthetic two-class problem, by drawing 2*400 samples from two bivariate normal distributions (centred at (0,1) and (1,0), respectively, with standard deviation 0.5). The two features for the two-dimensional classification task were augmented by a third feature comprising only random noise (normally distributed, centred at 0, standard deviation 0.5), resulting in a data set with N = 800, P = 3 and balanced classes. To mimic local noise, we rescaled the third, random feature by a factor S, for S = 2{0,1,...,20}. In real spectra one might expect S – the ratio between the amplitude of a variable that is relevant to the classification problem, and a larger variable introducing non-discriminatory variance only – to be of several orders of magnitude. Here, changing S gradually increased the variance of the third feature and the amount of non-discriminatory variance in the classification problem. To mimic global noise, we added a constant offset (normally distributed, centred at 0, standard deviation 0.5), also scaled by S = 2{0,1,...,20}, to the features of every sample as an offset. This increased the correlation between the features and, along S, gradually stretched the data along the bisecting line (Fig. 1, right).

In addition to the synthetic two-class problem of Fig. 1, we modified two exemplary real data sets (candida 2 and BSE binned) by these procedures in the same way, here using S = 10{-6,-4,...,16}, using the largest amplitude of a spectrum as reference for a shift by S = 1, or a rescaling of the random feature (N(0,.5)).


Gini importance and univariate importance (t-test) were calculated along S for the features of the synthetic data set. PLS and random forest classification were applied to all data sets, for all values of S, after a L2-normalization of the feature vector. (Which may be a closer match with the noise statistic than the L1 normalization used in the real data in the first experiment.) Classification accuracy was determined according to the procedure described above (Experiment 1).


  1. 1.

    Guyon I, Elisseeff A: An introduction to variable and feature selection. J Mach Learn Res 2003, 3: 1157–82. 10.1162/153244303322753616

    Google Scholar 

  2. 2.

    Stone M, J R, Brooks Continuum regression: Cross-validated sequentially constructed prediction embracing ordinary least squares, partial least squares and principal components regression. J Roy Stat Soc B (Meth) 1990, 52: 237–269.

    Google Scholar 

  3. 3.

    Frank IE, Friedman JH: A statistical view of some Chemometrics regression tools. Technometrics 1993, 35: 109–135. 10.2307/1269656

    Article  Google Scholar 

  4. 4.

    Bylesjö M, Rantalainen M, Nicholson JK, Holmes E, Trygg J: K-OPLS package: Kernel-based orthogonal projections to latent structures for prediction and interpretation in feature space. BMC Bioinformatics 2008, 9: 106. 10.1186/1471-2105-9-106

    PubMed Central  Article  PubMed  Google Scholar 

  5. 5.

    Westad F, Martens H: Variable selection in near infrared spectroscopy based on significance testing in partial least squares regression. J Near Infrared Spectrosc 2000, 117: 117–124. 10.1255/jnirs.271

    Article  Google Scholar 

  6. 6.

    Nadler B, Coifman RR: The prediction error in CLS and PLS: the importance of feature selection prior to multivariate calibration. J Chemometrics 2005, 19: 107–118. 10.1002/cem.915

    CAS  Article  Google Scholar 

  7. 7.

    Denham MC, Brown PJ: Calibration with many variables. Appl Stat 1993, 42: 515–528. 10.2307/2986329

    Article  Google Scholar 

  8. 8.

    Baumann K, von Korff M, Albert H: Asystematic evaluation of the benefits and hazards of variable selection in latent variable regression. Part I. Search Algorithm, theory and simulations. J Chemometrics 2002, 16: 339–350. 10.1002/cem.730

    CAS  Article  Google Scholar 

  9. 9.

    Hastie T, Tibshirani R, Eisen MB, Alizadeh A, Levy R, Staudt L, Chan WC, Botstein D, Brown P: 'Gene shaving' as a method for identifying distinct sets of genes with similar expression patterns. Genome Biol 2000, 1: 3. 10.1186/gb-2000-1-2-research0003

    Article  Google Scholar 

  10. 10.

    Zeng XQ, Li GZ, Yang JY, Yang MQ, Wu GF: Dimension reduction with redundant gene elimination for tumor classification. BMC Bioinformatics 2008, 9: S8. 10.1186/1471-2105-9-S6-S8

    PubMed Central  Article  PubMed  Google Scholar 

  11. 11.

    Leardi R: Genetic algorithms in chemometrics and chemistry: a review. J Chemometrics 2001, 15: 559–569. 10.1002/cem.651

    CAS  Article  Google Scholar 

  12. 12.

    Centner V, Massart DL, de Noord OE, de Jong S, Vandeginste BM, Sterna C: Elimination of uninformative variables for multivariate calibration. Anal Chem 1996, 68: 3851–58. 10.1021/ac960321m

    CAS  Article  PubMed  Google Scholar 

  13. 13.

    Forina M, Casolino C, Millan CP: Iterative predictor weighting (IPW) PLS: a technique for the elimination of useless predictors in regression problems. J Chemometrics 1999, 13: 165–84. Publisher Full Text10.1002/(SICI)1099-128X(199903/04)13:2<165::AID-CEM535>3.0.CO;2-Y

    CAS  Article  Google Scholar 

  14. 14.

    Breiman L: Random forests. J Mach Learn 2001, 45: 5–32. 10.1023/A:1010933404324

    Article  Google Scholar 

  15. 15.

    Jiang H, Deng Y, Chen H-S, Tao L, Sha Q, Chen J, Tsai C-J, Zhang S: Joint analysis of two microarray gene-expression data sets to select lung adenocarcinoma marker genes. BMC Bioinformatics 2004, 5: 1–12. 10.1186/1471-2105-5-81

    Article  Google Scholar 

  16. 16.

    Diaz-Uriarte R, Alvarez de Andres S: Gene selection and classification of microarray data using random forest. BMC Bioinformatics 2006, 7: 1–25. 10.1186/1471-2105-7-3

    Article  Google Scholar 

  17. 17.

    Li S, Fedorowicz A, Singh H, Soderholm SC: Application of the random forest method in studies of local lymph node assay based skin sensitization data. J Chem Inf Comp Sci 2005, 45: 952–64.

    CAS  Article  Google Scholar 

  18. 18.

    Geurts P, Fillet M, de Seny D, Meuwis M-A, Malaise M, Merville M-P, Wehenkel L: Proteomic mass spectra classification using decision tree based ensemble methods. Bioinformatics 2005, 21: 313–845. 10.1093/bioinformatics/bti494

    Article  Google Scholar 

  19. 19.

    Dudoit S, Fridlyand J, Speed TP: Comparison of discrimination methods for the classification of tumors using gene expression data. J Am Stat Assoc 2002, 97: 77–88. 10.1198/016214502753479248

    CAS  Article  Google Scholar 

  20. 20.

    Statnikov A, Wang L, Aliferis CF: A comprehensive comparison of random forests and support vector machines for microarray-based cancer classification. BMC Bioinformatics 2008, 9: 319. 10.1186/1471-2105-9-319

    PubMed Central  Article  PubMed  Google Scholar 

  21. 21.

    Shen KQ, Ong CJ, Li XP, Zheng H, Wilder-Smith EPV: A Feature Selection Method for Multi-Level Mental Fatigue EEG Classification. IEEE Trans Biomed Engin 2007, 54: 1231–1237. 10.1109/TBME.2007.890733

    Article  Google Scholar 

  22. 22.

    Menze BH, Petrich W, Hamprecht FA: Multivariate feature selection and hierarchical classification for infrared spectroscopy: serum-based detection of bovine spongiform encephalopathy. Anal Bioanal Chem 2007, 387: 801–1807. 10.1007/s00216-006-1070-5

    Google Scholar 

  23. 23.

    Granitto P, Furlanello C, Biasioli F, Gasperi F: Recursive Feature Elimination with Random Forest for PTR-MS analysis of agroindustrial products. Chem Intell Lab Sys 2006, 83: 83–90. 10.1016/j.chemolab.2006.01.007

    CAS  Article  Google Scholar 

  24. 24.

    Svetnik V, Liaw A, Tong C, Culberson JC, Sheridan RP, Feuston BP: Random Forest: A Classification and Regression Tool for Compound Classification and QSAR Modeling. J Chem Inf Comp Sci 2003, 43: 1947–58.

    CAS  Article  Google Scholar 

  25. 25.

    Lin Y, Jeon Y: Random Forests and adaptive nearest neighbor. J Am Stat Assoc 2006, 101: 578–590. 10.1198/016214505000001230

    CAS  Article  Google Scholar 

  26. 26.

    Biau G, Devroye L, Lugosi G: Consistency of Random Forests and Other Averaging Classifiers. J Mach Learn Res 2008, 9: 2015–2033.

    Google Scholar 

  27. 27.

    Breiman L: Consistency for a simple model of random forests. In Technical Report 670. Technical report, Department of Statistics, University of California, Berkeley, USA; 2004.

    Google Scholar 

  28. 28.

    Strobl C, Boulesteix A-L, Kneib T, Augustin T, Zeileis A: Conditional variable importance for random forests. BMC Bioinformatics 2008, 9: 307. 10.1186/1471-2105-9-307

    PubMed Central  Article  PubMed  Google Scholar 

  29. 29.

    Jiang R, Tang W, Wu X, Fu W: A random forest approach to the detection of epistatic interactions in case-control studies. BMC Bioinformatics 2009, 10(Suppl 1):S65.

    PubMed Central  Article  PubMed  Google Scholar 

  30. 30.

    Strobl C, Boulesteix AL, Zeileis A, Hothorn T: Bias in Random Forest Variable Importance Measures: Illustrations, Sources and a Solution. BMC Bioinformatics 2007, 8: 25. 10.1186/1471-2105-8-25

    PubMed Central  Article  PubMed  Google Scholar 

  31. 31.

    Sandri M, Zuccoletto P: A bias correction algorithm for the Gini variable importance measure in classification trees. J Comp Graph Stat 2008, 17: 611–628. 10.1198/106186008X344522

    Article  Google Scholar 

  32. 32.

    Archer KJ, Kimes RV: Empirical characterization of random forest variable importance measures. Comp Stat Data Anal 2008, 52: 2249–2260. 10.1016/j.csda.2007.08.015

    Article  Google Scholar 

  33. 33.

    Gauchi J-P, Chagnon P: Comparison of selection methods of explanatory variables in PLS regression with application to manufacturing process data. Chem Intell Lab Sys 2001, 58: 171–93. 10.1016/S0169-7439(01)00158-7

    CAS  Article  Google Scholar 

  34. 34.

    Murthy SK, Kasif S, Salzberg S: A System for Induction of Oblique Decision Trees. J Artif Intell Res 1994, 2: 1–32.

    Google Scholar 

  35. 35.

    Bjorkstrom A: A generalized view on continuum regression. Scand J Stat 1999, 26: 17–30. 10.1111/1467-9469.00134

    Article  Google Scholar 

  36. 36.

    Martin TC, Moecks J, Belooussov A, Cawthraw S, Dolenko B, Eiden M, Von Frese J, Kohler W, Schmitt J, Somorjai RL, Udelhoven T, Verzakov S, Petrich W: Classification of signatures of bovine spongiform encephalopathy in serum using infrared spectroscopy. Analyst 2004, 129: 897–901. 10.1039/b408950m

    CAS  Article  PubMed  Google Scholar 

  37. 37.

    Menze BH, Lichy MP, Bachert P, Kelm BM, Schlemmer H-P, Hamprecht FA: Optimal classification of long echo time in vivo magnetic resonance spectra in the detection of recurrent brain tumors. NMR in Biomedicine 2006, 19: 599–60. 10.1002/nbm.1041

    CAS  Article  PubMed  Google Scholar 

  38. 38.

    Menze BH, Kelm BM, Heck D, Lichy MP, Hamprecht FA: Machine based rejection of low-quality spectra and estimation of brain tumor probabilities from magnetic resonance spectroscopic images. In Proceedings of BVM. Edited by: Handels H, Ehrhardt J, Horsch A, Meinzer H-P, Tolxdorff T. Springer, New York; 2006:31–35.

    Google Scholar 

  39. 39.

    Himmelreich U, Somorjai RL, Dolenko B, Lee OC, Daniel HM, Murray R, Mountford CE, Sorrell TC: Rapid identification of candida species by using nuclear magnetic resonance spectroscopy and a statistical classification strategy. Appl Environm Microbiol 2003, 69: 4566–74. 10.1128/AEM.69.8.4566-4574.2003

    CAS  Article  Google Scholar 

  40. 40.

    Mevik B-H, Wehrens R: The pls Package: Principal Component and Partial Least Squares Regression in R. J Stat Software 2007, 18: 1–24.

    Article  Google Scholar 

  41. 41.

    Liaw A, Wiener M: Classification and Regression by randomForest. R News 2002, 2: 18–22.

    Google Scholar 

  42. 42.

    Hothorn T, Leisch F, Zeileis A, Hornik K: The design and analysis of benchmark experiments. J Comp Graph Stat 2005, 14: 575–699.

    Article  Google Scholar 

  43. 43.

    Demsar J: Statistical comparisons of classifiers over multiple data sets. J Mach Learn Res 2006, 7: 1–30.

    Google Scholar 

Download references


BHM acknowledges support from the German Academy of Sciences Leopoldina through the Leopoldina Fellowship Programme (LPDS 2009-10). FAH acknowledges support by the German Research Foundation (DFG HA-4364).

Author information



Corresponding author

Correspondence to Fred A Hamprecht.

Additional information

Authors' contributions

BHM performed the design of the study and drafted the manuscript. FAH contributed significantly to the manuscript. RM, UH, PB, WP acquired data for the study. All authors participated in the analysis of the results. BHM, BMK, WP, FAH conceived of the study and participated in its coordination. All authors read and approved the final manuscript.

Authors’ original submitted files for images

Rights and permissions

Reprints and Permissions

About this article

Cite this article

Menze, B.H., Kelm, B.M., Masuch, R. et al. A comparison of random forest and its Gini importance with standard chemometric methods for the feature selection and classification of spectral data. BMC Bioinformatics 10, 213 (2009).

Download citation


  • Feature Selection
  • Partial Little Square
  • Random Forest
  • Bovine Spongiform Encephalopathy
  • Feature Selection Method