# Standardizing inputs for CART

I know I do not need to standardize the predictor variables before applying CART but would there be any adverse effects to doing it anyway? I'm comparing CART to a linear regression where I did standardize the inputs and for the sake of consistency I'd like to do the same for CART, but could it be detrimental to my results? I'm not really sure how CART goes about finding the splitting point at each node (I can't find a copy of the original paper and most of what I've read just skips over that detail) but I would think that standardizing the inputs would actually help speed up that process. Does anyone have any intuition in this regard?

• So long as you are doing "intercept only" regressions at each terminal node, the difference can only be in numerical calculations, or possibly in some of the arbitrary implementation specific choices - such as which variable to try first. Although, it could be important to standardise "within replicates" if you are using cross validation or bootstrapping with CART. Apr 24, 2014 at 9:38
• Trees are invariant to any monotonic tranformation of predictors, including standardisation. See this very closely related thread stats.stackexchange.com/questions/51523/…
– Momo
Apr 24, 2014 at 9:38

My answer at this stage is based on my intuitive understanding of how CART works, so take it face value.

Standardization does not add or subtract information contained in a given variable and does not distort its relationship to a target variable. For example, if you had a variable "age" which was a predictor for "purchase car". By changing age to (age - mean / sd ) is not going to change its relationship to purchase car, it merely maps it to a new space.

When CART looks for the best splits, it going to use entropy or gini to calculate information gain, this is not dependent on the scale of your predictor variable, rather on the resultant purity of the variable "purchase car".

So long story cut short, standardization should have no influence on your final solution. To verify this, simply run your model twice. Once on the standardized version of data and once with the original. If all goes well, you should see the same variables and order of selection, just different cut off points.

Edit: I've appended two images for your reference for a tree with and without standardized inputs.

• But the different scales might affect the route the optimization algorithm takes to find the splits... it could affect convergence which could then lead to different trees. The problem with your test is that even without standardizing, you don't always get the same tree when running twice on the same data (at least not in the Matlab implementation) so you'd actually have to run it many times on each and do some stats tests to check for equivalence.
– Dan
Apr 24, 2014 at 6:28
• For classification it really does not matter. For numerical variable the only important thing is the order which is preserved after standardization. For regression I managed to demonstrate something, but not enough. Note that the question is about regression (since it is compared with linear regression), and in the regression setup info gain or other impurity functions are not used. Apr 24, 2014 at 6:45
• @Dan As far as I see it, the problem should be considered without additional random induced (which might be the case for mathlab, is for sure in R) in order to optimize computation time. Apr 24, 2014 at 6:47
• @ArunJose Your tree uses a single predictor variable? It looks like this. I managed to show that after scaling the best split for the same variable, scaled and unscaled is the same. The question is how scaling affects the interactions between variables. I still consider that not a proof. And again, impurity functions like gini and brothers are not used in regression trees. Apr 24, 2014 at 7:33
• I just re-ran this with more than one predictor variable and had same results as well. Will append them if you need. Apr 24, 2014 at 7:39

I will try to give a formal proof here to clarify things.

Step 1

We denote with $x = {x_1, x_2, .., x_n}$ a vector, and with $var(x)=\frac{1}{n}\sum_{i=1}^{n}(x_i-\frac{1}{n}\sum_{j=1}^{n}x_j)^2$ the biased sample variance. We denote with $y = \frac{x-m}{sd}$ the scaled version.

We work out a formula for $var(y)$ in terms of $var(x),m,sd$.

$$var(y)=\frac{1}{n}\sum_{i=1}^{n}(y_i-\frac{1}{n}\sum_{j=1}^{n}y_j)^2 = \frac{1}{n}\sum_{i=1}^{n}(\frac{x_i-m}{sd}-\frac{1}{n}\sum_{j=1}^{n}\frac{x_j-m}{sd})^2$$ $$= \frac{1}{n sd^2}\sum_{i=1}^{n}(x_i-m-\frac{1}{n}\sum_{j=1}^{n}(x_j-m))^2$$ $$= \frac{1}{n sd^2}\sum_{i=1}^{n}(x_i-m-\frac{1}{n}\sum_{j=1}^{n}x_j+\frac{1}{n}\sum_{j=1}^{n}m)^2$$ $$= \frac{1}{n sd^2}\sum_{i=1}^{n}(x_i-m-\frac{1}{n}\sum_{j=1}^{n}x_j+m)^2 = \frac{1}{n sd^2}\sum_{i=1}^{n}(x_i-\frac{1}{n}\sum_{j=1}^{n}x_j)^2$$ $$= \frac{1}{sd^2}var(x)$$ So we know that the variance of the scaled version is proportional with the variance of the unscaled version. $$var(y)=\frac{1}{sd^2}var(x)$$

Step 2

For CART regression we know that the split test is evaluated with a formula like $var(x_{left})+var(x_{right})$, where $x_{left}$ consists of all observation values of the target variable which are less than or equal some threshold value on the test variable.

In order to show that various tests preserves the same order after scaling I think there is enough to say something like:

For any given two binary splits of the values of the target variables, if the evaluation function for the first split is less than the evaluation function for the second split on the unscaled variable implies that the evaluation function for the first split is less than evaluation function for the second split on scaled variable.

In plain English comparison between splits is the same for scaled and unscaled variables.

Demonstration is trivial since the evaluation function is $split(x_{left},x_{x_right})=var(x_{left})+var(x_{right})$, and we know that variance for unscaled version is proportional with variance for scaled version and this property is preserved on addition.