Ekonometri Final projesi
train.csv - Yolcuların yaklaşık üçte ikisinin (~8700) kişisel kayıtları, eğitim verileri olarak kullanılacak. PassengerId - Her yolcu için benzersiz bir Kimlik. Her Kimlik gggg_pp biçimini alır; burada gggg yolcunun birlikte seyahat ettiği grubu belirtir ve pp grup içindeki numaradır. Bir gruptaki insanlar çoğunlukla aile üyeleridir, ancak her zaman değil.
HomePlanet - Yolcunun ayrıldığı gezegen, genellikle daimi ikamet ettikleri gezegen.
CryoSleep - Yolcunun yolculuk süresince askıya alınmış animasyona alınmayı seçip seçmediğini gösterir. Dondurarak uykudaki yolcular kabinlerine hapsedilir.
Kabin - Yolcunun kaldığı kabin numarası. Güverte/numara/yan formunu alır; burada taraf, İskele için P veya Sancak için S olabilir. Hedef - Yolcunun gemiden ineceği gezegen.
Age - Yolcunun yaşı.
VIP - Yolcunun yolculuk sırasında özel VIP hizmeti için ödeme yapıp yapmadığı.
RoomService, FoodCourt, Alışveriş Merkezi, Spa, VRDeck - Yolcunun, Spaceship Titanic’in birçok lüks olanağının her birinde fatura ettiği tutar.
Name - Yolcunun adı ve soyadı.
Transported - Yolcunun başka bir boyuta taşınıp taşınmadığı. Bu hedeftir, tahmin etmeye çalıştığınız sütundur.
test.csv - Yolcuların geri kalan üçte birinin (~4300) kişisel kayıtları, test verisi olarak kullanılacak. Göreviniz bu setteki yolcular için Taşınan değerini tahmin etmektir.
sample_submission.csv - Doğru formatta bir gönderim dosyası.
PassengerId - Test setindeki her yolcunun kimliği.
Transported - Hedef.Her yolcu için Doğru veya Yanlış’ı tahmin edin.
## # 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
## # A tibble: 13 × 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 lgl 93 2.2 3 0 0.37 1
## 4 Cabin chr 100 2.3 3266 NA NA NA
## 5 Destination chr 92 2.2 4 NA NA NA
## 6 Age dbl 91 2.1 80 0 28.7 79
## 7 VIP lgl 93 2.2 3 0 0.02 1
## 8 RoomService dbl 82 1.9 843 0 219. 11567
## 9 FoodCourt dbl 106 2.5 903 0 439. 25273
## 10 ShoppingMall dbl 98 2.3 716 0 177. 8292
## 11 Spa dbl 101 2.4 834 0 303. 19844
## 12 VRDeck dbl 80 1.9 797 0 311. 22272
## 13 Name chr 94 2.2 4177 NA NA NA
train[c('group','pp')] <- str_split_fixed(train$PassengerId,'_',2)
test[c('group','pp')] <- str_split_fixed(test$PassengerId,'_',2)## # A tibble: 6 × 3
## PassengerId group pp
## <chr> <chr> <chr>
## 1 0001_01 0001 01
## 2 0002_01 0002 01
## 3 0003_01 0003 01
## 4 0003_02 0003 02
## 5 0004_01 0004 01
## 6 0005_01 0005 01
## # A tibble: 6 × 4
## PassengerId group pp withgroup
## <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
## PassengerId HomePlanet CryoSleep Cabin
## 0001_01: 1 Earth :4602 Mode :logical G/734/S: 8
## 0002_01: 1 Europa:2131 FALSE:5439 B/11/S : 7
## 0003_01: 1 Mars :1759 TRUE :3037 B/201/P: 7
## 0003_02: 1 NA's : 201 NA's :217 B/82/S : 7
## 0004_01: 1 C/137/S: 7
## 0005_01: 1 (Other):8458
## (Other):8687 NA's : 199
## Destination Age VIP RoomService
## 55 Cancri e :1800 Min. : 0.00 Mode :logical Min. : 0.0
## PSO J318.5-22: 796 1st Qu.:19.00 FALSE:8291 1st Qu.: 0.0
## TRAPPIST-1e :5915 Median :27.00 TRUE :199 Median : 0.0
## NA's : 182 Mean :28.83 NA's :203 Mean : 224.7
## 3rd Qu.:38.00 3rd Qu.: 47.0
## Max. :79.00 Max. :14327.0
## NA's :179 NA's :181
## FoodCourt ShoppingMall Spa VRDeck
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
## 1st Qu.: 0.0 1st Qu.: 0.0 1st Qu.: 0.0 1st Qu.: 0.0
## Median : 0.0 Median : 0.0 Median : 0.0 Median : 0.0
## Mean : 458.1 Mean : 173.7 Mean : 311.1 Mean : 304.9
## 3rd Qu.: 76.0 3rd Qu.: 27.0 3rd Qu.: 59.0 3rd Qu.: 46.0
## Max. :29813.0 Max. :23492.0 Max. :22408.0 Max. :24133.0
## NA's :183 NA's :208 NA's :183 NA's :188
## Name Transported group pp
## Alraium Disivering: 2 Mode :logical 0984 : 8 01 :6217
## Ankalik Nateansive: 2 FALSE:4315 4005 : 8 02 :1412
## Anton Woody : 2 TRUE :4378 4256 : 8 03 : 571
## Apix Wala : 2 4498 : 8 04 : 231
## Asch Stradick : 2 5133 : 8 05 : 128
## (Other) :8483 5756 : 8 06 : 75
## NA's : 200 (Other):8645 (Other): 59
## withgroup deck num side
## Min. :0.0000 F :2794 : 199 : 199
## 1st Qu.:0.0000 G :2559 82 : 28 P:4206
## Median :0.0000 E : 876 19 : 22 S:4288
## Mean :0.4473 B : 779 86 : 22
## 3rd Qu.:1.0000 C : 747 176 : 21
## Max. :1.0000 (Other): 739 56 : 21
## NA's : 199 (Other):8380
train$num <- droplevels(train$num)
test$num <- droplevels(test$num)
train$side <- droplevels(train$side)
test$side <- droplevels(test$side)Bosluklari dolduralim
##
## Attachement du package : 'zoo'
## Les objets suivants sont masqués depuis 'package:base':
##
## as.Date, as.Date.numeric
most_frequent_hp <- train %>%
filter(! is.na(HomePlanet)) %>%
group_by(Destination,HomePlanet) %>%
summarize(count = n()) %>%
arrange(Destination,desc(count)) %>%
slice(1) %>%
ungroup()## `summarise()` has grouped output by 'Destination'. You can override using the
## `.groups` argument.
## # A tibble: 4 × 3
## Destination HomePlanet count
## <fct> <fct> <int>
## 1 55 Cancri e Europa 893
## 2 PSO J318.5-22 Earth 715
## 3 TRAPPIST-1e Earth 3116
## 4 <NA> Earth 99
train$HomePlanet <- as.character(train$HomePlanet)
train$Destination <- as.character(train$Destination)train <- train %>%
mutate(HomePlanet = ifelse(is.na(HomePlanet) & Destination == "55 Cancri e","Europa" ,
ifelse(is.na(HomePlanet), "Earth",HomePlanet)))test <- test %>%
mutate(HomePlanet = ifelse(is.na(HomePlanet) & Destination == "55 Cancri e","Europa" ,
ifelse(is.na(HomePlanet), "Earth",HomePlanet)))## # A tibble: 20 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId fct 0 0 8693 NA NA NA
## 2 HomePlanet chr 4 0 4 NA NA NA
## 3 CryoSleep lgl 217 2.5 3 0 0.36 1
## 4 Cabin fct 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 fct 200 2.3 8474 NA NA NA
## 14 Transported lgl 0 0 2 0 0.5 1
## 15 group fct 0 0 6217 NA NA NA
## 16 pp fct 0 0 8 NA NA NA
## 17 withgroup dbl 0 0 2 0 0.45 1
## 18 deck fct 199 2.3 9 NA NA NA
## 19 num fct 199 2.3 1818 NA NA NA
## 20 side fct 199 2.3 3 NA NA NA
## # A tibble: 19 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId fct 0 0 4277 NA NA NA
## 2 HomePlanet chr 0 0 3 NA NA NA
## 3 CryoSleep lgl 93 2.2 3 0 0.37 1
## 4 Cabin fct 100 2.3 3266 NA NA NA
## 5 Destination chr 92 2.2 4 NA NA NA
## 6 Age dbl 91 2.1 80 0 28.7 79
## 7 VIP lgl 93 2.2 3 0 0.02 1
## 8 RoomService dbl 82 1.9 843 0 219. 11567
## 9 FoodCourt dbl 106 2.5 903 0 439. 25273
## 10 ShoppingMall dbl 98 2.3 716 0 177. 8292
## 11 Spa dbl 101 2.4 834 0 303. 19844
## 12 VRDeck dbl 80 1.9 797 0 311. 22272
## 13 Name fct 94 2.2 4177 NA NA NA
## 14 group fct 0 0 3063 NA NA NA
## 15 pp fct 0 0 8 NA NA NA
## 16 withgroup dbl 0 0 2 0 0.45 1
## 17 deck fct 100 2.3 9 NA NA NA
## 18 num fct 100 2.3 1506 NA NA NA
## 19 side fct 100 2.3 3 NA NA NA
most_frequent_destinations <- train %>%
filter(!is.na(Destination)) %>%
group_by(HomePlanet,Destination) %>%
summarize(count = n()) %>%
arrange(HomePlanet,desc(count)) %>%
slice(1) %>%
ungroup()## `summarise()` has grouped output by 'HomePlanet'. You can override using the
## `.groups` argument.
## # A tibble: 3 × 3
## HomePlanet Destination count
## <chr> <chr> <int>
## 1 Earth TRAPPIST-1e 3221
## 2 Europa TRAPPIST-1e 1204
## 3 Mars TRAPPIST-1e 1490
train$HomePlanet <- as.factor(train$HomePlanet)
train$Destination <- as.factor(train$Destination)
test$HomePlanet <- as.factor(test$HomePlanet)
test$Destination <- as.factor(test$Destination)train <- train %>%
mutate(RoomService = coalesce(RoomService, 0),
FoodCourt = coalesce(FoodCourt, 0),
ShoppingMall = coalesce(ShoppingMall, 0),
Spa = coalesce(Spa, 0),
VRDeck = coalesce(VRDeck, 0))test <- test %>%
mutate(RoomService = coalesce(RoomService, 0),
FoodCourt = coalesce(FoodCourt, 0),
ShoppingMall = coalesce(ShoppingMall, 0),
Spa = coalesce(Spa, 0),
VRDeck = coalesce(VRDeck, 0))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$expense <- train$RoomService + train$FoodCourt + train$ShoppingMall + train$Spa + train$VRDecktrain <- transform(train,CryoSleep = replace(CryoSleep, is.na(CryoSleep) & expense>0 & Age>12, "FALSE"))test <- transform(test,CryoSleep = replace(CryoSleep, is.na(CryoSleep) & expense>0 & Age>12, "FALSE"))train <- transform(train,CryoSleep = replace(CryoSleep,is.na(CryoSleep) & expense==0 & Age>12, "TRUE"))test <- transform(test,CryoSleep = replace(CryoSleep,is.na(CryoSleep) & expense==0 & Age>12, "TRUE"))most_frequent_decks <- train %>%
filter(!is.na(deck)) %>%
group_by(HomePlanet,deck) %>%
summarize(count = n()) %>%
arrange(HomePlanet,desc(count)) %>%
slice(1) %>%
ungroup()## `summarise()` has grouped output by 'HomePlanet'. You can override using the
## `.groups` argument.
## # A tibble: 3 × 3
## HomePlanet deck count
## <fct> <fct> <int>
## 1 Earth G 2576
## 2 Europa B 787
## 3 Mars F 1122
train <- train %>%
mutate(deck = ifelse(is.na(deck) & HomePlanet == "Earth", "G",
ifelse(is.na(deck) & HomePlanet == "Europa", "B",
ifelse(is.na(deck) & HomePlanet == "Mars", "F", deck))))test <- test %>%
mutate(deck = ifelse(is.na(deck) & HomePlanet == "Earth", "G",
ifelse(is.na(deck) & HomePlanet == "Europa", "B",
ifelse(is.na(deck) & HomePlanet == "Mars", "F", deck))))most_frequent_sides <- train %>%
filter(!is.na(side)) %>%
group_by(HomePlanet,side) %>%
summarize(count = n()) %>%
arrange(HomePlanet,desc(count)) %>%
slice(1) %>%
ungroup()## `summarise()` has grouped output by 'HomePlanet'. You can override using the
## `.groups` argument.
## # A tibble: 3 × 3
## HomePlanet side count
## <chr> <fct> <int>
## 1 Earth P 2352
## 2 Europa S 1155
## 3 Mars P 900
train <- train %>%
mutate(side = ifelse(is.na(side) & HomePlanet == "Earth", "P",
ifelse(is.na(side) & HomePlanet == "Europa", "S",
ifelse(is.na(side) & HomePlanet == "Mars", "P", side))))test <- test %>%
mutate(side = ifelse(is.na(side) & HomePlanet == "Earth", "P",
ifelse(is.na(side) & HomePlanet == "Europa", "S",
ifelse(is.na(side) & HomePlanet == "Mars", "P", side))))## Adding missing grouping variables: `group`
## Adding missing grouping variables: `group`
## `mutate_if()` ignored the following grouping variables:
## • Column `group`
## `mutate_if()` ignored the following grouping variables:
## • Column `group`
## PassengerId HomePlanet CryoSleep Destination
## Length:8693 Europa:2174 FALSE:5581 55 Cancri e :1800
## Class :character Earth :4743 TRUE :3112 PSO J318.5-22: 796
## Mode :character Mars :1776 TRAPPIST-1e :6097
##
##
##
##
## Age VIP RoomService FoodCourt
## Min. : 0.00 Mode :logical Min. : 0 Min. : 0.0
## 1st Qu.:20.00 FALSE:8494 1st Qu.: 0 1st Qu.: 0.0
## Median :27.00 TRUE :199 Median : 0 Median : 0.0
## Mean :28.84 Mean : 220 Mean : 448.4
## 3rd Qu.:37.00 3rd Qu.: 41 3rd Qu.: 61.0
## Max. :79.00 Max. :14327 Max. :29813.0
##
## ShoppingMall Spa VRDeck Transported
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Mode :logical
## 1st Qu.: 0.0 1st Qu.: 0.0 1st Qu.: 0.0 FALSE:4315
## Median : 0.0 Median : 0.0 Median : 0.0 TRUE :4378
## Mean : 169.6 Mean : 304.6 Mean : 298.3
## 3rd Qu.: 22.0 3rd Qu.: 53.0 3rd Qu.: 40.0
## Max. :23492.0 Max. :22408.0 Max. :24133.0
##
## withgroup deck side expense
## Min. :0.0000 F :2832 P:4335 Min. : 0
## 1st Qu.:0.0000 G :2648 S:4358 1st Qu.: 0
## Median :0.0000 E : 881 Median : 716
## Mean :0.4473 B : 825 Mean : 1441
## 3rd Qu.:1.0000 C : 758 3rd Qu.: 1441
## Max. :1.0000 D : 483 Max. :35987
## (Other): 266
## PassengerId HomePlanet CryoSleep Destination
## Length:8693 Europa:2174 FALSE:5581 55 Cancri e :1800
## Class :character Earth :4743 TRUE :3112 PSO J318.5-22: 796
## Mode :character Mars :1776 TRAPPIST-1e :6097
##
##
##
##
## Age VIP RoomService FoodCourt
## Min. : 0.00 Mode :logical Min. : 0 Min. : 0.0
## 1st Qu.:20.00 FALSE:8494 1st Qu.: 0 1st Qu.: 0.0
## Median :27.00 TRUE :199 Median : 0 Median : 0.0
## Mean :28.84 Mean : 220 Mean : 448.4
## 3rd Qu.:37.00 3rd Qu.: 41 3rd Qu.: 61.0
## Max. :79.00 Max. :14327 Max. :29813.0
##
## ShoppingMall Spa VRDeck Transported
## Min. : 0.0 Min. : 0.0 Min. : 0.0 Mode :logical
## 1st Qu.: 0.0 1st Qu.: 0.0 1st Qu.: 0.0 FALSE:4315
## Median : 0.0 Median : 0.0 Median : 0.0 TRUE :4378
## Mean : 169.6 Mean : 304.6 Mean : 298.3
## 3rd Qu.: 22.0 3rd Qu.: 53.0 3rd Qu.: 40.0
## Max. :23492.0 Max. :22408.0 Max. :24133.0
##
## withgroup deck side expense omePlanet
## Min. :0.0000 F :2832 P:4335 Min. : 0 Europa:2174
## 1st Qu.:0.0000 G :2648 S:4358 1st Qu.: 0 Earth :4743
## Median :0.0000 E : 881 Median : 716 Mars :1776
## Mean :0.4473 B : 825 Mean : 1441
## 3rd Qu.:1.0000 C : 758 3rd Qu.: 1441
## Max. :1.0000 D : 483 Max. :35987
## (Other): 266
## # 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 8693 NA NA NA
## 2 HomePlanet chr 0 0 3 NA NA NA
## 3 CryoSleep lgl 0 0 2 0 0.36 1
## 4 Destination chr 0 0 3 NA NA NA
## 5 Age dbl 0 0 88 0 28.8 79
## 6 VIP lgl 0 0 2 0 0.02 1
## 7 RoomService int 0 0 1273 0 220. 14327
## 8 FoodCourt int 0 0 1507 0 448. 29813
## 9 ShoppingMall int 0 0 1115 0 170. 23492
## 10 Spa int 0 0 1327 0 305. 22408
## 11 VRDeck int 0 0 1306 0 298. 24133
## 12 Transported lgl 0 0 2 0 0.5 1
## 13 withgroup int 0 0 2 0 0.45 1
## 14 deck chr 0 0 8 NA NA NA
## 15 side chr 0 0 2 NA NA NA
## 16 expense int 0 0 2336 0 1441. 35987
## # 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 chr 0 0 3 NA NA NA
## 3 CryoSleep lgl 0 0 2 0 0.36 1
## 4 Destination chr 0 0 3 NA NA NA
## 5 Age dbl 0 0 88 0 28.8 79
## 6 VIP lgl 0 0 2 0 0.02 1
## 7 RoomService int 0 0 1273 0 220. 14327
## 8 FoodCourt int 0 0 1507 0 448. 29813
## 9 ShoppingMall int 0 0 1115 0 170. 23492
## 10 Spa int 0 0 1327 0 305. 22408
## 11 VRDeck int 0 0 1306 0 298. 24133
## 12 Transported lgl 0 0 2 0 0.5 1
## 13 withgroup int 0 0 2 0 0.45 1
## 14 deck chr 0 0 8 NA NA NA
## 15 side chr 0 0 2 NA NA NA
## 16 expense int 0 0 2336 0 1441. 35987
## 17 omePlanet chr 0 0 3 NA NA NA
train$HomePlanet <- as.factor(train$HomePlanet)
train$Destination <- as.factor(train$Destination)
train$PassengerId <- as.factor(train$PassengerId)
train$deck <- as.factor(train$deck)
train$side <- as.factor(train$side)test$HomePlanet <- as.factor(test$HomePlanet)
test$Destination <- as.factor(test$Destination)
test$deck <- as.factor(test$deck)
test$side <- as.factor(test$side)
test$PassengerId <- as.factor(test$PassengerId)## # A tibble: 16 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId fct 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 3 NA NA NA
## 3 CryoSleep lgl 0 0 2 0 0.36 1
## 4 Destination fct 0 0 3 NA NA NA
## 5 Age dbl 0 0 88 0 28.8 79
## 6 VIP lgl 0 0 2 0 0.02 1
## 7 RoomService int 0 0 1273 0 220. 14327
## 8 FoodCourt int 0 0 1507 0 448. 29813
## 9 ShoppingMall int 0 0 1115 0 170. 23492
## 10 Spa int 0 0 1327 0 305. 22408
## 11 VRDeck int 0 0 1306 0 298. 24133
## 12 Transported lgl 0 0 2 0 0.5 1
## 13 withgroup int 0 0 2 0 0.45 1
## 14 deck fct 0 0 8 NA NA NA
## 15 side fct 0 0 2 NA NA NA
## 16 expense int 0 0 2336 0 1441. 35987
## # A tibble: 17 × 8
## variable type na na_pct unique min mean max
## <chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
## 1 PassengerId fct 0 0 8693 NA NA NA
## 2 HomePlanet fct 0 0 3 NA NA NA
## 3 CryoSleep lgl 0 0 2 0 0.36 1
## 4 Destination fct 0 0 3 NA NA NA
## 5 Age dbl 0 0 88 0 28.8 79
## 6 VIP lgl 0 0 2 0 0.02 1
## 7 RoomService int 0 0 1273 0 220. 14327
## 8 FoodCourt int 0 0 1507 0 448. 29813
## 9 ShoppingMall int 0 0 1115 0 170. 23492
## 10 Spa int 0 0 1327 0 305. 22408
## 11 VRDeck int 0 0 1306 0 298. 24133
## 12 Transported lgl 0 0 2 0 0.5 1
## 13 withgroup int 0 0 2 0 0.45 1
## 14 deck fct 0 0 8 NA NA NA
## 15 side fct 0 0 2 NA NA NA
## 16 expense int 0 0 2336 0 1441. 35987
## 17 omePlanet chr 0 0 3 NA NA NA
## corrplot 0.92 loaded
library(DataExplorer)
create_report(train)
##
## Call:
## lm(formula = Transported ~ ., data = train[, 2:16])
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.48097 -0.30495 -0.02786 0.28279 1.75905
##
## Coefficients: (1 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.046e-01 4.003e-02 7.609 3.05e-14 ***
## HomePlanetEuropa 2.110e-01 2.864e-02 7.367 1.91e-13 ***
## HomePlanetMars 8.968e-02 1.479e-02 6.062 1.40e-09 ***
## CryoSleepTRUE 3.901e-01 1.158e-02 33.680 < 2e-16 ***
## DestinationPSO J318.5-22 -4.323e-02 1.802e-02 -2.400 0.016438 *
## DestinationTRAPPIST-1e -4.570e-02 1.128e-02 -4.051 5.14e-05 ***
## Age -2.217e-03 3.192e-04 -6.947 4.00e-12 ***
## VIPTRUE -3.367e-02 2.967e-02 -1.135 0.256466
## RoomService -1.147e-04 7.050e-06 -16.269 < 2e-16 ***
## FoodCourt 4.403e-05 3.053e-06 14.422 < 2e-16 ***
## ShoppingMall 8.240e-05 7.448e-06 11.063 < 2e-16 ***
## Spa -8.531e-05 4.106e-06 -20.777 < 2e-16 ***
## VRDeck -8.127e-05 4.109e-06 -19.776 < 2e-16 ***
## withgroup 1.999e-02 9.260e-03 2.159 0.030867 *
## deckB 1.076e-01 2.866e-02 3.755 0.000175 ***
## deckC 1.442e-01 2.893e-02 4.986 6.28e-07 ***
## deckD 5.455e-02 3.462e-02 1.575 0.115193
## deckE 1.033e-02 3.602e-02 0.287 0.774351
## deckF 1.074e-01 3.693e-02 2.907 0.003655 **
## deckG 5.576e-02 3.855e-02 1.446 0.148098
## deckT 6.774e-02 1.810e-01 0.374 0.708306
## sideS 8.559e-02 8.606e-03 9.946 < 2e-16 ***
## expense NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4001 on 8671 degrees of freedom
## Multiple R-squared: 0.3612, Adjusted R-squared: 0.3596
## F-statistic: 233.4 on 21 and 8671 DF, p-value: < 2.2e-16
library(caTools)
set.seed(123)
split = sample.split(train$Transported,SplitRatio = 0.75)
train_train = subset(train, split == TRUE)
train_test = subset(train, split == FALSE)##
## Call:
## lm(formula = Transported ~ ., data = train_train[, -c(1)])
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.55277 -0.30795 -0.02772 0.28588 1.74204
##
## Coefficients: (1 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.373e-01 4.627e-02 7.290 3.46e-13 ***
## HomePlanetEuropa 1.979e-01 3.338e-02 5.927 3.25e-09 ***
## HomePlanetMars 8.044e-02 1.706e-02 4.715 2.46e-06 ***
## CryoSleepTRUE 3.849e-01 1.335e-02 28.834 < 2e-16 ***
## DestinationPSO J318.5-22 -6.053e-02 2.076e-02 -2.915 0.003563 **
## DestinationTRAPPIST-1e -5.053e-02 1.304e-02 -3.876 0.000107 ***
## Age -2.382e-03 3.714e-04 -6.414 1.52e-10 ***
## VIPTRUE -1.268e-02 3.376e-02 -0.375 0.707329
## RoomService -1.147e-04 7.788e-06 -14.729 < 2e-16 ***
## FoodCourt 4.005e-05 3.466e-06 11.555 < 2e-16 ***
## ShoppingMall 8.546e-05 8.407e-06 10.166 < 2e-16 ***
## Spa -8.430e-05 4.704e-06 -17.921 < 2e-16 ***
## VRDeck -8.077e-05 4.771e-06 -16.930 < 2e-16 ***
## withgroup 1.620e-02 1.073e-02 1.510 0.130979
## deckB 1.003e-01 3.283e-02 3.057 0.002248 **
## deckC 1.388e-01 3.311e-02 4.193 2.78e-05 ***
## deckD 3.548e-02 3.952e-02 0.898 0.369332
## deckE -1.945e-02 4.186e-02 -0.465 0.642212
## deckF 8.940e-02 4.267e-02 2.095 0.036188 *
## deckG 4.025e-02 4.456e-02 0.903 0.366367
## deckT 5.872e-02 1.818e-01 0.323 0.746676
## sideS 8.994e-02 9.958e-03 9.033 < 2e-16 ***
## expense NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4003 on 6498 degrees of freedom
## Multiple R-squared: 0.3611, Adjusted R-squared: 0.3591
## F-statistic: 174.9 on 21 and 6498 DF, p-value: < 2.2e-16
## reg_transported_tahmin
## transported_gercek 0 1
## 0 904 175
## 1 320 774
## [1] 0.7722043
## reg_transported_tahmin
## transported_gercek 0 1
## 0 2673 563
## 1 936 2348
## [1] 0.770092
## Le chargement a nécessité le package : rJava
## Le chargement a nécessité le package : leaps
regresyon_opt <- glmulti(Transpoted ~ HomePlanet + CryoSleep + Destination + Age +VIP
+ RoomService + FoodCourt + ShoppingMall + Spa + VRDeck + winthgroup + deck + side, level =
1, crit = bic, data = train)
modelglmulti <- lm(Transported ~ 1 + HomePlanet + Destination + deck + side + CryoSleep + Age + RoomService + FoodCourt + ShoppingMall + Spa + VRDeck, data = train)
write.csv(submission_regresyon_glmulti, "submission_regresyon_glmulti.csv",
row. names =FALSE, quote=FALSE)
modellog <- lm(Transported ~ 1 + HomePlanet + Destination + deck + side + CryoSleep + Age + RoomService + FoodCourt + ShoppingMall + Spa + VRDeck, data = train_log)write.csv(submission_regresyon_log, "submission_regresyon_log.csv", row.names = FALSE,
quote = FALSE)## Warning: glm.fit: des probabilités ont été ajustées numériquement à 0 ou 1
##
## Call:
## glm(formula = Transported ~ ., family = binomial, data = train_train[,
## -c(1)])
##
## Coefficients: (1 not defined because of singularities)
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -4.737e-01 3.584e-01 -1.322 0.186261
## HomePlanetEuropa 1.533e+00 2.654e-01 5.775 7.72e-09 ***
## HomePlanetMars 5.094e-01 1.112e-01 4.580 4.65e-06 ***
## CryoSleepTRUE 1.297e+00 9.304e-02 13.942 < 2e-16 ***
## DestinationPSO J318.5-22 -4.995e-01 1.299e-01 -3.844 0.000121 ***
## DestinationTRAPPIST-1e -4.608e-01 9.424e-02 -4.889 1.01e-06 ***
## Age -8.758e-03 2.463e-03 -3.555 0.000378 ***
## VIPTRUE -1.507e-01 2.917e-01 -0.517 0.605422
## RoomService -1.711e-03 1.136e-04 -15.059 < 2e-16 ***
## FoodCourt 4.582e-04 4.450e-05 10.297 < 2e-16 ***
## ShoppingMall 5.436e-04 7.623e-05 7.131 9.95e-13 ***
## Spa -1.947e-03 1.166e-04 -16.707 < 2e-16 ***
## VRDeck -1.876e-03 1.155e-04 -16.241 < 2e-16 ***
## withgroup 1.231e-01 7.188e-02 1.712 0.086855 .
## deckB 1.113e+00 2.896e-01 3.842 0.000122 ***
## deckC 2.427e+00 3.314e-01 7.325 2.39e-13 ***
## deckD 6.808e-01 3.245e-01 2.098 0.035935 *
## deckE 8.476e-02 3.347e-01 0.253 0.800066
## deckF 7.591e-01 3.393e-01 2.237 0.025257 *
## deckG 3.459e-01 3.489e-01 0.991 0.321465
## deckT -1.204e-01 1.854e+00 -0.065 0.948224
## sideS 6.035e-01 6.668e-02 9.051 < 2e-16 ***
## expense NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 9038.3 on 6519 degrees of freedom
## Residual deviance: 5599.8 on 6498 degrees of freedom
## AIC: 5643.8
##
## Number of Fisher Scoring iterations: 7
## 2 3 7 14 16 21
## -1.1025143 -10.9381357 0.9585015 -1.6451179 -0.4385553 -1.6923796
## ── Attaching packages ────────────────────────────────────── tidymodels 1.2.0 ──
## ✔ broom 1.0.5 ✔ rsample 1.2.1
## ✔ dials 1.2.1 ✔ tune 1.2.1
## ✔ infer 1.0.7 ✔ workflows 1.1.4
## ✔ modeldata 1.3.0 ✔ workflowsets 1.1.0
## ✔ parsnip 1.2.1 ✔ yardstick 1.3.1
## ✔ recipes 1.0.10
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ scales::discard() masks purrr::discard()
## ✖ dplyr::filter() masks stats::filter()
## ✖ recipes::fixed() masks stringr::fixed()
## ✖ dplyr::lag() masks stats::lag()
## ✖ yardstick::spec() masks readr::spec()
## ✖ recipes::step() masks stats::step()
## • Search for functions across packages at https://www.tidymodels.org/find/
result$Transported <- as.factor(result$Transported)
result$logistic_Transpoted_tahmin <- as.factor(result$logistic_Transpoted_tahmin)## # A tibble: 1 × 3
## .metric .estimator .estimate
## <chr> <chr> <dbl>
## 1 accuracy binary 0.782
## Truth
## Prediction 0 1
## 0 918 312
## 1 161 782
## Le chargement a nécessité le package : lattice
##
## Attachement du package : 'caret'
## Les objets suivants sont masqués depuis 'package:yardstick':
##
## precision, recall, sensitivity, specificity
## L'objet suivant est masqué depuis 'package:purrr':
##
## lift
## logistic_Transpoted_tahmin
## transported_gercek 0 1
## 0 918 161
## 1 312 782
## Warning: glm.fit: des probabilités ont été ajustées numériquement à 0 ou 1
Naive bayes
##
## Attachement du package : 'e1071'
## L'objet suivant est masqué depuis 'package:tune':
##
## tune
## L'objet suivant est masqué depuis 'package:rsample':
##
## permutations
## L'objet suivant est masqué depuis 'package:parsnip':
##
## tune
##
## Naive Bayes Classifier for Discrete Predictors
##
## Call:
## naiveBayes.default(x = X, y = Y, laplace = laplace)
##
## A-priori probabilities:
## Y
## FALSE TRUE
## 0.496319 0.503681
##
## Conditional probabilities:
## HomePlanet
## Y Earth Europa Mars
## FALSE 0.6220643 0.1755253 0.2024104
## TRUE 0.4604141 0.3306943 0.2088916
##
## CryoSleep
## Y FALSE TRUE
## FALSE 0.8652658 0.1347342
## TRUE 0.4205238 0.5794762
##
## Destination
## Y 55 Cancri e PSO J318.5-22 TRAPPIST-1e
## FALSE 0.16069221 0.09363412 0.74567367
## TRUE 0.24969549 0.09043849 0.65986602
##
## Age
## Y [,1] [,2]
## FALSE 30.01119 13.45225
## TRUE 27.85293 14.87588
##
## VIP
## Y FALSE TRUE
## FALSE 0.97126082 0.02873918
## TRUE 0.98142509 0.01857491
##
## RoomService
## Y [,1] [,2]
## FALSE 402.20365 916.6547
## TRUE 56.93484 246.8105
##
## FoodCourt
## Y [,1] [,2]
## FALSE 396.2923 1258.123
## TRUE 514.8018 1918.620
##
## ShoppingMall
## Y [,1] [,2]
## FALSE 160.2250 432.1103
## TRUE 182.7135 748.5867
##
## Spa
## Y [,1] [,2]
## FALSE 561.16193 1554.2636
## TRUE 61.11571 264.0556
##
## VRDeck
## Y [,1] [,2]
## FALSE 533.98733 1542.8703
## TRUE 69.07186 295.0542
##
## withgroup
## Y [,1] [,2]
## FALSE 0.3952410 0.4889780
## TRUE 0.4960414 0.5000605
##
## deck
## Y A B C D E
## FALSE 0.0296662546 0.0543881335 0.0574783684 0.0661310260 0.1344252163
## TRUE 0.0310596833 0.1385505481 0.1199756395 0.0490255786 0.0676004872
## deck
## Y F G T
## FALSE 0.3637206428 0.2929542645 0.0012360939
## TRUE 0.2828867235 0.3105968331 0.0003045067
##
## side
## Y P S
## FALSE 0.5568603 0.4431397
## TRUE 0.4448843 0.5551157
##
## expense
## Y [,1] [,2]
## FALSE 2053.8702 3224.219
## TRUE 884.6376 2307.962
## FALSE. TRUE.
## 1 0.22726191 7.727381e-01
## 2 1.00000000 8.444155e-135
## 3 0.02805365 9.719464e-01
## 4 0.59934478 4.006552e-01
## 5 0.02471507 9.752849e-01
## 6 0.39125602 6.087440e-01
## Transported_pred_nb
## Transported_train_test 0 1
## 0 482 597
## 1 77 1017
## [1] 0.6898297
Transported <- as.character(Transported_pred_nb)
PassengerId <- test$PassengerId
Transported <- as.vector(Transported)
sample_submission <- cbind(PassengerId,Transported)
sample_submission <- as.data.frame(sample_submission)
sample_submission$Transported <- str_to_title(sample_submission$Transported)
write.csv(sample_submission,"sub_nb.csv",row.names = FALSE, quote = FALSE)SVM
fit_svm <- svm(Transported ~ ., data = train_train[, -1], type= 'C-classification',
kernel = 'linear' )
preds <- predict(fit_svm, newdata= train_test[, -c(1,12)], type= "raw") %>% data.frame()Transported_pred_svm = ifelse(preds$.== TRUE, 1,0)
cm = table(Transported_train_test,Transported_pred_svm)## Transported_pred_svm
## Transported_train_test 0 1
## 0 841 238
## 1 193 901
## [1] 0.8021169
fit_svm <- svm(Transported ~ ., data = train[, -1],
type= 'C-classification',
kernel = 'linear' )
preds <- predict(fit_svm, newdata= test, type= "raw") %>% data.frame()Transported <- as.character(Transported_pred_svm)
PassengerId <- test$PassengerId
Transported <- as.vector(Transported)
sample_submission <- cbind(PassengerId,Transported)
sample_submission <- as.data.frame(sample_submission)
sample_submission$Transported <- str_to_title(sample_submission$Transported)
write.csv(sample_submission,"sub_svm.csv",row.names = FALSE, quote = FALSE)