Spaceship Titanic

Kozmik bir gizemi çözmek için veri bilimi becerilerinize ihtiyaç duyulan 2912 yılına hoş geldiniz. Dört ışık yılı öteden bir sinyal aldık ve işler pek iyi görünmüyor.

Uzay Gemisi Titanik, bir ay önce fırlatılan yıldızlararası bir yolcu gemisiydi. Gemide neredeyse 13.000 yolcu bulunan gemi, güneş sistemimizden göçmenleri yakın yıldızların yörüngesinde bulunan üç yeni yaşanabilir dış gezegene taşımak üzere ilk yolculuğuna çıktı.

Dikkatsiz Uzay Gemisi Titanic, ilk varış noktası olan kavurucu 55 Cancri E’ye giderken Alpha Centauri’yi dönerken, bir toz bulutunun içine gizlenmiş bir uzay-zaman anormalliğiyle çarpıştı. Ne yazık ki 1000 yıl öncesindeki adaşı ile benzer bir kaderle karşılaştı. Gemi sağlam kalmasına rağmen yolcuların neredeyse yarısı alternatif bir boyuta taşındı!

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.

İlk önce elimizdeki train datasını library kodunu kullanarak R yüklememiz gerekiyor.

str(train)
## spc_tbl_ [8,693 × 14] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ PassengerId : chr [1:8693] "0001_01" "0002_01" "0003_01" "0003_02" ...
##  $ HomePlanet  : chr [1:8693] "Europa" "Earth" "Europa" "Europa" ...
##  $ CryoSleep   : logi [1:8693] FALSE FALSE FALSE FALSE FALSE FALSE ...
##  $ Cabin       : chr [1:8693] "B/0/P" "F/0/S" "A/0/S" "A/0/S" ...
##  $ Destination : chr [1:8693] "TRAPPIST-1e" "TRAPPIST-1e" "TRAPPIST-1e" "TRAPPIST-1e" ...
##  $ Age         : num [1:8693] 39 24 58 33 16 44 26 28 35 14 ...
##  $ VIP         : logi [1:8693] FALSE FALSE TRUE FALSE FALSE FALSE ...
##  $ RoomService : num [1:8693] 0 109 43 0 303 0 42 0 0 0 ...
##  $ FoodCourt   : num [1:8693] 0 9 3576 1283 70 ...
##  $ ShoppingMall: num [1:8693] 0 25 0 371 151 0 3 0 17 0 ...
##  $ Spa         : num [1:8693] 0 549 6715 3329 565 ...
##  $ VRDeck      : num [1:8693] 0 44 49 193 2 0 0 NA 0 0 ...
##  $ Name        : chr [1:8693] "Maham Ofracculy" "Juanna Vines" "Altark Susent" "Solam Susent" ...
##  $ Transported : logi [1:8693] FALSE TRUE FALSE FALSE TRUE TRUE ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   PassengerId = col_character(),
##   ..   HomePlanet = col_character(),
##   ..   CryoSleep = col_logical(),
##   ..   Cabin = col_character(),
##   ..   Destination = col_character(),
##   ..   Age = col_double(),
##   ..   VIP = col_logical(),
##   ..   RoomService = col_double(),
##   ..   FoodCourt = col_double(),
##   ..   ShoppingMall = col_double(),
##   ..   Spa = col_double(),
##   ..   VRDeck = col_double(),
##   ..   Name = col_character(),
##   ..   Transported = col_logical()
##   .. )
##  - attr(*, "problems")=<externalptr>

Daha sonra str kodunu kullanarak veri setimizdeki kaç tane gözlem olduğunu ve ne anlama geldiğini öğrenelim.

library(DataExplorer)
create_report(train)
## 
## 
## processing file: report.rmd
## 
  |                                           
  |                                     |   0%
  |                                           
  |.                                    |   2%                                 
  |                                           
  |..                                   |   5% [global_options]                
  |                                           
  |...                                  |   7%                                 
  |                                           
  |....                                 |  10% [introduce]                     
  |                                           
  |....                                 |  12%                                 
  |                                           
  |.....                                |  14% [plot_intro]                    
  |                                           
  |......                               |  17%                                 
  |                                           
  |.......                              |  19% [data_structure]                
  |                                           
  |........                             |  21%                                 
  |                                           
  |.........                            |  24% [missing_profile]               
  |                                           
  |..........                           |  26%                                 
  |                                           
  |...........                          |  29% [univariate_distribution_header]
  |                                           
  |...........                          |  31%                                 
  |                                           
  |............                         |  33% [plot_histogram]                
  |                                           
  |.............                        |  36%                                 
  |                                           
  |..............                       |  38% [plot_density]                  
  |                                           
  |...............                      |  40%                                 
  |                                           
  |................                     |  43% [plot_frequency_bar]            
  |                                           
  |.................                    |  45%                                 
  |                                           
  |..................                   |  48% [plot_response_bar]             
  |                                           
  |..................                   |  50%                                 
  |                                           
  |...................                  |  52% [plot_with_bar]                 
  |                                           
  |....................                 |  55%                                 
  |                                           
  |.....................                |  57% [plot_normal_qq]                
  |                                           
  |......................               |  60%                                 
  |                                           
  |.......................              |  62% [plot_response_qq]              
  |                                           
  |........................             |  64%                                 
  |                                           
  |.........................            |  67% [plot_by_qq]                    
  |                                           
  |..........................           |  69%                                 
  |                                           
  |..........................           |  71% [correlation_analysis]          
  |                                           
  |...........................          |  74%                                 
  |                                           
  |............................         |  76% [principal_component_analysis]  
  |                                           
  |.............................        |  79%                                 
  |                                           
  |..............................       |  81% [bivariate_distribution_header] 
  |                                           
  |...............................      |  83%                                 
  |                                           
  |................................     |  86% [plot_response_boxplot]         
  |                                           
  |.................................    |  88%                                 
  |                                           
  |.................................    |  90% [plot_by_boxplot]               
  |                                           
  |..................................   |  93%                                 
  |                                           
  |...................................  |  95% [plot_response_scatterplot]     
  |                                           
  |.................................... |  98%                                 
  |                                           
  |.....................................| 100% [plot_by_scatterplot]           
