Need Help in understanding a code snippet from Titanic Passenger Survival Project

titanic_survival
data_science
python

#1

Hello,

I have picked uo the following code snippet from titanic passenger survival project on Kaggle

I would like to know the role of “IsAlone” feature/field in the following command.

Its neither being used like a flag nor a feature. Kindly help me understand

for dataset in full_data:
dataset[‘IsAlone’] = 0 // I was able to understand this command
dataset.loc[dataset[‘FamilySize’] == 1, ‘IsAlone’] = 1 // Not able to make out the role of “IsAlone” here

Thanks,

Mohit


#2

If you do a basic exploratory analysis of the titanic dataset, you will find that the passengers who were with family had on an average a lower survival rate. By creating a new feature for this particular information, we are explicitly providing this information to the model.
Read the statement as when the family size is 1, the isAlone flag becomes one otherwise its a zero.


#3

Thanks Ankit !
if i understood it correctly then you mean to say is that primariy the command is being used to set the value of dataset.loc[‘IsAlone’] = 1 for all records which meet the condition [“FamilySize”]==1.

can you also help with me with the following snippet

dataset[‘Age’][np.isnan(dataset[‘Age’])] = age_null_random_list

what does the left hand side of the command specify…what is its meaning ?

Thanks for your help.


#4

It replaces all the missing age values with values from age_null_random_list.