| |

Running a Classification Tree – Decision Tree – Data Analysis and Intrepretation

Overview

My research work deals with Ghana, a country from the Gapminder dataset as has already been discussed from the beginning and progression through this course.

Picture
Of My Final Decision Tree Outputted From My Python Program

image

 

The variables in my observation dataset
are all quantitative.

For the purposes of this assignment, I have binned my quantitative target variable, Life Expectancy (lifeexpectancy) into a 2-level binary categorical target variable. I have named this categorical target variable, lifeExpectancyCat. It has been coded as 0 = low life expectancy and 1 = high life expectancy

I have also binned all the other predictor variables categorical variables for the purpose of this assignment.

Thus these are the respective categorical end result variables of my quantitative predictor variables:

Quantitative           Binary Categorical variable

incomeperperson – incomeLevelGrp

inflation – inflationCatGrp

exports – exportsCatGrp

 

However, I have only used 2 of these variables, namely, incomeLevelGrp and exportsCatGrp predictor variables in classifying my tree.

Decision tree analysis was performed to test nonlinear relationships among my 2 explanatory variables and my binary, categorical response variable. All possible
separations (categorical) are tested.

From my decision, it first starts with a split on X[1] which is exportsCatGrp my
second explanatory variable.  If the value for exportsCatGrp is less than 0.5, that is low exports as my exportsCatGrp has values of 0 = low exports and 1 = high exports, then the observation moves to the left side of the split and includes 28 of the 30 observations in the training sample.

From this node another split is made on incomeLevelGrp which is X[0] so that I have periods with  low exports and high incomes and also periods with  low exports and low income levels.

From the resulting leaf that has periods with low exports and high incomes, which shown to the right of the split from X[0], 7 of the people of Ghana have High Life Expectancy and 7 also have Low Life Expectancy.

From the resulting leaf that has periods with low exports and low incomes, 8 of the people of Ghana have High Life Expectancy and 6 have Low Life Expectancy.

However, if the value for exportsCatGrp, X[1] is greater than 0.5 that is high exports, then the observation moves to the right hand side of the split and
includes 2 of the 30 observations in the training sample.

From this, a decision tree leaf is created and from this leaf, 0 person(s), that is no one, has High Life Expectancy rate and 2 people have Low Life Expectancy.

Hence from the decision tree classification, periods with low exports and low incomes are more likely to have High Life Expectancy than periods of high exports and high income levels. (which is rather surprising!)

Requesting the shape of my predictor training sample it can be seen that it has 30 observation or rows which represents 60% of our original sample and 2 explanatory variables as indicated above.

 

image

The test sample has 21 observation or rows which is 40% of
the original sample and 2 explanatory variables or columns

A Confusion Matrix was used to estimate the prediction accuracy of my model. From the results of the Confusion Matrix, the models accurately classified 15 of the total 21 observations included in my data set for the classification and misclassified 6 of the 21 observations included in the classification process. This means the model correctly classified 71% of the observations as having High Life
Expectancy or Low Life Expectancy and misclassified 29% of the observations in
my data set.

The Confusion Matrix result can be seen below:

 

image

 

This can be interpreted as the model having low prediction error as it correctly classified high percentage of the observations and misclassified low percentage of the observations in my dataset

This can further be seen by running a Test Accuracy score on
my model and the result was 0.7142857142857143 (71%) as can also be seen below:

 

image

################################

PYTHON CODE

#################################

 

################################

CODE OUTPUT

#################################

Want more information like this?

Similar Posts

  • |

    Running An Analysis of Variance (ANOVA) – Data Analysis Tools

    Chosen Dataset I will be working with Data from the Gapminder dataset. This happens to be the same dataset I worked with under the Data Management and Visualization course  assignments. As elaborated and discussed in under the Data Management and Visualization course  assignments, I have chosen to focus on the country, Ghana. Hence I will be particularly interested…

  • Python PyQt Gui Basics Button Window PyQt4 Pt1

    This is just some quick scrap notes on the basics of Python GUI building using PyQt. In [1]:

     

      the ‘init‘ statements runs anytime we call call the Window class we have created and it runs all the code in the Window class the _init__ method calls the super constructor and then sets…

  • Getting Stock Prices from Yahoo and plotting Python 3 Matplolib Urllib

    This is  some quick notes about getting stock data from Yahoo and plotting it using Matplotlib . The Python version used is Python 3.5 Credits to sentdex.  You can check him out on Youtube. In [11]:

      In [12]:

      In [13]:

      In [14]:

        Want more information like this?

  • | |

    Save Multiple Pandas DataFrames to One Single Excel Sheet Side by Side or Dowwards – XlsxWriter

      This tutorial is just to illustrate how to save Python Pandas dataframe into one excel work SHEET . You can save it column-wise, that is side by side or row-wise, that is downwards, one dataframe after the other.   In [110]:

      In [111]:

     

    In [112]:

      Out[112]: First Name Last Name…

  • Python Pandas Groupby function agg Series GroupbyObject

    Group By FunctionThis is a quick look at Python groupby function. Very powerful and useful function. We will take a simple look at it here. Credits to Data School , creator of Python course materials. lets import sample dataset In [18]:

      In [19]:

      In [20]:

      Out[20]: country beer_servings spirit_servings wine_servings total_litres_of_pure_alcohol continent…

  • Matplotlib Pyplot Plt Python Pandas Data Visualization Plotting

      This is some quick notes about graphing or plotting graphs with Matplotlib in Python. Credits to sentdex.  You can check him out on Youtube.

      In [4]:

      In [10]:

      In [14]:

      In [20]:

      In [23]:

      In [30]:

      Out[30]:

    In [48]:

        Want more information like this?

Leave a Reply

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