-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.R
65 lines (44 loc) · 1.25 KB
/
Main.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
library(tidyverse)
library(tidymodels)
library(ggthemes)
library(scales)
library(mice)
library(randomForest)
train <- read_csv("train.csv")
test <- read_csv("test.csv")
str(train)
train <- train %>%
mutate(IsTrain=T)
test <- test %>%
mutate(IsTrain=F)
ncol(train)
ncol(test)
names(train)
names(test)
test <- test %>%
mutate(Survived = NA)
full <- rbind(train,test)
str(full)
full$Sex <- as.factor(full$Sex)
full$Embarked <- as.factor(full$Embarked)
full$Pclass <- as.factor(full$Pclass)
summary(full)
full$Embarked <- replace_na(full$Embarked,"S")
full %>%
select(Age) %>%
is.na() %>%
table()
up<- boxplot.stats(full$Fare)$stats[5]
out <- full$Fare<up
fare_mod <- lm(
Fare~Pclass + Sex + Age + SibSp + Parch + Embarked,
data = full[out,]
)
fare_row<- full[is.na(full$Fare),c("Pclass","Sex", "Age","SibSp", "Parch", "Embarked")]
fare_pred<- predict(fare_mod, newdata = fare_row)
full[is.na(full$Fare), "Fare"] <- fare_pred
bench_fare <- 31.275+1.5*IQR(full$Fare)
full$Fare[full$Fare>bench_fare] <- bench_fare
boxplot(full$Fare)
full$Age <- replace_na(full$Age, mean(full$Age, na.rm = T))
# EDA ---------------------------------------------------------------------------------------