isotree
(Python, R, C++) Extended Isolation Forest, Fair-Cut Forest, SCiForest, with some additions (outlier detection + NA imputation + similarity)
view repo
This work proposes a non-iterative strategy for missing value imputations which is guided by similarity between observations, but instead of explicitly determining distances or nearest neighbors, it assigns observations to overlapping buckets through recursive semi-random hyperplane cuts, in which weighted averages are determined as imputations for each variable. The quality of these imputations is oftentimes not as good as that of chained equations, but the proposed technique is much faster, non-iterative, can make imputations on new data without re-calculating anything, and scales easily to large and high-dimensional datasets, providing a significant boost over simple mean/median imputation in regression and classification metrics with imputed values when other methods are not feasible.
READ FULL TEXT VIEW PDF
Techniques such as clusterization, neural networks and decision making
u...
read it
Modern data acquisition based on high-throughput technology is often fac...
read it
Often in real-world datasets, especially in high dimensional data, some
...
read it
Despite the large body of research on missing value distributions and
im...
read it
The processing of data which contain missing values is a complicated and...
read it
The weighted k-nearest neighbors algorithm is one of the most fundamenta...
read it
(Python, R, C++) Extended Isolation Forest, Fair-Cut Forest, SCiForest, with some additions (outlier detection + NA imputation + similarity)
When designing statistical models from tabular data for supervised learning tasks such as regression or classification, oftentimes it happens that some of the observations available for fitting such models are missing values in one or more variables, usually due to reasons such as poor data collection practices, loss of information, participants dropping out of a survey, or similar. Many methods such as
[2] or [4]overcome this issue by using heuristics to handle missing information – decision tree methods in particular, due to their splitting nature that takes one variable at a time, are particularly well suited for implicit handling of missing data without a-priori imputation (
[16]), but other methods such as generalized linear models or support vector machines cannot handle missing values in the same way, and when using them on a dataset with missing entries, these entries have to either be dropped or imputed.
Typical strategies for imputing the missing entries include: replacing them with the column mean or median, determining the most similar observations (nearest neighbors) according to the non-missing variables and taking a simple or weighted average of the missing variable(s) from them ([11]), producing a latent representation of the data by some low-rank matrix factorization that minimizes errors on the non-missing entries and from which the missing entries are then reconstructed ([10]), and iterative imputation that starts with some basic imputation for all values and then cycles through each variable by constructing a model to predict the missing values from the non-missing observations, replacing the earlier imputation with the model prediction and repeating until convergence ([3], [18]).
This work proposes a strategy for imputation of missing values in data based on unsupervised decision trees similar to the Isolation Forest ([13]) algorithm or to Random Tree Embeddings^{1}^{1}1https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomTreesEmbedding.html, which as opposed to common decision tree algorithms such as C5.0 ([17]) or CART ([2]), do not aim at predicting one variable from a set of other variables, but rather aim at grouping observations according to random criteria.
The general idea is to construct multiple and independent binary trees by recursively splitting the data according to some condition, with each terminal node in a tree producing imputations for every variable according to the non-missing observations that end in that node. At prediction time, observations are passed down these trees until reaching a terminal node, from which the imputations are taken and averaged across the terminal nodes reached in each tree. The data is split through hyperplane cuts similar to [14], but using a pooled information gain criterion like in [2] instead, which results in improved imputations compared to averaged gain and fully-random cuts. Missing values are temporarily median-imputed at each non-terminal node in order to continue passing observations down the tree, but these imputations are not used for the final calculations.
The Isolation Forest algorithm ([13]
) – initially proposed for outlier detection – explored the idea of producing decision trees that split (assign to different branches of a binary tree node) a set of multi-dimensional points/observations according to whether they are greater or smaller than a threshold chosen uniformly at random within the range of a randomly-determined variable/feature, continuing the process recursively on the subset of observations that fall into each branch until observations/points become isolated (put alone in one branch), following the logic that outlier observations will become isolated with fewer splits than expected. Under an alternative view, this same procedure manages to group observations that are closer in the feature space according to the variables that were chosen, with nodes further down the tree grouping together observations that are more and more similar, and outliers alternatively being interpreted as the ones that are dissimilar from all other observations – a scaled version of the (negative) average depth at which two observations are separated can be shown to constitute a distance metric with many desirable properties as analyzed in
[6].As such, when building a random tree like this, the nearest neighbors of an observation are more likely to be those that end in the same terminal node if there is a pre-determined height limit, or those with which a larger number of ancestors is shared. The random tree procedure, however, at no point implies explicitly computing pairwise distances or even defining a distance metric – the splitting logic of random trees, when averaged across multiple runs, will implicitly put together similar observations more often according to the sample data distribution, being invariant to the scales of variables and taking complex relationships between variables into account (see [6]). It is also a computationally efficient procedure in large and/or high-dimensional datasets as the procedure scales only linearly with the sample size, depth, and number of trees () when growing the trees, and only linearly with the number of trees and their depth when passing observations down the tree ().
There are some logical improvements that can make this random tree procedure better at grouping similar observations (and isolating outliers faster in the process). As shown in [8], splitting by only one variable at a time introduces some biases which can be overcomed by using hyperplane cuts instead – that is, the split criterion is based on a threshold set on a linear combination of randomly-chosen variables instead of a threshold on a single variable’s value at a time.
The uniformly-random threshold can also be changed to a guided threshold as proposed in [14]
, by trying to minimize the standard deviations of the obtained linear combination when calculated on the observations within each branch (
), which manages to isolate clustered minority observations faster. This concept is similar to the information gain criterion used by supervised decision tree algorithms such as CART or C5.0, but with the target variable being split according to a threshold on itself instead of being split according to some other variable.If the objective is to group similar observations instead of separating clustered outliers, it makes more sense to maximize a weighted or pooled average for the gain criterion that could take into account the number of observations that are being assigned to each branch (), in the same way as CART
for example. A pooled gain-maximizing split criterion, when applied on the same variable being split, tends to favor more “even” or “fair” splits – for example, a symmetric distribution would get split in half for each branch, and a gamma distribution would get the long tail assigned to a branch, whereas an averaged gain criterion will put the maximum or minimum valued observation alone in one branch. This produces a more fair split, in the sense that it will prefer a half-each division unless there is some reasonable cluster(s) with reasonable size that could be assigned to a branch as minority. As well, the criterion has a natural threshold that can tell if the groups are being made more homogeneous: if the gain is negative, then the split is not making the observations under each branch more similar to each other, and this threshold can be increased if desired. There is unfortunately no fast way of determining the linear combination that would have the split point with the highest gain, so different linear combinations can be tried and only the best (highest-gain) among them taken, as proposed in
[14].An obvious shortcoming of this procedure is that it doesn’t handle missing values, and missing values cannot be handled by assigning a whole observation to both branches simultaneously with decreased weights on them, since there is more than one variable deciding the split and there could be missing values in multiple variables or even no complete observations. An alternative for handling missing values is to resort to mean or median imputation – if these are re-calculated at each tree node, then their quality should get better as the depth increases.
The logic can also be extended to handle categorical variables by assigning a random coefficient in the linear combination for each possible category, thereby mixing them into the gain calculation along with the numeric variables. If the numeric variables are standardized, and the coefficients for numeric columns and categorical values are both drawn from e.g. a standard normal distribution, then the variance in numeric variables will tend to be higher, which is perhaps preferable in many situations, whereas a wider range of possible coefficients for categorical values (e.g. the product of two draws from a normal distribution) would make them more comparable.
The procedure, named hereafter as FairCutTree, is illustrated below – the steps are the same as the iTreeExtEnh proposed in [6], but with the addition of the gain criterion.
(For a software implementation of the procedure, an equivalent but more numerically-stable formulation might center the variables beforehand by subtracting their mean, setting the threshold on a linear combination of the standardized values instead)
Using the notion that the FairCutTree is grouping together more similar observations with each split, potential imputation values could be determined at every node in the tree according to the observations that reach that node and which have no missing values, or according to observations that were separated the least splits ago if some variable has only-missing observations. Intuitively, the further down the tree (away from the root) a node is, the higher the impact it should have in an imputation (e.g. if an observation is isolated at the first split, new observations falling into that same node are potentially not too similar to that observation), and the fewer observations there are in a deep node, the more likely it is that they are nearest neighbors.
This work suggests a weighted-average imputation that looks only at the terminal node in which an observation falls under each tree in an ensemble of FairCutTrees (hereafter FairCutForest
), and weights the imputations of these terminal nodes according to their depth and the number of observations they had at training (tree growing) time. In order to have more reasonable results, the trees need not be grown to full-depth (this is similar to setting the number of neighbors in kNN). There is also no necessity for sub-sampling or bootstrapping the sample observations from which a tree is grown.
The procedure for determining imputation values from an ensemble (forest) of FairCutTrees is outlined below:
The recommended hyperparameters are
, , , , , . Increasing translates into a small increase in the quality of the imputations, while the optimal and varies in each dataset. Weighting the number of observations differently in the imputation (e.g. not using the number of observations in a terminal node) sometimes also results in improved results, especially when is low. For faster imputation times, and can be reduced, and the trees can be fit to sub-sampled data.Notice however that this imputation technique, just like kNN or similar methods, does not take into account patterns of non-randomly-missing variables (e.g. censored data), nor does it enforce constraints such as some variable being calculated deterministically from other variables (e.g. ), or some variable only allowed to take certain values according to a different variable (e.g. ”pregnant” and ”gender”).
The FairCutForest
imputation method proposed here (the implementation used is made open source and freely available
^{2}^{2}2https://www.github.com/david-cortes/isotree) was compared against simple median imputation, kNN imputation from the software library SciKit-Learn ([15]), matrix factorization from software library ”cmfrec” ([5]), and chained equations (hereafter referred to interchangeably as ”iterative imputation”) from the software libraries ”missForest” ([18]), ”mice” ([3]), and SciKit-Learn, using datasets of different sizes and characteristics from which some values were set randomly as missing, or which originally came with many missing values. The imputed data was then given as input to regression and classification algorithms which included linear and logistic regression from SciKit-Learn, random forest (
[1]) from software ”randomForest” ([12]), and gradient-boosted decision trees from software ”XGBoost” (
[4]) and ”CatBoost” ([7]). Evaluation metrics were calculated using k-fold cross-validation, and the timing was calculated for a single run in the full data for both imputation-model fitting and producing imputations from the model on new data (which in this case was the same training data). The benchmarks, depending on the dataset, were run either on a 3.2GHz AMD Ryzen 2700 processor with 8 cores, or on a 2.0GHz Intel Xeon Knight’s Landing processor with 64 virtual CPUs from Google Cloud Platform. All timings make use of the full available number of threads, and all methods are used with their default hyperparameters in each software, except for the method proposed here.
For FairCutForest, three combinations of hyperparameters were compared:
”Large”, with the previously recommended hyperparameters (, , , , , ).
”Mid”, with fewer and shallower trees (same depth recommended for outlier detection), evaluating fewer splits (, , , , , ).
”Small”, with mostly the same hyperparameters as ”Mid” but growing the trees with sub-samples of 5,000 points each instead of taking the full data, and using a maximum depth that reflects the reduced sample size ().
This regression dataset^{3}^{3}3https://scikit-learn.org/stable/modules/generated/sklearn.datasets.fetch_california_housing.html (20,640 rows, 8 columns) contains basic geographic and demographic information about districts in California (all of them numeric columns), with the suggested target variable being the median house value in the district.
Given the low dimensionality and the type of variables, this is the kind of problem in which iterative imputation is most appropriate and in which it tends to outperform other methods. Another reasonable alternative here is kNN, but making predicions on new data from it is too slow for a real-time system.
In order to evaluate imputation quality, some of the entries were set randomly as missing across rows/columns, and a situation in which every row has 1 missing column (at random) was also evaluated. Another scenario in which only 10% of the rows were used was also simulated in order to have a better idea of what happens when the problem size varies.
The evaluation metric used was root mean squared error (RMSE), which is evaluated through 10-fold cross-validation. The timings are measured on a 2.0GHz Intel Xeon Knight’s Landing processor with 64 virtual CPUs from Google Cloud Platform.
No feature engineering or filtering of rows was performed, but for kNN, the variables were standardized by subtracting their mean and dividing them by their standard deviation.
This classification dataset^{4}^{4}4https://archive.ics.uci.edu/ml/datasets/covertype
(581,012 rows, 54 columns, 7 classes) contains a mixture of numeric and binary variables about cartographic measurements and properties of soil plots, with the target variable of interest being forest cover type, and missing values introduced in the same way as for the previous dataset.
Iterative imputation and kNN do not scale well to these problem scales, so the data was sub-sampled by taking only 10% of the observations, with an additional test taking only 1% of the observations, and kNN was not evaluated for cross-validation metrics due to the long times it takes. While most of the columns are binary, these were treated as numeric for imputation purposes due to limitations of the software and methods being compared against, without any post-processing of these imputations. The linear regression used here for imputations uses regularization on its coefficients.
The classifiers used multinomial loss minimization as objective, and the metric evaluated was classification accuracy. This can however be a rather variable metric despite the large number of observations, with the imputed data some times producing higher accuracy than the full data with no missing values. Some basic feature transformations such as standardizing variables can easily increase test set accuracy for logistic regression, but this work only evaluated methods with the data as-is.
This dataset^{5}^{5}5https://archive.ics.uci.edu/ml/datasets/Thyroid+Disease
(3,163 observations, 26 columns) contains a mixture of numeric, boolean, and categorical columns, but unlike the previous ones, the missing values are not simulated as the data already comes with missing values, with some variables being non-randomly missing - for example, it contains columns ”sex” and ”pregnant”, with all males having missing values for ”pregnant”. As it contains mixed-type columns, not all benchmarked software is able to produce imputations or to use the categorical columns as categorical (e.g. SciKit-Learn requires dummy or one-hot encoding), so the choice of comparisons here was different. Software such as ”missForest” and ”mice” cannot produce imputations on new data from an already-fitted model, so the timing in this case was for the whole imputation-model fitting and reconstruction of missing values combined.
For FairCutForest, categorical and boolean variables were imputed by following the logic of assigning a random coefficient to each category in such columns, which was drawn from the same standard normal distribution as the coefficients for numeric columns, and categorical imputations decided by proportion of observations in each node having each possible categorical value, with the final imputation decided according to the one presenting the highest weighted proportion.
The suggested target variable for this dataset is ”hypothyroid”, but this is a rather uninteresting variable to analyze as most models would achieve AUC - instead, the data was used for regression by trying to predict ”age” among the observations that were not missing it (2,717). Linear models with no feature engineering were not benchmarked for this dataset due to presenting performance too far below tree-based regressors. Models were evaluated by 10-fold cross-validation, with the missing values imputed beforehand for all data (including those without age) instead of building an imputation model with the training data of each fold. These imputations made use of the target variable itself.
Using the extra observations with missing age (the target variable) for imputing other variables managed to significantly improve performance for the FairCutForest model with certain combinations of hyperparameters, which was not the case for ”missForest” and ”mice”. It should be remarked that it is not a problem to use the target variable for imputations on new data with FairCutForest, since it does not need to be known for the imputation model to work.
This is a different problem from previous ones - the data consists of movie rating triplets User-Item-Rating (944 users/rows, 1683 items/columns, 100k ratings - see [9] for details), with most entries being missing (93.7%), and the objective is to rank the missing entries for each user so as to recommend movies according to their predicted rating.
The most common evaluation metric for this problem is RMSE in a hold-out sample of triplets (an approach popularized by the Netflix Prize competition), which however is very sensitive to differences that do not change the induced ranking of predictions, so pearson correlation was also measured (it should be noted that this is not a ranking metric either, and is not measured on a per-user basis). Typical regression techniques are not suitable for this problem, but this is where matrix factorization outperforms other approaches. An iterative imputation method would be computationally infeasible for a dataset with these dimensions.
The parameters used for FairCutForest were , , , , . The test set consisted of the last ratings in the data rather than k-folds (it’s more realistic to predict future behavior based on past behavior), which after discarding users and items that were not in the training set, was reduced to triplets. The timings for matrix factorization use sparse matrices, while the timings for FairCutForest use dense matrices. The imputation timing in the case of matrix factorization is only for the test set triplets, while for FairCutForest includes whole-row imputations.
While the quality of the recommendations from the method proposed here lags behind that from specialized recommender system techniques, it does at least manage to surpass non-personalized recommendations.
This work proposed a missing-value imputation algorithm (FairCutForest imputation) which is based on similarity according to unsupervised semi-random hyperplane splits. The quality of these imputations was evaluated by measuring regression and classification metrics with models fitted to imputed data from both randomly and non-randomly missing entries.
The method was compared against other imputation strategies and was found to decrease loss metrics for regression and classification with missing data when compared against simple median/mode imputations, in some situations also managing to decrease loss metrics further than kNN and iterative imputation, but is usually behind iterative methods that couple low-bias algorithms for imputation.
The FairCutForest imputation was on the other hand found to be much faster and able to scale to very high-dimensional datasets in which kNN and iterative imputation methods are not computationally feasible, offering a reasonable alternative for low-latency systems and for large and/or high-dimensional datasets.
This work proposed a missing-value imputation algorithm (FairCutForest imputation) which is based on similarity according to unsupervised semi-random hyperplane splits. The quality of these imputations was evaluated by measuring regression and classification metrics with models fitted to imputed data from both randomly and non-randomly missing entries.
The method was compared against other imputation strategies and was found to decrease loss metrics for regression and classification with missing data when compared against simple median/mode imputations, in some situations also managing to decrease loss metrics further than kNN and iterative imputation, but is usually behind iterative methods that couple low-bias algorithms for imputation.
The FairCutForest imputation was on the other hand found to be much faster and able to scale to very high-dimensional datasets in which kNN and iterative imputation methods are not computationally feasible, offering a reasonable alternative for low-latency systems and for large and/or high-dimensional datasets.
Comments
There are no comments yet.