Get startedGet started for free

Passenger Title and survival rate

Was it coincidence that upper-class Rose survived and third-class passenger Jack not? Let's have a look...

You have access to a new train and test set named train_new and test_new. These data sets contain a new column with the name Title (referring to Miss, Mr, etc.). Title is another example of feature engineering: it's a new variable that possibly improves the model.

This exercise is part of the course

Kaggle R Tutorial on Machine Learning

View Course

Exercise instructions

  • Finish the command to create a decision tree my_tree_five: make sure to include the Title variable, and to create the tree based on train_new.
  • Visualize my_tree_five with fancyRpartPlot(). Notice that Title appears in one of the nodes.
  • Finish the predict() call to create my_prediction: the function should use my_tree_five and test_new to make predictions.
  • The code that creates a data frame my_solution and writes it to a CSV file is included: these steps make the solution ready for a submission on Kaggle.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# train_new and test_new are available in the workspace

# Finish the command
my_tree_five <- rpart(Survived ~ Pclass + Sex + Age + SibSp + Parch + Fare + Embarked + ___,
                      data = ___, method = "class")

# Visualize my_tree_five


# Make prediction
my_prediction <- predict(___, ___, type = "class")

# Make results ready for submission
my_solution <- data.frame(PassengerId = test_new$PassengerId, Survived = my_prediction)
write.csv(my_solution, file = "my_solution.csv", row.names = FALSE)
Edit and Run Code