| |

Running a Random Forest – 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.

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 2 of the other predictor categorical variables (incomeperperson and exports) 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

exports – exportsCatGrp

I have also added 2 more explanatory variables which is obtained
from the Gapminder website: http://www.gapminder.org/data/

to my list of variables which are used for this assignment. This is to get more explanatory variables for this Random Forest Assignment.

These new variables are:

agriculture which represents Agriculture, value added (% of GDP)

democracyscore which represents Overall polity score from the Polity IV dataset, calculated by subtracting an autocracy score from a democracy score. It is a summary measure of a country’s democratic and free nature. -10 is the lowest value, 10 the highest.

Running a Random Forest

Random forest analysis was performed to evaluate the
importance of a series of explanatory variables in predicting my binary,
categorical response variable – . The following explanatory variables were
included as possible contributors to a random forest evaluating;

income per person, exports, inflation, agriculture, and democracy score

The explanatory variable with the highest relative importance
scores was agriculture which has relative importance score of 0.4005748 followed by democracy score with a score of 0.35894682, followed by inflation with a relative importance score of 0.12744075. Then comes exports
with a score of 0.05900944. The explanatory variable with the lowest relative
importance score is income per person with a relative importance score of 0.05402819

 

Relative Importance Scores

image

 

The accuracy of the random forest was 95% (0.94999999999999996),
with the subsequent growing of multiple trees rather than a single tree, adding
little to the overall accuracy of the model, and suggesting that interpretation
of a single decision tree may be appropriate.

 

Random Forest Graph

image

 

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 5 explanatory variables as indicated above.

image

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

image

A Confusion Matrix was used to estimate the prediction
accuracy of my model. From the results of the Confusion Matrix, the models
accurately classified 19 of the total 20 observations included in my data set
for the classification and misclassified just 1 of the 20 observations included
in the classification process. This means the model correctly classified 95% of
the observations as having High Life Expectancy or Low Life Expectancy and
misclassified 5% 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.94999999999999996 (95%) as can also be seen below:

image

 

 

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

PYTHON
CODE

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

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

CODE
OUTPUT

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

Want more information like this?

Similar Posts

  • |

    R Shiny App for Mining Fields Evaluation

    Presenting your report in an interactive and user-friendly way is a very effective communicative tool which can help you convey message to your audience easily. R is a very powerful analytic tool which helps you to do that with the “shiny” package. Here, I simply look at an app about the Mining Fields Evaluation which was…

  • |

    Quick Link to Connect to Google Analytics Developer API

    Hi Guys, My mentor and Godfather in IT,  Terry,  showed me a simple and quick link to connect to Google Analytics API.  Hope you also find it useful. Link is as below: https://ga-dev-tools.appspot.com/query-explorer/   To connect to your Google Analytics, Simply click on the link : https://ga-dev-tools.appspot.com/query-explorer/ Enter your login details for your Google Analytics account…

  • Simple Python Logging Callling Reload to Help Save Logging to File

      In this notes, we are looking at a simple but yet useful and powerful logging in Python In [77]:

      In [78]:

      In [79]:

     

      Want more information like this?

  • | |

    Various Types of Basic Charts For Data Analysis and Exploration – Visualization and Meaning

    Sometimes, you need some charts to explore your data and many times when your analysis is done and you want to report, you would most likely want to convey your message using charts and graphs. This is a quick look at some charts which are available and their names: We use this raw data in…

  • 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?

  • |

    DataSets Around the Web For Big Data, Machine Learning and DataScience Practices

    Here is a collection of several DataSet repositories, I have come across the web. ( I will adding more along the way) You can add to this by commenting on the post and I will update it in the this list Google Dataset Search : This is a great tool released by Google to help…

Leave a Reply

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