What is Decision Tree Regression?

Manik Soni
4 min readSep 26, 2020

--

Decision Tree Regression helps to break down a dataset into smaller subsets which helps to do the prediction and give results more precisely for non-linear distribution of the dataset.

Let's take an example of a sample data set :

So you can see our linear models like simple, multiple, or polynomial regression models unable to do accurate predictions. So here Decision Tree Regression comes into play which helps us to model the dataset and give an accurate prediction.

See the outcome of the above scatter plot before we understand the individual part deeply.

We can see in the above plot how the dataset is categorized. So now we do a deep analysis of this algorithm.

So as per Decision Tree Regression, the algorithm categorizes the first part of the split, that is, values having a number than 20 or greater than 20.

So we develop a tree for a better understanding of the concept.

Now, again doing the split on the y-axis having a number smaller than 170 or greater than 170.

Now in a similar fashion, the machine is doing the split and for our understanding tree visualization is done.

Now, our splits have done, and in order to give the predicted result, we can visualize it in 3D.

Now we are calculating the average of all points with a particular region.

Now you can see how prediction happens in Decision Tree Regression. So, we are doing the practical implementation, we are importing the dataset of people having a position salary.

Now follow the steps to do Prediction:

Step 1: Import the Libraries

Import Libraries

Step 2. Importing the Dataset

Import Dataset

Step 3. Split the data into a matrix of features(X) and the dependent variable(y).

X and y splitting

Step 4. Fitting a linear model to test and training dataset.

Fitting the linear model

Step 5. Predicting the Test result.

Predict the model

Step 6. Visualization of the dataset.

--

--