# Decision Tree Regression

The following two tabs change content below.

#### Renuka Joshi

I am a technology enthusiast and always up for challenges. Recently I have started getting hands dirty in machine learning using python and aspiring to gather everything I can.

#### Latest posts by Renuka Joshi (see all)

We learned about support vector regression in previous article and now we will implement decision tree regression to predict salaries of employees at certain position.

# Decision Tree Regression

It splits dataset into sections  and calculates predictions from average values of data points in each section. So, prediction for all data points lying within one section will be same.

Here,

• We have used DecisionTreeRegressor class from sklearn.tree library
• regressor.fit will fit x and y to regressor object of DecisionTreeRegressor class

Execute above lines of code and you will see graph plotted as below

• We can notice the graph is not continuous.
• Prediction for 8.3 level is 170000.
• Horizontal lines are averages of all data points in sections created.
•  Predictions are averages of data point sections. So prediction for each value lying in one section will be the same.
• For example, note that horizontal lines start from halfway past any number and end just before halfway of next interval. In our case, horizontal lines are from 1.6 to 2.5, 2.6 to 3.5 and so on.
• These horizontal lines represent sections. If you predict value of all data points between 7.6 and 8.5, prediction will always be 170000 according to decision tree regression.

### Related Posts

#### Renuka Joshi

I am a technology enthusiast and always up for challenges. Recently I have started getting hands dirty in machine learning using python and aspiring to gather everything I can.

### 2 thoughts on “Decision Tree Regression”

• September 23, 2018 at 5:38 pm