Created
January 7, 2020 03:25
-
-
Save adammb86/45a3741dd3241831aa31efdc464d6102 to your computer and use it in GitHub Desktop.
Ujicoba Algoritma Decision Tree Menggunakan R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("readr") | |
install.packages("dplyr") | |
install.packages("party") | |
install.packages("rpart") | |
install.packages("rpart.plot") | |
install.packages("ROCR") | |
library(readr) | |
library(dplyr) | |
library(party) | |
library(rpart) | |
library(rpart.plot) | |
library(ROCR) | |
set.seed(100) | |
#baca data online | |
titanic3 <- "https://goo.gl/At238b" %>% | |
read_csv %>% | |
select(survived, embarked, sex, sibsp, parch, fare) %>% | |
mutate(embarked = factor(embarked),sex = factor(sex)) | |
View(titanic3) | |
#split data ke training dan test data | |
.data <- c("training", "test") %>% | |
sample(nrow(titanic3), replace = T) %>% | |
split(titanic3, .) | |
#conditional partitioning | |
tree_fit <- ctree(survived ~ ., data = .data$training) | |
plot(tree_fit) | |
#Binary decision tree recursive partitioning | |
rtree_fit <- rpart(survived ~ ., .data$training) | |
rpart.plot(rtree_fit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment