Exploratory Data Analysis With an Example
By: Alifia Ghantiwala
Tags: Machine Learning, Eda

Exploratory Data Analysis With an Example

The most important step to work on a machine learning problem is to understand the input data.

Photo by Luke Chesser on Unsplash

EDA helps in identifying any outlier data points, understanding the relationships between the various attributes and structure of the data, recognizing the important variables. It helps in framing questions and visualizing the results, paving the way to make an informed choice of the machine learning algorithm for the problem in hand.

While working on performing EDA, it is important that we keep our objective in mind. Plotting fancy graphs is not the aim but deriving useful insights is.

Keeping that in mind, in this article we would look into an example of EDA performed on the Haberman’s survival dataset which is available on Kaggle.

Objective of this analysis is:- To find patterns within the dataset to gain further understanding of the data and leverage it to choose a machine learning algorithm for predicting the survival rates of patients who undergo the surgery.

The dataset contains cases from a study that was conducted between 1958 and 1970 at the University of Chicago’s Billings Hospital on the survival of patients who had undergone surgery for breast cancer.

Data attributes:-

Age of patient at time of operation (numerical)

Patient’s year of operation (year — 1900, numerical)

Number of positive axillary nodes detected (numerical)

Survival status (class attribute) 1 = the patient survived 5 years or longer, 2 = the patient died within 5 year

We start by loading the data into a data frame

The data has 305 rows and 4 columns with no NULL values. The columns do not have a heading/title, hence we provide a meaningful title to the columns in our dataset.

Observations:-

The data includes patients whose age is ranging from 30 to 83 years.

The operation has been performed for years 1958 to 1969

The maximum number of lymph nodes in the dataset is 52, with an approximate mean value of 4

Exploring the data

A quick look at the count of records for the attributes “age” and “year”(when the operation was performed) gives us the following insights.

We have more number of patients with a survival status of 1(those who survived for more than 5 years or longer) than of patients with survival status of 2(those who died within 5 years)

As the number of records existing for both survival rates has a major difference, our data is imbalanced.

In the year 1958, most of the operations were performed and the least operations were performed in 1969

Univariate Analysis

It is the simplest form of analyzing data, it uses only one variable hence the name, Univariate.

We would use Probability Density Function, Cumulative Distribution Function, Box Plots and Violin Plots for our analysis

Probability Density Function

The probability density function(PDF) provides the probability of a random variable falling in the range of values.

We have plotted below the PDF of age

Observations:-

Patients between age 30–34 have survived for 5 years or longer.

Patients whose age is more than 75 died within 5 years of the operation.

Number of patients between the age of 40–50 are more for status 2(i.e those who died within 5 years)

Number of patients between the age of 35–40 are more for status 1(i.e who have survived for 5 years or more), patients within this age group have a good chance of survival post the operation.

PDF of number of nodes

Observations:-

We see that the data is overlapping but we can note that survival rate is better in patients who have 0–2 nodes and the survival rate decreases as there is an increase in the number of nodes.

PDF of year of operation

Observations:-

The data is overlapping but we can see that between 1963 and 1966 we have more survival data and between 1958–1961 we have more data of patients who died within 5 years of the operation.

Cumulative Distribution Function

It describes the probability that a random variable will be found at a value less than or equal to the point at which the CDF is calculated.

CDF of number of nodes

Observations:-

80% of the patients who survived had nodes less than 5.

Whereas 80% of the patients who could not survive had greater than 10 nodes.

CDF of age

Observations:-

The CDF curve is highly overlapping but we can observe that 20% of surviving patients had an approximate age of 38, while 20% of patients who could not survive have an approximate age of 45

Box Plots

Help us in visualizing the distribution of data based on the quartiles and provide some indication of the data’s symmetry and skewness. Unlike many other methods of data display, boxplots show outliers.

Boxplot on Age

Observations:-

25th percentile of patients who have survived are of age approximate 42 years

25th percentile of patients who died are of age approximate 46 years

50th percentile of patients who have survived are of age approximate 52 years

50th percentile of patients who died are of age approximate 55 years

75th percentile of patients who have survived are of age approximate 60 years

75th percentile of patients who died are of age approximate 61 years

As we have noted before the data is overlapping to a great extent and hence we would not be able to draw an accurate conclusion on the basis of just the age of the patient.

Boxplot on nodes

Observations:-

We can see that for the nodes attribute we have some outlier points.

75 percentile of patients who survived have less than 4 nodes whereas 50 percentile of patients who could not survive have 5 nodes

Having low count of active nodes is definitely a contributing factor for the survival of a patient.

Bivariate Analysis

The aim is to find patterns/relationships within the dataset using two attributes. It is useful in testing simple associations.

One plot which can be used for the analysis is the pair plot.

Pair plots are an easy way to visualize relationships within your data. A matrix of each variable associated with another variable is produced for our analysis.

Below is an example of Pair Plots

Observations:-

Plot 2:- attributes:- age and year

The points are overlapping, due to which all points are not clearly visible on the plot, which makes it difficult to conclude.

Plot 3:- attributes:- age and nodes

The points are overlapping, due to which all points are not clearly visible on the plot, which makes it difficult to conclude. We can however see that patients with more number of nodes and high age are generally of status 2(who could not survive)

Plot 6:- attributes:- year and nodes

The points are overlapping, due to which all points are not clearly visible on the plot, which makes it difficult to conclude.

Multivariate Analysis

Contour plots can be used for multivariate analysis. They are used to represent a three dimensional surface on a two dimensional plane. One variable is represented on the horizontal axis and a second variable is represented on the vertical axis. The third variable is represented by a color gradient.

A contour plot on attributes, age on the Y axis, year on the X-axis and the third variable is status = 1(successful survival post 5 years of operation)

Observations:-

The patients who survived are mostly in the approximate age group of 45–55 within the years 1962–1964

A contour plot on attributes, age on the Y axis, year on the X-axis and the third variable is status = 2(could not survive)

Observations:-

The patients who could not survive were in the approximate age group of 45–50 between the years 1962 and 1965

Conclusions