Titanic Test Script

# This R script will run on our backend. You can write arbitrary code here! # Many standard libraries are already installed, such as randomForest library(randomForest) library(rpart) library(rpart.plot) library(RColorBrewer) library(dplyr) # The train and test data is stored in the ../input directory train <- read.csv(“../input/train.csv”) test <- read.csv(“../input/test.csv”) #Create Family Size variable train$family_size <- train$SibSp + train$Parch + 1 test$family_size <- test$SibSp + test$Parch + 1 #Create Survived variable column in test and fill with NA test$Survived <- NA #Temporarily combine train and test to do formatting combi <- rbind(train, test) #Format combi combi$Name <- as.character(combi$Name) combi$Title <- sapply(combi$Name, FUN=function(x) {strsplit(x, split='[,.]’)[[1]][2]}) combi$Title <- sub(‘ ‘, ”, combi$Title) combi$Title[combi$Title %in% c(‘Mme’, ‘Mlle’)] <- ‘Mlle’ combi$Title[combi$Title %in% c(‘Capt’, ‘Don’, ‘Major’, ‘Jonkheer’, ‘Sir’)] <- ‘Sir’ combi$Title[combi$Title %in% c(‘Dona’, ‘Lady’, ‘the Countess’)] <-…


Link to Full Article: Titanic Test Script