## output file: /cloud/project/report.knit.md
## /usr/lib/rstudio-server/bin/quarto/bin/tools/pandoc +RTS -K512m -RTS /cloud/project/report.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output /cloud/project/report.html --lua-filter /cloud/lib/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /cloud/lib/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/latex-div.lua --embed-resources --standalone --variable bs3=TRUE --section-divs --table-of-contents --toc-depth 6 --template /cloud/lib/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --variable theme=yeti --mathjax --variable 'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' --include-in-header /tmp/Rtmpa8dFbb/rmarkdown-stre8444f64bbd.html
## 
## Output created: report.html

Oluşturulan verilerin raporunu görmek için ilk önce paket bölümünden DataExplorer paketi yüklenir ve library kodu kullanılarak R a yükleriz. Daha sonra create_report kodu ile train data verisinin tablosu çıkarılır.

ilkaltısütun<- train[,1:6]

veride ilk 6 sütunu görmek için yukarıdaki kodu kullanırız.

ilkaltısütun1<- train[,c(1:6,14)]

ilk 6 sütuna ek olarak farklı bir sütun eklemek için yukarıdaki kodu kullanırız.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ purrr     1.0.2
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::between()     masks data.table::between()
## ✖ dplyr::filter()      masks stats::filter()
## ✖ dplyr::first()       masks data.table::first()
## ✖ lubridate::hour()    masks data.table::hour()
## ✖ lubridate::isoweek() masks data.table::isoweek()
## ✖ dplyr::lag()         masks stats::lag()
## ✖ dplyr::last()        masks data.table::last()
## ✖ lubridate::mday()    masks data.table::mday()
## ✖ lubridate::minute()  masks data.table::minute()
## ✖ lubridate::month()   masks data.table::month()
## ✖ lubridate::quarter() masks data.table::quarter()
## ✖ lubridate::second()  masks data.table::second()
## ✖ purrr::transpose()   masks data.table::transpose()
## ✖ lubridate::wday()    masks data.table::wday()
## ✖ lubridate::week()    masks data.table::week()
## ✖ lubridate::yday()    masks data.table::yday()
## ✖ lubridate::year()    masks data.table::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(explore)

Data verimizde kaç tane NA olduğu ve ortalamayı göstermek için aşağıdaki kodu kullanırız.

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

Data verisindeki passengerId sütununu ailenumarası ve ailesıra numarası olarak ayırmak için aşağıdaki kodu kullanıyoruz.

train$ailenum<- str_split_fixed(train$PassengerId, "_",2)

Yukarıdaki işlemin ikinci yolu olarak aşağıdaki kodu kullanabilriz.

train[c('ailenum','ailesıra')]<- str_split_fixed(train$PassengerId, "_",2)

Ailenum ve Ailesıra sütununu veride başa almak için aşağıdaki kodu kullanırız

train<- train[,c(15:16,1:14)]
head(train)
## # A tibble: 6 × 16
##   ailenum ailesıra PassengerId HomePlanet CryoSleep Cabin Destination     Age
##   <chr>   <chr>    <chr>       <chr>      <lgl>     <chr> <chr>         <dbl>
## 1 0001    01       0001_01     Europa     FALSE     B/0/P TRAPPIST-1e      39
## 2 0002    01       0002_01     Earth      FALSE     F/0/S TRAPPIST-1e      24
## 3 0003    01       0003_01     Europa     FALSE     A/0/S TRAPPIST-1e      58
## 4 0003    02       0003_02     Europa     FALSE     A/0/S TRAPPIST-1e      33
## 5 0004    01       0004_01     Earth      FALSE     F/1/S TRAPPIST-1e      16
## 6 0005    01       0005_01     Earth      FALSE     F/0/P PSO J318.5-22    44
## # ℹ 8 more variables: VIP <lgl>, RoomService <dbl>, FoodCourt <dbl>,
## #   ShoppingMall <dbl>, Spa <dbl>, VRDeck <dbl>, Name <chr>, Transported <lgl>

İlk altı gözlemi görmek için head kodu kullanılır.