5
$\begingroup$

I have targets ordered by a feature. I want to find a single split that minimizes a squared deviation (RMSE). For example, I have 100 values (targets) and it might be the case that, if I split them as 30 + 70, I get minimal squared deviation (as compared with all the other splits like 10+90 or 83+17). Here I assume that 30 targets "on the left" get one prediction (average of those 30 targets) and 70 targets on the right get another prediction (average over 70 values).

To test my split function, I have generated 100 values using a single normal distribution and for those values I found an optimal split given by its location (for example location 15 means 15 values on the left and 85 values on the right). When I do it many times I find that split locations are distributed non uniformly. For example very small locations (3, 4, 5) or very large locations (97, 98) are much more frequent than locations close to the middle (48, 50, 52). In other words, good RMSEs are more likely to be found for the splits close to the two edges of the whole interval.

So, it looks to me as an inherent undesirable bias of the method. In the case of no pattern in the data (no dependency on the feature, as in my test), I would expect splits to be distributed uniformly between 1 and 100. Otherwise, when I do have a dependency on the feature, mixed with large noise, I still would get close to the edges of the intervals and I do not want it.

By the way, my explanation of the effect is that root means squares deviations corresponding to the splits close to the edges are less correlated with each other and therefore the chances that we find minimal root mean square there is larger.

$\endgroup$
5
  • $\begingroup$ Are you asking for extra trees? Random forest which split randomly at each node? $\endgroup$ Commented May 17, 2022 at 12:06
  • $\begingroup$ No, I am asking about one single split. If there is no dependency of targets on a feature, the minimization of RMSE tend to split closer to the edges (for example 3 + 97, or 95 + 5). $\endgroup$
    – Roman
    Commented May 17, 2022 at 12:10
  • $\begingroup$ Did you randomly generate the features, the targets, or both ? $\endgroup$
    – J. Delaney
    Commented May 20, 2022 at 12:49
  • $\begingroup$ I have randomly generated targets using a normal distribution and, per construction, the targets we independent on features. $\endgroup$
    – Roman
    Commented May 20, 2022 at 13:10
  • $\begingroup$ Are you fitting a decision tree? How do you do this with 100 values? You only have a single variable? What is the objective function that this decision tree tries to optimize by fitting? What are the input features for this decision tree? $\endgroup$ Commented May 21, 2022 at 11:46

1 Answer 1

4
+250
$\begingroup$

One way to approach dataset splitting is as a model selection problem. Consider the following set of hypotheses :

$$ H_k : y_i \sim \begin{cases} \mathcal N(\mu_1,\sigma^2),& \text{if } i < k\\ \mathcal N(\mu_2,\sigma^2), & \text{if } i \ge k \end{cases}$$

Namely, the set of data points $y_i$ are assumed to belong to two populations with different (unknown) means. Now calculate the posterior probabilities of each hypothesis :

$$ P(y|H_k) = \int d \mu_1 P(y^{(1,k)} | \mu_1,\sigma) \pi(\mu_1) \times \int d \mu_2 P(y^{(2,k)} | \mu_2,\sigma) \pi(\mu_2)$$

where $y^{(1,k)} = \{y_i | i<k\}$ and $y^{(2,k)} = \{y_i | k \le i \le N\}$.

Assuming uniform priors for the unknown means, we have

$$\int d \mu_1 P(y^{(1,k)} | \mu_1,\sigma) = \frac{1}{(2\pi)^{k/2}\sigma^k}\int d \mu_1 \prod_{i=1}^k e^{-\frac{1}{2\sigma^2}(y_i-\mu_1)^2} \\ = \frac{1}{(2\pi)^{k/2}\sigma^k}\int d \mu_1 \exp\left({-\frac{1}{2\sigma^2} \sum_{i=1}^k(y_i-\mu_1)^2} \right) \\ = \frac{1}{(2\pi)^{k/2}\sigma^k}\int d \mu_1 \exp\left( -\frac{k}{2\sigma^2} (\mu_1 - \bar y^{(1,k)})^2 \right) \times \exp \left( -\frac{1}{2\sigma^2} \text{SSE}^{(1,k)}\right) \\ = \frac{\sqrt{2\pi}\sqrt{k}}{(2\pi)^{k/2}\sigma^{k-1} }\exp \left( -\frac{1}{2\sigma^2} \text{SSE}^{(1,k)}\right)$$

