Decision Tree Regression using sklearn:

Decision tree is a decision making tool in python for data science that uses a flowchart or is a model of decisions and all the possible outcomes, including cost and utility.

The decision tree algorithm comes under a supervised learning algorithm. It works efficiently for both continuous and categorical output variables.

The results are reflected on the branches of the node, and the nodes will have either:

  1. Conditions or decision nodes
  2. Result or end nodes.

The branches represent truth or falsity of a statement, and it makes a decision which is based on it. The below example represents a decision tree that will evaluate the smallest of three numbers.

Decision Tree Regression using sklearn in Python for Data Science

Decision tree regression:

It observes the features of an object and then trains a model in the structure of a tree for predicting data in the future for producing meaningful continuous output. By continuous output we mean the result is not discrete.

Discrete output examples: We will make a model for the prediction of rain on a particular day.

Continuous output example: It is a profit prediction model which will state the probable profit that can be generated from the sale of a product.

In this, the continuous values are predicted with a decision tree regression model.

Now we will observe the Step by step implementation.

  • Step 1: Importing the required libraries.Decision Tree Regression using sklearn in Python for Data Science
  • Step 2: Initializing and printing the data set.
  • Decision Tree Regression using sklearn in Python for Data Science
  • Step3: Selecting all the rows and column 1 from the data set to “X”.Decision Tree Regression using sklearn in Python for Data Science
    Decision Tree Regression using sklearn in Python for Data Science
  • Step 4: Selecting all rows and column 2 from the data set of “y”.
  • Step5: Fitting the decision tree regressor to the data set.
  • Step 6: Prediction of a new value.
  • Step 7: Visualization of the result.
  • Step8: The tree is exported and shown n a tree structure below.
    OUTPUT:

So, to learn more about it in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.