PassengerId : Yolcu Kimliği HomePlanet : başlangıç gezegeni CryoSleep : Uyku yöntemi veya değil Cabin : Oda tipi ve numarası (iskele: iskele, sancak: sancak) Destination : Hedef Age : Yolcunun yaşı VIP : Yolcunun VIP hizmetinin olup olmadığı RoomService, FoodCourt, ShoppingMall, Spa, VRDeck :Yolcunun hizmet karşılığında ödediği tutar Name : isim Transported Geldi ya da ulaşmadı
Spaceship Titanic
1.VERI YUKLEME
library(readr)
train <- read_csv("train.csv")
test <- read_csv("test.csv")
library(tidyverse)
library(explore)
train %>% describe_all()
## # A tibble: 14 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet chr 201 2.3 4 NA NA NA
## 3 CryoSleep lgl 217 2.5 3 0 0.36 1
## 4 Cabin chr 199 2.3 6561 NA NA NA
## 5 Destination chr 182 2.1 4 NA NA NA
## 6 Age dbl 179 2.1 81 0 28.8 79
## 7 VIP lgl 203 2.3 3 0 0.02 1
## 8 RoomService dbl 181 2.1 1274 0 225. 14327
## 9 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 10 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 11 Spa dbl 183 2.1 1328 0 311. 22408
## 12 VRDeck dbl 188 2.2 1307 0 305. 24133
## 13 Name chr 200 2.3 8474 NA NA NA
## 14 Transported lgl 0 0 2 0 0.5 1
train[c("ailenum", "ailesira")] <- str_split_fixed(train$PassengerId, "_", 2)
test[c("ailenum", "ailesira")] <- str_split_fixed(test$PassengerId, "_", 2)
train[c('deck', 'num', 'side')] <- str_split_fixed(train$Cabin, '/', 3)
test[c('deck', 'num', 'side')] <- str_split_fixed(test$Cabin, '/', 3)
train[train == ''] <- NA
test[test == ''] <- NA
train %>% describe_all()
## # A tibble: 19 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet chr 201 2.3 4 NA NA NA
## 3 CryoSleep lgl 217 2.5 3 0 0.36 1
## 4 Cabin chr 199 2.3 6561 NA NA NA
## 5 Destination chr 182 2.1 4 NA NA NA
## 6 Age dbl 179 2.1 81 0 28.8 79
## 7 VIP lgl 203 2.3 3 0 0.02 1
## 8 RoomService dbl 181 2.1 1274 0 225. 14327
## 9 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 10 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 11 Spa dbl 183 2.1 1328 0 311. 22408
## 12 VRDeck dbl 188 2.2 1307 0 305. 24133
## 13 Name chr 200 2.3 8474 NA NA NA
## 14 Transported lgl 0 0 2 0 0.5 1
## 15 ailenum chr 0 0 6217 NA NA NA
## 16 ailesira chr 0 0 8 NA NA NA
## 17 deck chr 199 2.3 9 NA NA NA
## 18 num chr 199 2.3 1818 NA NA NA
## 19 side chr 199 2.3 3 NA NA NA
train <- train %>% select(-Cabin)
test <- test %>% select(-Cabin)
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet chr 201 2.3 4 NA NA NA
## 3 CryoSleep lgl 217 2.5 3 0 0.36 1
## 4 Destination chr 182 2.1 4 NA NA NA
## 5 Age dbl 179 2.1 81 0 28.8 79
## 6 VIP lgl 203 2.3 3 0 0.02 1
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 183 2.1 1328 0 311. 22408
## 11 VRDeck dbl 188 2.2 1307 0 305. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side chr 199 2.3 3 NA NA NA
unique(train$HomePlanet)
## [1] "Europa" "Earth" "Mars" NA
levels(train$HomePlanet)
## NULL
train$HomePlanet <- addNA(train$HomePlanet)
levels(train$HomePlanet )
## [1] "Earth" "Europa" "Mars" NA
levels(train$HomePlanet)[is.na(levels(train$HomePlanet))] <- "NA"
levels(test$HomePlanet)[is.na(levels(test$HomePlanet))] <- "NA"
levels(train$HomePlanet)
## [1] "Earth" "Europa" "Mars" "NA"
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep lgl 217 2.5 3 0 0.36 1
## 4 Destination chr 182 2.1 4 NA NA NA
## 5 Age dbl 179 2.1 81 0 28.8 79
## 6 VIP lgl 203 2.3 3 0 0.02 1
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 183 2.1 1328 0 311. 22408
## 11 VRDeck dbl 188 2.2 1307 0 305. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side chr 199 2.3 3 NA NA NA
train <- train %>%
group_by(HomePlanet,Destination) %>%
mutate_at(vars(Age) ,~replace_na(., mean(., na.rm = TRUE)))
test <- test %>%
group_by(HomePlanet,Destination) %>%
mutate_at(vars(Age) ,~replace_na(., mean(., na.rm = TRUE)))
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep lgl 217 2.5 3 0 0.36 1
## 4 Destination chr 182 2.1 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP lgl 203 2.3 3 0 0.02 1
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 183 2.1 1328 0 311. 22408
## 11 VRDeck dbl 188 2.2 1307 0 305. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side chr 199 2.3 3 NA NA NA
train$CryoSleep <- addNA(train$CryoSleep)
test$CryoSleep <- addNA(test$CryoSleep)
levels(train$CryoSleep)[is.na(levels(train$CryoSleep))] <- "NA"
levels(test$CryoSleep)[is.na(levels(test$CryoSleep))] <- "NA"
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination chr 182 2.1 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP lgl 203 2.3 3 0 0.02 1
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 183 2.1 1328 0 311. 22408
## 11 VRDeck dbl 188 2.2 1307 0 305. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side chr 199 2.3 3 NA NA NA
unique(train$Destination)
## [1] "TRAPPIST-1e" "PSO J318.5-22" "55 Cancri e" NA
train$Destination <- addNA(train$Destination)
test$Destination <- addNA(test$Destination)
levels(train$Destination)[is.na(levels(train$Destination))] <- "NA"
levels(test$Destination)[is.na(levels(test$Destination))] <- "NA"
train$side <- addNA(train$side)
test$side <- addNA(test$side)
levels(train$side)[is.na(levels(train$side))] <- "NA"
levels(test$side)[is.na(levels(test$side))] <- "NA"
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP lgl 203 2.3 3 0 0.02 1
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 183 2.1 1328 0 311. 22408
## 11 VRDeck dbl 188 2.2 1307 0 305. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side fct 0 0 3 NA NA NA
train$VIP <- addNA(train$VIP)
test$VIP <- addNA(test$VIP)
levels(train$VIP )[is.na(levels(train$VIP))] <- "NA"
levels(test$VIP )[is.na(levels(test$VIP))] <- "NA"
train <- train %>%
group_by(Destination) %>%
mutate_at(vars(Age) ,~replace_na(., mean(., na.rm = TRUE)))
test <- test %>%
group_by(Destination) %>%
mutate_at(vars(Age) ,~replace_na(., mean(., na.rm = TRUE)))
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP fct 0 0 3 NA NA NA
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 183 2.1 1508 0 458. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 183 2.1 1328 0 311. 22408
## 11 VRDeck dbl 188 2.2 1307 0 305. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side fct 0 0 3 NA NA NA
2.HISTOGRAM
hist(train$Spa)
hist(iris$Sepal.Width, col = "orange",xlab = "HomePlanet", ylab = "Destination", main = "Histogram")
train <- train %>% mutate(FoodCourt = coalesce(FoodCourt, 0))
test <- test %>% mutate(FoodCourt = coalesce(FoodCourt, 0))
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP fct 0 0 3 NA NA NA
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 0 0 1507 0 448. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 183 2.1 1328 0 311. 22408
## 11 VRDeck dbl 188 2.2 1307 0 305. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side fct 0 0 3 NA NA NA
train <- train %>% mutate(ShoppingMall = coalesce(ShoppingMall), Spa = coalesce(Spa, 0), VRDeck = coalesce(VRDeck, 0))
test <- test %>% mutate(ShoppingMall = coalesce(ShoppingMall), Spa = coalesce(Spa, 0), VRDeck = coalesce(VRDeck, 0))
train %>% describe_all()
## # A tibble: 18 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP fct 0 0 3 NA NA NA
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 0 0 1507 0 448. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 0 0 1327 0 305. 22408
## 11 VRDeck dbl 0 0 1306 0 298. 24133
## 12 Name chr 200 2.3 8474 NA NA NA
## 13 Transported lgl 0 0 2 0 0.5 1
## 14 ailenum chr 0 0 6217 NA NA NA
## 15 ailesira chr 0 0 8 NA NA NA
## 16 deck chr 199 2.3 9 NA NA NA
## 17 num chr 199 2.3 1818 NA NA NA
## 18 side fct 0 0 3 NA NA NA
train <- train %>% select(-Name)
test <- test %>% select(-Name)
train %>% describe_all()
## # A tibble: 17 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP fct 0 0 3 NA NA NA
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 0 0 1507 0 448. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 0 0 1327 0 305. 22408
## 11 VRDeck dbl 0 0 1306 0 298. 24133
## 12 Transported lgl 0 0 2 0 0.5 1
## 13 ailenum chr 0 0 6217 NA NA NA
## 14 ailesira chr 0 0 8 NA NA NA
## 15 deck chr 199 2.3 9 NA NA NA
## 16 num chr 199 2.3 1818 NA NA NA
## 17 side fct 0 0 3 NA NA NA
train$deck <- addNA(train$deck)
test$deck <- addNA(test$deck)
levels(train$deck )[is.na(levels(train$deck))] <- "NA"
levels(test$deck )[is.na(levels(test$deck))] <- "NA"
train %>% describe_all()
## # A tibble: 17 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP fct 0 0 3 NA NA NA
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 0 0 1507 0 448. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 0 0 1327 0 305. 22408
## 11 VRDeck dbl 0 0 1306 0 298. 24133
## 12 Transported lgl 0 0 2 0 0.5 1
## 13 ailenum chr 0 0 6217 NA NA NA
## 14 ailesira chr 0 0 8 NA NA NA
## 15 deck fct 0 0 9 NA NA NA
## 16 num chr 199 2.3 1818 NA NA NA
## 17 side fct 0 0 3 NA NA NA
test %>% describe_all()
## # A tibble: 16 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 4277 NA NA NA
## 2 HomePlanet chr 87 2 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.7 79
## 6 VIP fct 0 0 3 NA NA NA
## 7 RoomService dbl 82 1.9 843 0 219. 11567
## 8 FoodCourt dbl 0 0 902 0 429. 25273
## 9 ShoppingMall dbl 98 2.3 716 0 177. 8292
## 10 Spa dbl 0 0 833 0 296. 19844
## 11 VRDeck dbl 0 0 796 0 305. 22272
## 12 ailenum chr 0 0 3063 NA NA NA
## 13 ailesira chr 0 0 8 NA NA NA
## 14 deck fct 0 0 9 NA NA NA
## 15 num chr 100 2.3 1506 NA NA NA
## 16 side fct 0 0 3 NA NA NA
train$ailes <- ifelse(duplicated(train$ailenum) | duplicated(train$ailenum, fromLast = TRUE), 1.0, 0.0)
test$ailes <- ifelse(duplicated(test$ailenum) | duplicated(test$ailenum, fromLast = TRUE), 1.0, 0.0)
head(train[, c("PassengerId", "ailenum", "ailesira", "ailes")], 20)
## # A tibble: 20 × 4
## PassengerId ailenum ailesira ailes
## <chr> <chr> <chr> <dbl>
## 1 0001_01 0001 01 0
## 2 0002_01 0002 01 0
## 3 0003_01 0003 01 1
## 4 0003_02 0003 02 1
## 5 0004_01 0004 01 0
## 6 0005_01 0005 01 0
## 7 0006_01 0006 01 1
## 8 0006_02 0006 02 1
## 9 0007_01 0007 01 0
## 10 0008_01 0008 01 1
## 11 0008_02 0008 02 1
## 12 0008_03 0008 03 1
## 13 0009_01 0009 01 0
## 14 0010_01 0010 01 0
## 15 0011_01 0011 01 0
## 16 0012_01 0012 01 0
## 17 0014_01 0014 01 0
## 18 0015_01 0015 01 0
## 19 0016_01 0016 01 0
## 20 0017_01 0017 01 1
train <- train %>% select(-c(ailenum, ailesira, num))
test <- test %>% select(-c(ailenum, ailesira, num))
train %>% describe_all()
## # A tibble: 15 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId chr 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 4 NA NA NA
## 3 CryoSleep fct 0 0 3 NA NA NA
## 4 Destination fct 0 0 4 NA NA NA
## 5 Age dbl 0 0 91 0 28.8 79
## 6 VIP fct 0 0 3 NA NA NA
## 7 RoomService dbl 181 2.1 1274 0 225. 14327
## 8 FoodCourt dbl 0 0 1507 0 448. 29813
## 9 ShoppingMall dbl 208 2.4 1116 0 174. 23492
## 10 Spa dbl 0 0 1327 0 305. 22408
## 11 VRDeck dbl 0 0 1306 0 298. 24133
## 12 Transported lgl 0 0 2 0 0.5 1
## 13 deck fct 0 0 9 NA NA NA
## 14 side fct 0 0 3 NA NA NA
## 15 ailes dbl 0 0 2 0 0.45 1
3.LOGISTIC REGRESYON
train_set <- train[2:15]
test_set <- test[2:14]
library(caTools)
set.seed(123)
split = sample.split(train_set$Transported, SplitRatio = 0.75)
training_set = subset(train_set, split == TRUE)
testing_set = subset(train_set, split == FALSE)
logistic = glm(formula = Transported ~ ., family = binomial, data = training_set)
logistic = glm(formula = Transported ~ ., family = binomial, data = training_set, control = list(maxit = 100))
prob_pred = predict(logistic, type = 'response', newdata = testing_set[-11])
y_Pred = ifelse(prob_pred > 0.5, 1,0)
y_true <- ifelse(testing_set[11] == TRUE, 1,0)
cm = table(y_true, y_Pred)
cm
## y_Pred
## y_true 0 1
## 0 784 250
## 1 175 866
(866+784)/(784+866+250+175)
## [1] 0.7951807
logistic_son = glm(formula = Transported ~ ., family = binomial, data = train_set )
# Önce modeli eğitelim (eğitim seti üzerinde)
logistic_son = glm(formula = Transported ~ ., family = binomial, data = training_set)
# Ardından, eğitilmiş modeli kullanarak yeni veri seti üzerinde tahmin olasılıklarını elde edelim
prob_pred = predict(logistic_son, type = 'response', newdata = test_set)
y_Pred = ifelse(prob_pred > 0.5, TRUE, FALSE)
Transported <- as.character(y_Pred)
PassengerId <- test$PassengerId
Transported <- as.vector(Transported)
submission <- cbind(PassengerId, Transported)
submission <- as.data.frame(submission)
SUBMISSION LOGISTIC Kaggl SONUçlar
4. STRINGR
library(stringr)
submission$Transported <- str_to_title(submission$Transported)
write.csv(submission, "submission_logistic.csv", row.names = FALSE, quote = FALSE)
5.NAIVE BAYES
library(e1071)
fit_nb <- naiveBayes(Transported ~ ., data = training_set)
preds <- predict(fit_nb, newdata = testing_set[,-11], type = "raw") %>% data.frame()
y_Pred = ifelse(preds$TRUE. > 0.5, 1,0)
cm = table(y_true, y_Pred)
cm
## y_Pred
## y_true 0 1
## 0 509 570
## 1 78 1016
(509 +1016)/(509 + 1016+ 78 +570)
## [1] 0.7017948
nb_son = naiveBayes(Transported ~ ., data = train_set)
preds <- predict(nb_son, newdata = test_set, type = "raw") %>% data.frame()
y_Pred = ifelse(preds$TRUE. > 0.5, TRUE, FALSE)
Transported <- as.character(y_Pred)
PassengerId <- test$PassengerId
Transported <- as.vector(Transported)
submission <- as.data.frame(submission)
submission$Transported <- str_to_title(submission$Transported)
write.csv(submission, "sub_nb.csv", row.names = FALSE, quote = FALSE)
SUB_nb.csv sonuç
6.SVM
library(e1071)
fit_svm <- svm(Transported ~ ., data = training_set, type = 'C-classification', kernel = 'linear')
preds <- predict(fit_svm, newdata = testing_set, type = "raw") %>%
data.frame()
y_Pred = ifelse(preds$. == TRUE, 1, 0)
write.csv(submission, "sub_svm.csv", row.names = FALSE, quote = FALSE)
SUB_SVM Kaggle sonuç
svm_ker_son = svm(Transported ~ ., data =train_set,
type = 'C-classification',
kernel = 'radial')
preds <- predict(svm_ker_son, newdata = test_set, type = "raw") %>%
data.frame()
y_pred = preds$.
Transported <- as.character(y_pred)
PassengerId <- test$PassengerId
Transported <-as.vector(Transported)