Logistic regression with R codes
Train the model using the training sets and check scorelogistic <- glm(formula = Survived ~ Pclass + Sex + Embarked + Age, data = train, family ="binomial")summary(logistic)
# Let us make prediction using logistic modelmy_log_prediction <- predict(logistic, test, type = "response")# Suppose you wish to calculate probabilitysubmit <- data.frame(PassengerId = test$PassengerId, Survived = my_log_prediction)write.csv(submit, file = "logistic_prob.csv", row.names = FALSE)# Suppose you wish to calculate classifcationpredicted.classes <- ifelse(predicted > 0.5, "1", "0")table(predicted.classes)
# If you want import the data in csv formatsubmit <- data.frame(PassengerId = test$PassengerId, Survived = my_log_prediction, Classification = predicted.classes)write.csv(submit, file = "logistic_class_prob.csv", row.names = FALSE)