Goal is to build a classification model to predict whether the person died.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readr)
library(correlationfunnel)
## ══ correlationfunnel Tip #2 ════════════════════════════════════════════════════
## Clean your NA's prior to using `binarize()`.
## Missing values and cleaning data are critical to getting great correlations. :)
data1 <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2020/2020-09-22/members.csv')
## Rows: 76519 Columns: 21
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (10): expedition_id, member_id, peak_id, peak_name, season, sex, citizen...
## dbl (5): year, age, highpoint_metres, death_height_metres, injury_height_me...
## lgl (6): hired, success, solo, oxygen_used, died, injured
##
## ℹ 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.
skimr::skim(data1)
Name | data1 |
Number of rows | 76519 |
Number of columns | 21 |
_______________________ | |
Column type frequency: | |
character | 10 |
logical | 6 |
numeric | 5 |
________________________ | |
Group variables | None |
Variable type: character
skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
---|---|---|---|---|---|---|---|
expedition_id | 0 | 1.00 | 9 | 9 | 0 | 10350 | 0 |
member_id | 0 | 1.00 | 12 | 12 | 0 | 76518 | 0 |
peak_id | 0 | 1.00 | 4 | 4 | 0 | 391 | 0 |
peak_name | 15 | 1.00 | 4 | 25 | 0 | 390 | 0 |
season | 0 | 1.00 | 6 | 7 | 0 | 5 | 0 |
sex | 2 | 1.00 | 1 | 1 | 0 | 2 | 0 |
citizenship | 10 | 1.00 | 2 | 23 | 0 | 212 | 0 |
expedition_role | 21 | 1.00 | 4 | 25 | 0 | 524 | 0 |
death_cause | 75413 | 0.01 | 3 | 27 | 0 | 12 | 0 |
injury_type | 74807 | 0.02 | 3 | 27 | 0 | 11 | 0 |
Variable type: logical
skim_variable | n_missing | complete_rate | mean | count |
---|---|---|---|---|
hired | 0 | 1 | 0.21 | FAL: 60788, TRU: 15731 |
success | 0 | 1 | 0.38 | FAL: 47320, TRU: 29199 |
solo | 0 | 1 | 0.00 | FAL: 76398, TRU: 121 |
oxygen_used | 0 | 1 | 0.24 | FAL: 58286, TRU: 18233 |
died | 0 | 1 | 0.01 | FAL: 75413, TRU: 1106 |
injured | 0 | 1 | 0.02 | FAL: 74806, TRU: 1713 |
Variable type: numeric
skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
---|---|---|---|---|---|---|---|---|---|---|
year | 0 | 1.00 | 2000.36 | 14.78 | 1905 | 1991 | 2004 | 2012 | 2019 | ▁▁▁▃▇ |
age | 3497 | 0.95 | 37.33 | 10.40 | 7 | 29 | 36 | 44 | 85 | ▁▇▅▁▁ |
highpoint_metres | 21833 | 0.71 | 7470.68 | 1040.06 | 3800 | 6700 | 7400 | 8400 | 8850 | ▁▁▆▃▇ |
death_height_metres | 75451 | 0.01 | 6592.85 | 1308.19 | 400 | 5800 | 6600 | 7550 | 8830 | ▁▁▂▇▆ |
injury_height_metres | 75510 | 0.01 | 7049.91 | 1214.24 | 400 | 6200 | 7100 | 8000 | 8880 | ▁▁▂▇▇ |
Issues with data: - Missing Values: peak_name, sex, citizenship, expedition_role, death_cause, injury_type, age, highpoint_metres, death_height_metres, injury_height_metres - Factors or numeric variables: none - Zero variance values: none - Character variables: Convert them to numbers in recipe step (step_dummy) _ Unbalanced Target variable: died _ ID Variable: member_id
# treat missing values
data_clean1 <- data1 %>%
na.omit()
data_clean1 %>% count(died)
## # A tibble: 1 × 2
## died n
## <lgl> <int>
## 1 TRUE 2
data_clean1 %>%
ggplot(aes(died)) +
geom_bar()
died vs age
data_clean1 %>%
ggplot(aes(died, age)) +
geom_boxplot()
died vs highpoint_metres
data_clean1 %>%
ggplot(aes(died, highpoint_metres)) +
geom_boxplot()
correlation plot
# step 1 binarize
data_binarized1 <- data_clean1 %>%
select(-member_id) %>%
binarize()
data_binarized1 %>% glimpse()
## Rows: 2
## Columns: 20
## $ expedition_id__BAUD70101 <dbl> 1, 0
## $ expedition_id__GAUR85101 <dbl> 0, 1
## $ peak_id__BAUD <dbl> 1, 0
## $ peak_id__GAUR <dbl> 0, 1
## $ peak_name__Baudha <dbl> 1, 0
## $ peak_name__Gaurishankar <dbl> 0, 1
## $ year__1970 <dbl> 1, 0
## $ year__1985 <dbl> 0, 1
## $ age__26 <dbl> 1, 0
## $ age__28 <dbl> 0, 1
## $ expedition_role__Climber <dbl> 1, 0
## $ expedition_role__Leader <dbl> 0, 1
## $ highpoint_metres__6150 <dbl> 1, 0
## $ highpoint_metres__6500 <dbl> 0, 1
## $ death_cause__Crevasse <dbl> 1, 0
## $ death_cause__Fall <dbl> 0, 1
## $ death_height_metres__5900 <dbl> 0, 1
## $ death_height_metres__6095 <dbl> 1, 0
## $ injury_height_metres__6000 <dbl> 1, 0
## $ injury_height_metres__6100 <dbl> 0, 1
# step 2 correlate
data_correlation1 <- data_binarized1 %>%
correlate(death_cause__Fall)
data_correlation1
## # A tibble: 20 × 3
## feature bin correlation
## <fct> <chr> <dbl>
## 1 expedition_id BAUD70101 -1
## 2 expedition_id GAUR85101 1
## 3 peak_id BAUD -1
## 4 peak_id GAUR 1
## 5 peak_name Baudha -1
## 6 peak_name Gaurishankar 1
## 7 year 1970 -1
## 8 year 1985 1
## 9 age 26 -1
## 10 age 28 1
## 11 expedition_role Climber -1
## 12 expedition_role Leader 1
## 13 highpoint_metres 6150 -1
## 14 highpoint_metres 6500 1
## 15 death_cause Crevasse -1
## 16 death_cause Fall 1
## 17 death_height_metres 5900 1
## 18 death_height_metres 6095 -1
## 19 injury_height_metres 6000 -1
## 20 injury_height_metres 6100 1
#step 3 plot
data_correlation1 %>%
correlationfunnel::plot_correlation_funnel()