Titanic: Machine Learning Disaster

Tarunjot Singh
4 min readMar 24, 2021

--

Lets import all the required Libraries

Acquire data

The Python Pandas packages helps us work with our datasets. We start by acquiring the training and testing datasets into Pandas DataFrames. We also combine these datasets to run certain operations on both datasets together.

Analyze by describing data

Pandas also helps describe the datasets answering following questions early in our project.

The above list is of the feature variables out of which ‘Survived’ is our target variable, the variable which we have to predict. And if we talk about the rest of the variables, at the current moment at least we can say that ‘PassengerId’, ‘Ticket’ and ‘Cabin’ are of no use because they have no relation with the probability of survival of a passenger.

Which features are categorical?

These values classify the samples into sets of similar samples. Within categorical features are the values nominal, ordinal, ratio, or interval based? Among other things this helps us select the appropriate plots for visualization.

  • Categorical: Survived, Sex, and Embarked. Ordinal: Pclass.

Which features are numerical?

Which features are numerical? These values change from sample to sample. Within numerical features are the values discrete, continuous, or timeseries based? Among other things this helps us select the appropriate plots for visualization.

  • Continous: Age, Fare. Discrete: SibSp, Parch.

Which features are mixed data types?

Numerical, alphanumeric data within same feature. These are candidates for correcting goal.

  • Ticket is a mix of numeric and alphanumeric data types. Cabin is alphanumeric.

Which features may contain errors or typos?

This is harder to review for a large dataset, however reviewing a few samples from a smaller dataset may just tell us outright, which features may require correcting.

  • Name feature may contain errors or typos as there are several ways used to describe a name including titles, round brackets, and quotes used for alternative or short names.

Which features contain blank, null or empty values?

These will require correcting.

  • Cabin > Age > Embarked features contain a number of null values in that order for the training dataset.
  • Cabin > Age are incomplete in case of test dataset.

What are the data types for various features?

Helping us during converting goal.

  • Seven features are integer or floats. Six in case of test dataset.
  • Five features are strings (object).

What is the distribution of numerical feature values across the samples?

This helps us determine, among other early insights, how representative is the training dataset of the actual problem domain.

  • Total samples are 891 or 40% of the actual number of passengers on board the Titanic (2,224).
  • Survived is a categorical feature with 0 or 1 values.
  • Around 38% samples survived representative of the actual survival rate at 32%.
  • Most passengers (> 75%) did not travel with parents or children.
  • Nearly 30% of the passengers had siblings and/or spouse aboard.
  • Fares varied significantly with few passengers (<1%) paying as high as $512.
  • Few elderly passengers (<1%) within age range 65–80.

Analyze by pivoting features

To confirm some of our observations and assumptions, we can quickly analyze our feature correlations by pivoting features against each other. We can only do so at this stage for features which do not have any empty values. It also makes sense doing so only for features which are categorical (Sex), ordinal (Pclass) or discrete (SibSp, Parch) type.

  • Pclass We observe significant correlation (>0.5) among Pclass=1 and Survived (classifying #3). We decide to include this feature in our model.
  • Sex We confirm the observation during problem definition that Sex=female had very high survival rate at 74% (classifying #1).
  • SibSp and Parch These features have zero correlation for certain values. It may be best to derive a feature or a set of features from these individual features (creating #1).

--

--

Tarunjot Singh
Tarunjot Singh

No responses yet