where

$$ \text{SSE}^{(1,k)} = \sum_{i=1}^k (y_i - \bar y^{(1,k)})^2 $$

is the sum of squared errors. Combined with a similar expression from the second integral we get

$$ P(y|H_k) \propto \sqrt{k(N-k)} \exp \left( -\frac{1}{2\sigma^2} \text{SSE}^{(k)}\right)$$

where $\text{SSE}^{(k)} = \text{SSE}^{(1,k)} + \text{SSE}^{(2,k)}$ is the total sum of squared errors. If we assign the same prior probability for each hypothesis then $P(H_k|y) \propto P(y|H_k)$, and if we take the $\log$ of the posterior probabilities we can see that

$$ -\sigma^2\log P(H_k | y ) = \frac{1}{2}\text{SSE}^{(k)} - \frac{\sigma^2}{2} \log k(N-k) + const.$$

So, the splitting which has the maximum a posteriori probability is the one that minimizes $\text{SSE}^{(k)} - \sigma^2\log k(N-k)$ . Note that the second term effectively penalizes small leaves.

Note that the model so far assumed that the variance $\sigma^2$ is known and common to both leaves. If $\sigma^2$ is not known we can use the sample estimate $\hat \sigma^2 = \frac{1}{N}SSE^{(k)}$, so the minimization objective becomes $\text{SSE}^{(k)}(1 - \frac{1}{N}\log k(N-k))$. (In principle if the variances are not known we should marginalize over them, similar to way we treated the unknown means, which might lead to slightly different results) .

To see the effect of choosing a splitting based on the posterior probabilities we can run a test similar to yours (here with $\sigma^2=1$ for simplicity) :


for n=1:10000
  y = randn(100,1) ;
  for k=1:99
    SSE(k) = k*var(y(1:k),1) + (100-k)*var(y(k+1:end),1) ;
    logP(k) = SSE(k) - log(k*(100-k)) ;
  end
[~,loc1(n)] = min(SSE) ; %location that minimizes SSE
[~,loc2(n)] = min(logP) ; %location that minimizes posterior probability
end
figure, histogram(loc1,50)

Splitting that minimizes $SSE$ : enter image description here

figure, histogram(loc2,50)

Splitting that maximizes $P(H_k|y)$ :

enter image description here

This is indeed distributed uniformly as we would expect.

$\endgroup$
4
  • $\begingroup$ Thank you for your answer. It definitely goes in the direction I need. What I cannot understand, is why you integrate over mus (averages). I guess by integration you answer the following question: What is the probability that the split is at this point given that "left" and "right" averages are distributed homogeneously from minus infinity to plus infinity. Do we answer this question and, if it the case, why do we want to answer this question? $\endgroup$
    – Roman
    Commented May 23, 2022 at 9:53
  • $\begingroup$ Maybe I can reformulate my question as the follows. Why can't we just search for a model that given the largest likelihood for the observed data set. Such a model will be given by 2 averages ($\mu_1$ and $\mu_2$) and by a position of the split ($k$). Should expect in this case that the location of the split will be distributed homogeneously if there is not pattern in the data? $\endgroup$
    – Roman
    Commented May 23, 2022 at 10:02
  • $\begingroup$ From a Bayesian point of view the problem with the MLE is that it does not necessarily represent the bulk of the posterior probability. (Imagine for example an exponential distribution, where the "most likely" value is always at zero, but the mean can be arbitrarily large). This is why Bayesian calculations involve integrating over the unknown parameters, which has a precise probabilistic meaning. For an introduction see for example Bayesian model selection and model averaging $\endgroup$
    – J. Delaney
    Commented May 23, 2022 at 10:45
  • $\begingroup$ @J.Delaney I am at some loss in your derivations. Could you please help me out? In the place where you are doing the main 4-line derivation in the last step (where you get rid of the integral), shouldn't the square root of "k" be in the denominator? $\endgroup$
    – NickQuant
    Commented Dec 16, 2022 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.