Taking Decisions Based on Data – Titanic Example
The growing demand for data is a key challenge. Decision support teams such as institutional research and business intelligence often cannot take the right decisions on how to expand their business and research outcomes from a huge collection of data. Although data plays an important role in driving the decision, however, in reality, taking the right decision at right time is the goal.
In other words, the goal is the decision support, not the data support. This can be achieved through an advanced use of data management and analytics.
Data Value Chain for Making Decisions
The following diagram in figure 1 (source: H. Gilbert Miller and Peter Mork, From Data to Decisions: A Value Chain for Big Data, Proc. Of IT Professional, Volume: 15, Issue: 1, Jan.-Feb. 2013, DOI: 10.1109/MITP.2013.11) shows the data chain towards taking actual decisions–that is, the goal. The value chains start through the data discovery stage consisting of several steps such as data collection and annotating data preparation, and then organizing them in a logical order having the desired flow. Then comes the data integration for establishing a common data representation of the data. Since the target is to take the right decision, for future reference having the appropriate provenance of the data–that is, where it comes from, is important:
Well, now your data is somehow integrated into a presentable format, it's time for the data exploration stage, which consists of several steps such as analyzing the integrated data and visualization before taking the actions to take on the basis of the interpreted results.
However, is this enough before taking the right decision? Probably not! The reason is that it lacks enough analytics, which eventually helps to take the decision with an actionable insight. Predictive analytics comes in here to fill the gap between. Now let's see an example of how in the following section.
From Disaster to Decision – Titanic Survival Example
Here is the challenge, Titanic–Machine Learning from Disaster from Kaggle (https://www.kaggle.com/c/titanic):
"The sinking of the RMS Titanic is one of the most infamous shipwrecks in history. On April 15, 1912, during her maiden voyage, the Titanic sank after colliding with an iceberg, killing 1502 out of 2224 passengers and crew. This sensational tragedy shocked the international community and led to better safety regulations for ships. One of the reasons that the shipwreck led to such loss of life was that there were not enough lifeboats for the passengers and crew. Although there was some element of luck involved in surviving the sinking, some groups of people were more likely to survive than others, such as women, children, and the upper-class. In this challenge, we ask you to complete the analysis of what sorts of people were likely to survive. In particular, we ask you to apply the tools of machine learning to predict which passengers survived the tragedy."
But going into this deeper, we need to know about the data of passengers travelling in the Titanic during the disaster so that we can develop a predictive model that can be used for survival analysis.
The dataset can be downloaded from the preceding URL. Table 1 here shows the metadata about the Titanic survival dataset:
A snapshot of the dataset can be seen as follows:
The ultimate target of using this dataset is to predict what kind of people survived the Titanic disaster. However, a bit of exploratory analysis of the dataset is a mandate. At first, we need to import necessary packages and libraries:
Now read the dataset and create a panda's DataFrame:
Before drawing the distribution of the dataset, let's specify the parameters for the graph:
Draw a bar diagram for showing who survived versus who did not:
Plot a graph showing survival by Age
:
Plot a graph showing distribution of the passengers
classes:
Plot a kernel density estimate of the subset of the 1st class passengers' age:
Plot a graph showing passengers per boarding location
:
The figure shows the survival distribution, survival by age, age distribution, and the passengers per boarding location:
However, to execute the preceding code, you need to install several packages such as matplotlib, pandas, and scipy. They are listed as follows:
- Installing pandas: Pandas is a Python package for data manipulation. It can be installed as follows:
- Installing matplotlib: In the preceding code, matplotlib is a plotting library for mathematical objects. It can be installed as follows:
- Installing scipy: Scipy is a Python package for scientific computing. Installing
blas
and lapack
and gfortran
are a prerequisite for this one. Now just execute the following command on your terminal:
For Mac, use the following command to install the above modules:
For windows, I am assuming that Python 2.7 is already installed at C:\Python27. Then open the command prompt and type the following command:
For Python3, issue the following commands:
Well, we have seen the data. Now it's your turn to do some analytics on top of the data. Say predicting what kinds of people survived from that disaster. Don't you agree that we have enough information about the passengers, but how could we do the predictive modeling so that we can draw some fairly straightforward conclusions from this data?
For example, say being a woman, being in 1st class, and being a child were all factors that could boost passenger chances of survival during this disaster.
In a brute-force approach–for example, using if/else statements with some sort of weighted scoring system, you could write a program to predict whether a given passenger would survive the disaster. However, does writing such a program in Python make much sense? Naturally, it would be very tedious to write, difficult to generalize, and would require extensive fine tuning for each variable and samples (that is, passenger).
This is where predictive analytics with machine learning algorithms and emerging tools comes in so that you could build a program that learns from the sample data to predict whether a given passenger would survive. In such cases, we will see throughout this book that TensorFlow could be a perfect solution to achieve outstanding accuracies across your predictive models. We will start describing the general overview of the TensorFlow framework. Then we will show how to install and configure TensorFlow on Linux, Mac OS and Windows.