BaggedTrees

# This R script will run on our backend. You can write arbitrary code here! library(psych) library(caret) library(rpart) # The train and test data is stored in the ../input directory set.seed(1) train <- read.csv(“../input/train.csv”) test <- read.csv(“../input/test.csv”) ###Data Wrangle Function wrangleFeatures <- function(data) { variables <- c(“Pclass”, “Sex”, “Age”, “SibSp”, “Parch”, “Cabin”, “Fare”, “Embarked”) data <- data[variables] predicted_age <- rpart(Age ~ Pclass + Sex + SibSp + Parch + Fare + Embarked, data = data[!is.na(data$Age),], method = “anova”) data$Age[is.na(data$Age)] <- predict(predicted_age, data[is.na(data$Age),]) data$Fare[is.na(data$Fare)] <- median(data$Fare, na.rm=TRUE) data$Embarked[data$Embarked==””] = “S” data$Sex <- as.factor(data$Sex) data$Embarked <- as.factor(data$Embarked) data$Cabin <- as.character(data$Cabin) data$Cabin[grep(“A”, data$Cabin)] <- “boat” data$Cabin[grep(“B”, data$Cabin)] <- “promenade” data$Cabin[grep(“C”, data$Cabin)] <- “bridge” data$Cabin[grep(“D”, data$Cabin)] <- “shelter” data$Cabin[grep(“E”, data$Cabin)] <- “saloon” data$Cabin[grep(“F”, data$Cabin)] <- “upper” data$Cabin[grep(“G”, data$Cabin)] <- “middle” data$Cabin[grep(“T”, data$Cabin)] <- “”…


Link to Full Article: BaggedTrees