2912 yılına hoş geldiniz. Veri bilimi becerilerinize kozmik bir gizemi çözmek için ihtiyaç duyuluyor. Dört ışık yılı uzaklıktan bir iletim aldık ve işler pek de iyi görünmüyor.
Spaceship Titanic, bir ay önce fırlatılan yıldızlararası bir yolcu gemisiydi. Neredeyse 13.000 yolcuyu taşıyan gemi, göçmenleri güneş sistemimizden, yakındaki yıldızların etrafında dönen üç yeni yaşanabilir ötegezegene götürmek üzere ilk yolculuğuna çıkmıştı.
İlk durağı olan kavurucu 55 Cancri E’ye giderken, gemi Alpha Centauri yakınlarında bir toz bulutunun içinde gizlenmiş bir uzay-zaman anomalisiyle çarpıştı. Ne yazık ki, bin yıl önceki adaşıyla benzer bir kaderi paylaştı. Gemi bütünlüğünü korumuş olsa da, yolcuların neredeyse yarısı alternatif bir boyuta taşındı!
Kurtarma ekiplerine yardımcı olmak ve kaybolan yolcuları geri getirmek için, uzay gemisinin hasar görmüş bilgisayar sisteminden kurtarılan kayıtları kullanarak hangi yolcuların anomali tarafından taşındığını tahmin etmeniz isteniyor.
Onları kurtarın ve tarihi değiştirin!
library(readr)train <-read_csv("train.csv")
Rows: 8693 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): PassengerId, HomePlanet, Cabin, Destination, Name
dbl (6): Age, RoomService, FoodCourt, ShoppingMall, Spa, VRDeck
lgl (3): CryoSleep, VIP, Transported
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
test <-read_csv("test.csv")
Rows: 4277 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): PassengerId, HomePlanet, Cabin, Destination, Name
dbl (6): Age, RoomService, FoodCourt, ShoppingMall, Spa, VRDeck
lgl (2): CryoSleep, VIP
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Dosya ve Veri Alanı Açıklamaları
train.csv - Eğitim verisi olarak kullanılacak yolcuların yaklaşık üçte ikisinin (yaklaşık 8700) kişisel kayıtları.
PassengerId - Her yolcu için benzersiz bir kimlik. Her kimlik, gggg_pp biçimini alır; burada gggg, yolcunun seyahat ettiği grubu, pp ise grup içindeki numarasını belirtir. Bir gruptaki kişiler genellikle aile üyeleridir, ancak her zaman değil.
HomePlanet - Yolcunun ayrıldığı gezegen, genellikle daimi ikamet ettiği gezegen.
Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
dplyr 1.1.0.
ℹ Please use `reframe()` instead.
ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
always returns an ungrouped data frame and adjust accordingly.
`summarise()` has grouped output by 'Aile'. You can override using the
`.groups` argument.
library(explore)describe_all(inceleme2)
# A tibble: 6 × 8
variable type na na_pct unique min mean max
<chr> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl>
1 Aile chr 0 0 6107 NA NA NA
2 uye_s int 0 0 8 1 1.41 8
3 bos_sayisi int 0 0 3 0 0.01 2
4 bosolamyan_sayisi int 0 0 8 1 1.39 8
5 farkli_gezegen int 0 0 1 1 1 1
6 gezegen_adi chr 0 0 3 NA NA NA
train2 <-left_join(train2,inceleme2)
Joining with `by = join_by(Aile)`
HomePlanet ve Destination
library(dplyr)library(tidyr)# 1. Mod (en sık görülen değer) bulma fonksiyonuget_mode <-function(x) { x <- x[!is.na(x)]if (length(x) ==0) return(NA) ux <-unique(x) ux[which.max(tabulate(match(x, ux)))]}# 2. Veri setini düzenletrain2 <- train %>%separate(PassengerId, sep ="_", into =c("Aile", "KisiNo"), remove =FALSE) %>%separate(Name, sep =" ", into =c("Ad", "Soyad"), remove =FALSE)# 3. Genel mod değerlerimod_homeplanet <-get_mode(train2$HomePlanet)mod_destination <-get_mode(train2$Destination)# 4. Aile bazında doldurma işlemitrain2 <- train2 %>%group_by(Aile) %>%mutate(grup_boyutu =n(),# Ailede HomePlanet bilgisi varsa, onu kullan; yoksa genel modHomePlanet =ifelse(is.na(HomePlanet),ifelse(all(is.na(HomePlanet)), mod_homeplanet,first(HomePlanet[!is.na(HomePlanet)]) ), HomePlanet ),# Ailede Destination bilgisi varsa, onu kullan; yoksa genel modDestination =ifelse(is.na(Destination),ifelse(all(is.na(Destination)), mod_destination,first(Destination[!is.na(Destination)]) ), Destination ) ) %>%ungroup() %>%select(-grup_boyutu)
train2 %>%is.na() %>%colSums()
PassengerId Aile KisiNo HomePlanet CryoSleep Cabin
0 0 0 0 217 199
Destination Age VIP RoomService FoodCourt ShoppingMall
0 179 203 181 183 208
Spa VRDeck Name Ad Soyad Transported
183 188 200 200 200 0
Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
dplyr 1.1.0.
ℹ Please use `reframe()` instead.
ℹ When switching from `summarise()` to `reframe()`, remember that `reframe()`
always returns an ungrouped data frame and adjust accordingly.
`summarise()` has grouped output by 'Aile'. You can override using the
`.groups` argument.
vip_01 <-sum(train4$uye_s >1& train4$VIP ==TRUE , na.rm = T)vip_02 <-sum(train4$uye_s >1& train4$VIP ==FALSE , na.rm = T)train4 <- train4 %>%group_by(uye_s) %>%# aynı gruptaki üyeleri birlikte ele almutate(VIP =ifelse(is.na(VIP) & uye_s >1, first(na.omit(VIP)), # gruptaki boş olmayan ilk değeri al VIP), )
# train4 <- train4 %>% group_by(uye_s) %>% # aynı gruptaki üyeleri birlikte ele al# mutate(VIP = ifelse(is.na(VIP) & uye_s > 1, # first(na.omit(VIP)), # gruptaki boş olmayan ilk değeri al# VIP),# )
# A tibble: 12 × 2
# Groups: HomePlanet, Destination [12]
HomePlanet Destination
<chr> <chr>
1 Europa TRAPPIST-1e
2 Earth TRAPPIST-1e
3 Earth PSO J318.5-22
4 Europa 55 Cancri e
5 Mars TRAPPIST-1e
6 Mars 55 Cancri e
7 Earth 55 Cancri e
8 Mars <NA>
9 Mars PSO J318.5-22
10 Earth <NA>
11 Europa PSO J318.5-22
12 Europa <NA>
Warning in plot.aggr(res, ...): not enough vertical space to display
frequencies (too many combinations)
Variables sorted by number of missings:
Variable Count
CryoSleep 0.02496261
ShoppingMall 0.02392730
VIP 0.02335212
HomePlanet 0.02312205
Name 0.02300702
Cabin 0.02289198
VRDeck 0.02162660
FoodCourt 0.02105142
Spa 0.02105142
Destination 0.02093639
RoomService 0.02082135
Age 0.02059128
PassengerId 0.00000000
Transported 0.00000000
library(naniar)
Присоединяю пакет: 'naniar'
Следующий объект скрыт от 'package:explore':
replace_na_with
gg_miss_upset(train, nsets =ncol(train))
Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
ℹ Please use tidy evaluation idioms with `aes()`.
ℹ See also `vignette("ggplot2-in-packages")` for more information.
ℹ The deprecated feature was likely used in the UpSetR package.
Please report the issue to the authors.
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
ℹ The deprecated feature was likely used in the UpSetR package.
Please report the issue to the authors.
Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
ℹ Please use the `linewidth` argument instead.
ℹ The deprecated feature was likely used in the UpSetR package.
Please report the issue to the authors.
# 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 6519 NA NA NA
2 HomePlanet chr 0 0 3 NA NA NA
3 CryoSleep lgl 0 0 2 0 0.35 1
4 Cabin chr 0 0 5153 NA NA NA
5 Destination chr 0 0 3 NA NA NA
6 Age dbl 0 0 81 0 28.8 79
7 VIP lgl 0 0 2 0 0.03 1
8 RoomService dbl 0 0 1086 0 221. 9920
9 FoodCourt dbl 0 0 1239 0 458. 29813
10 ShoppingMall dbl 0 0 962 0 176. 23492
11 Spa dbl 0 0 1104 0 311. 22408
12 VRDeck dbl 0 0 1095 0 301. 24133
13 Transported lgl 0 0 2 0 0.5 1
sonra factor seviyelerini koru
# for (col in names(train5_train)) {# if (is.factor(train5_train[[col]])) {# train5_test[[col]] <- factor(train5_test[[col]], levels = levels(train5_train[[col]]))# }# }
Regresyon Modelleri olustur
library(recipes)
Присоединяю пакет: 'recipes'
Следующий объект скрыт от 'package:VIM':
prepare
Следующий объект скрыт от 'package:stringr':
fixed
Следующий объект скрыт от 'package:stats':
step
# 1️⃣ Recipe oluştur, tüm kategorik değişkenlerde yeni seviyeleri "other" yaprec <-recipe(Transported ~ . , data = train5_train) %>%step_other(all_nominal(), threshold =0.01) # %1'den az görülen veya yeni seviyeler "other"# 2️⃣ Recipe'i eğitrec_prep <-prep(rec, training = train5_train)# 3️⃣ Train ve Test setlerini dönüştürtrain_transformed <-bake(rec_prep, new_data = train5_train)test_transformed <-bake(rec_prep, new_data = train5_test)