I need this assignment to be done completely.


A3.pdf
Answered 4 days AfterNov 09, 2021

Answer To: A3.pdf

Archit answered on Nov 14 2021
124 Votes
Solutions
Question 1
a) data <- read.csv("titanic.csv")
data["Pclass", "Sex", "Embarked"] <- lapply(data["Pclass", "Sex", "Embarked"], facto
r)
str(data)
b) sapply(data, function(x) sum(is.na (x)))
data$Age[is.na(data$Age)]<-median(data$Age,na.rm=TRUE)
c) prop <- createDataPartition(data$Survived, 1, 0.75, list = FALSE)
train <- data[prop,]
test <- data[-prop,]
d) nb <- naiveBayes(Survived ~ ., data = train)
e) tree <- tree(Survived ~ ., data = train)
f) set.seed(1245)
nb_pred1 <- predict(nb, test, type ="raw")
tab1 <- cbind(nb_pred1, train$Survived)
1 - sum(diag(tab1)) / sum(tab1)
tree_pred1 <- predict(tree, train)
tab3 <- cbind(tree_pred1, train$Survived)
1 - sum(diag(tab3)) / sum(tab3)
g) pred_nb1 <- prediction(tab1[,1], train$Survived)
perf_nb1 <- performance(pred_nb1, "acc")
plot(perf_nb1)
pred_nb3 <- prediction(tab3[,1], train$Survived)
perf_nb3 <- performance(pred_nb1, "acc")
plot(perf_nb3)
h) 1) prop1 <- createDataPartition(data$Survived, 1, 0.25, list = FALSE)
train1 <- data[prop1,]
test1 <- data[-prop1,]
nb1 <- naiveBayes(Survived ~ ., data = train1)
nb1_pred <- predict(nb1, test, type ="raw")
tab5 <- cbind(nb1_pred, test$Survived)
1 - sum(diag(tab5)) / sum(tab5)
2) prop2 <- createDataPartition(data$Survived, 1, 0.5, list = FALSE)
train2 <- data[prop2,]
test2 <- data[-prop2,]
nb2 <- naiveBayes(Survived ~ ., data = train2)
nb2_pred <- predict(nb2, test, type ="raw")
tab6 <-...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here