2
$\begingroup$

Could you explain how to perform decision tree regression? How is it different from decision tree classification?

$\endgroup$
1
  • $\begingroup$ Classification tends to use a "right or wrong" loss function. Regression allows a "how wrong"-based loss function. $\endgroup$
    – Henry
    Commented Jun 29, 2021 at 9:40

2 Answers 2

2
$\begingroup$

In both cases, the algorithm works pretty much the same with some small differences. One of the differences is the loss function. Another difference is how they make predictions. For classification, a decision tree may do a majority vote, by predicting for a node of the tree the class of most of the training samples in this node. Using the example from the scikit-learn documentation (below), the leftmost final node had [0, 47, 0] training samples in the node, so the majority of the samples came from the second class. Another thing a classification decision tree can do is to calculate the probability, i.e. [0, 1, 0] for the example since all the samples ended in the middle class.

Example of a DecissionTreeClassifier tree for the Iris data from the scikit-learn documentation.

The regression tree would instead calculate something like the mean of the target variable for the samples in the node. If you used the regression tree for classification data, this would mean predicting the probabilities, the same as the classification tree would do (but not exactly the same as would be predicted by a classification tree). This is how the classification and regression algorithms are nearly the same.

If you plot the results predicted by a regression tree, you would see jumps, the predictions would be a step function (see another example from the scikit-learn documentation below). You can see from the plot that the decision tree had a node for the data values (x-axis) between 0.5 and 1.5, for which the mean of the target variable (y-axis) was around 0.9 and this is the prediction that it returned for the node.

Example of DecissionTreeRegressor predictions on 2D plot, showing the data on x-axis and predictions on y-axis. The data used is a noisy sin function. The predictions are step functions.

You can notice the obvious problem with using a regression tree, that it cannot extrapolate outside the data. In the example below, if you asked it to predict for data values higher than 5, it would return the last seen value of around -1.

$\endgroup$
6
  • $\begingroup$ what is the impurity metric used in each node in the case of decision tree regression? $\endgroup$
    – AI_Revolt
    Commented Jul 4, 2021 at 7:33
  • $\begingroup$ @AI_Revolt they use mean squared error or mean absolute error, as mentioned in the first link, not impurity score. $\endgroup$
    – Tim
    Commented Jul 4, 2021 at 8:09
  • $\begingroup$ Could you provide links to references where we use MSE or MAE as impurity metric like we use gini index or entropy in the case of classification? $\endgroup$
    – AI_Revolt
    Commented Jul 4, 2021 at 8:43
  • $\begingroup$ @AI_Revolt not as a impurity metric but as a loss. This is covered in any machine learning handbook that mentions regression trees, e.g. this one web.stanford.edu/~hastie/ElemStatLearn $\endgroup$
    – Tim
    Commented Jul 4, 2021 at 9:16
  • $\begingroup$ Could you brief how feature importance scores are computed using MSE? $\endgroup$
    – AI_Revolt
    Commented Jul 8, 2021 at 11:19
2
$\begingroup$

The main difference between classification and regression trees is that the target attribute (i.e. the variable you want to predict) of the classification tree is a continuous variable, while the target attribute of the decision tree is a categorical variable.

The main idea behind both is the same though.

For classifications, the metric used in the splitting process is an impurity index (e.g. Gini index) whilst for the regression tree, it is the Mean Squared Error.

$\endgroup$
2
  • 1
    $\begingroup$ Could you brief how feature importance scores are computed using MSE? $\endgroup$
    – AI_Revolt
    Commented Jul 8, 2021 at 11:18
  • $\begingroup$ Good question. I am not an expert of what's happening under the hood but maybe you can find answers at this post $\endgroup$
    – FrsLry
    Commented Jul 8, 2021 at 12:48

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.