What would a passenger’s chance of survival be on the sinking Titanic?

1 Import

train=read.csv("titanic_train.csv")
test=read.csv("titanic_test.csv")

2 Clean

train$Survived=factor(train$Survived)
train=na.omit(train)
test=na.omit(test)

3 Model

model=randomForest(Survived~Pclass+Sex+Age+SibSp+Parch+Fare,ntree=500,importance=T,data=train)

predictions=predict(model,test)

4 Predict

titanic_predictions=read.csv('titanic_predictions.csv')
sum(titanic_predictions)/count(titanic_predictions)

Passengers have a 34% survival rate.

## R version 4.3.0 alpha (2023-04-01 r84141 ucrt)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19045)
## 
## Matrix products: default
## 
## 
## locale:
## [1] LC_COLLATE=English_United States.utf8 
## [2] LC_CTYPE=English_United States.utf8   
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C                          
## [5] LC_TIME=English_United States.utf8    
## 
## time zone: America/New_York
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] randomForest_4.7-1.1 readxl_1.4.2         tidyselect_1.2.0    
##  [4] lubridate_1.9.2      forcats_1.0.0        stringr_1.5.0       
##  [7] dplyr_1.1.1          purrr_1.0.1          readr_2.1.4         
## [10] tidyr_1.3.0          tibble_3.2.1         tidyverse_2.0.0     
## [13] ggplot2_3.4.1       
## 
## loaded via a namespace (and not attached):
##  [1] sass_0.4.5       utf8_1.2.3       generics_0.1.3   stringi_1.7.12  
##  [5] hms_1.1.3        digest_0.6.31    magrittr_2.0.3   evaluate_0.20   
##  [9] grid_4.3.0       timechange_0.2.0 fastmap_1.1.1    cellranger_1.1.0
## [13] jsonlite_1.8.4   fansi_1.0.4      scales_1.2.1     jquerylib_0.1.4 
## [17] cli_3.6.1        rlang_1.1.0      munsell_0.5.0    withr_2.5.0     
## [21] cachem_1.0.7     yaml_2.3.7       tools_4.3.0      tzdb_0.3.0      
## [25] colorspace_2.1-0 vctrs_0.6.1      R6_2.5.1         lifecycle_1.0.3 
## [29] pkgconfig_2.0.3  pillar_1.9.0     bslib_0.4.2      gtable_0.3.3    
## [33] glue_1.6.2       xfun_0.38        rstudioapi_0.14  knitr_1.42      
## [37] htmltools_0.5.5  rmarkdown_2.21   compiler_4.3.0