将一部分泰坦尼克号上的乘客数据(包括是否生还)作为训练集,对测试集中的的乘客生还情况进行预测。
导入所用的包
library(randomForest)
library(dplyr)
library(ggplot2)
library(mice)
导入数据
从csv中分别导入训练集和测试集数据
train = read.csv("train.csv",header = T,stringsAsFactors = F)
test = read.csv("test.csv",header = T,stringsAsFactors = F)
data = bind_rows(train,test)
str(data)
'data.frame': 1309 obs. of 12 variables:
$ PassengerId: int 1 2 3 4 5 6 7 8 9 10 ...
$ Survived : int 0 1 1 1 0 0 0 0 1 1 ...
$ Pclass : int 3 1 3 1 3 3 1 3 3 2 ...
$ Name : chr "Braund, Mr. Owen Harris" "Cumings, Mrs. John Bradley (Florence Briggs Thayer)" "Heikkinen, Miss. Laina" "Futrelle, Mrs. Jacques Heath (Lily May Peel)" ...
$ Sex : chr "male" "female" "female" "female" ...
$ Age : num 22 38 26 35 35 NA 54 2 27 14 ...
$ SibSp : int 1 1 0 1 0 0 0 3 0 1 ...
$ Parch : int 0 0 0 0 0 0 0 1 2 0 ...
$ Ticket : chr "A/5 21171" "PC 17599" "STON/O2. 3101282&