-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.Rmd
638 lines (525 loc) · 22.6 KB
/
main.Rmd
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
---
title: "US Census - Income Competition"
author: "Paul Marcilhacy"
date: "02/02/2017"
output:
md_document:
variant: markdown_github
---
# Introduction
In this analysis, we use a us census dataset containing detailed but anonymised information for approximately 300,000 people. We will use this data to create a model to try to "predict" who is earning more or less than $50,000 / year.
We will detail the different steps of the analysis. In the first part, we realize a quick audit of the data, then we build the model based on the training set and finally, we will confront our model to "reality" using the test set.
This analysis is entirely realized in R. First, let's set the environment
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r environment_setup, include=TRUE, eval=TRUE, message=FALSE, warning=FALSE}
require(data.table)
require(dplyr)
require(ggplot2)
require(xgboost)
require(Matrix)
require(DiagrammeR)
require(reshape2)
require(gridExtra)
require(lazyeval)
require(caret)
require(Metrics)
require(scales)
source("utilities/plot_utilities.R")
source("utilities/metrics_utilities.R")
```
# Data Exploration
In this part I carry out a quick audit of the training data.
## Load Data
First, I load the training data and make sure that all the categorical variables are indeed factors.
```{r load_training_data, eval=TRUE}
train_data <- data.table::fread(input = "data/census_income_learn.csv", header = F, sep = ",")
colnames <- c("age", "class_worker", "industry", "occupation", "education", "wage_per_hour",
"enrolled_edu_inst_last_wk", "marital_status", "major_industry", "major_occupation",
"race", "hispanic_origin", "sex", "labor_union", "unemployment_reason",
"full_part_employment", "capital_gains", "capital_losses", "dividends_stocks",
"tax_filer_status", "region_previous_residence", "state_previous_residence",
"detailed_family_stat", "detailed_household_summary", "instance_weight",
"migration_code_change_msa", "migration_code_change_reg", "migration_code_move_reg",
"same_house_1_ago", "migration_prev_res_sunbelt", "num_persons_employer",
"family_members_under_18", "father_country_birth", "mother_country_birth",
"country_birth", "citizenship", "own_business_self_employed",
"questionnaire_veteran_admin", "veteran_benefits", "weeks_worked_year", "year",
"target"
)
names(train_data) <- colnames
categorical_vars <- c("class_worker", "industry", "occupation", "education",
"enrolled_edu_inst_last_wk", "marital_status", "major_industry", "major_occupation",
"race", "hispanic_origin", "sex", "labor_union", "unemployment_reason",
"full_part_employment",
"tax_filer_status", "region_previous_residence", "state_previous_residence",
"detailed_family_stat", "detailed_household_summary", "migration_code_change_msa",
"migration_code_change_reg", "migration_code_move_reg", "same_house_1_ago",
"migration_prev_res_sunbelt", "family_members_under_18",
"father_country_birth", "mother_country_birth", "country_birth", "citizenship",
"own_business_self_employed", "questionnaire_veteran_admin", "veteran_benefits",
"year", "target"
)
train_data <- train_data %>%
mutate_each_(funs(as.factor(.))
, categorical_vars)
summary(train_data)
```
We named "target" the variable we try to predict - if the person earned more or less than $50K / year.
We observe that the training set is very unbalanced. Indeed the share of people earning more than \$50K is only `r scales::percent(sum(train_data$target == "50000+.")/length(train_data$target))` in the training set.
## Categorical variables
Let's plot bar charts of the number of records for each "target" (incomes superior to $50K or less) sliced by several categorical variables.
We create a plot for all categorical variables.
```{r cat_vars_plots, eval=TRUE}
# All categorical variables
factor_vars <- names(train_data)[sapply(train_data, is.factor)]
# A plot for for each categorical variable
plots <- list()
for (var in factor_vars) {
plots[[var]] <- train_data[, c(var, "target")] %>%
ggplot(., aes_string(var, fill = "target")) +
geom_bar(aes(y = (..count..)/sum(..count..)), position = "dodge") +
scale_fill_manual(values = c("#041B2E", "#2BB2AD")) +
scale_y_continuous(labels = percent) +
ylab("")
if (var == factor_vars[1]) {
plots[[var]] <- plots[[var]] +
theme(legend.position = "bottom")
} else {
plots[[var]] <- plots[[var]] +
theme(legend.position = "none")
}
}
# Here we save separately a legend, so that we can reuse in all multiplot situation.
mylegend <- get_legend(plots[[1]])
plots[[1]] <- plots[[1]] +
theme(legend.position = "none")
```
First, let's slice by race, sex and citizenship.
```{r cat_plot_1, fig.align="center"}
grid.arrange(do.call(arrangeGrob, plots[c("race", "sex", "citizenship")])
, mylegend, nrow = 2, heights = c (10, 1)
)
```
Second, let's show the split by education level, belonging to a labor union, and if the interogated person has lived in the same house more than a year or not.
```{r cat_plot_2, fig.align="center"}
grid.arrange(do.call(arrangeGrob, plots[c("education", "labor_union", "same_house_1_ago")])
, mylegend, nrow = 2, heights = c (10, 1)
)
```
Let's show the sames chart but not as percentages of the total number of people interrogated but as percentages of people interrogated belonging to the same target bucket.
First: race, sex and citizenship
```{r plot_percentages, eval=TRUE, fig.align="center"}
plots <- list()
for (var in factor_vars) {
plots[[var]] <- train_data[, c(var, "target")] %>%
group_by_(.dots = c(var, "target")) %>%
summarise(., count = n()) %>%
group_by_(.dots = c("target")) %>%
mutate(perc = count/sum(count)) %>%
ungroup() %>%
ggplot(., aes_string(x = var, y = "perc", fill = "target")) +
geom_bar(stat="identity", position = "dodge") +
scale_fill_manual(values = c("#041B2E", "#2BB2AD")) +
scale_y_continuous(labels = percent) +
ylab("") +
theme(legend.position = "none")
}
grid.arrange(do.call(arrangeGrob, plots[c("race", "sex", "citizenship")])
, mylegend, nrow = 2, heights = c (10, 1)
)
```
Then again, education, labor union and living in the same house more than a year.
```{r plot_percentages_2, eval=TRUE, fig.align="center"}
grid.arrange(do.call(arrangeGrob, plots[c("education", "labor_union", "same_house_1_ago")])
, mylegend, nrow = 2, heights = c (10, 1)
)
```
In the opposite, if we show percentages of each target bucketed by category:
```{r plot_percentages_bucket, eval=TRUE, fig.align="center"}
require(lazyeval)
plots <- list()
for(var in factor_vars){
varval <- interp(~substr(var, 1, 5), var = as.name(var))
plots[[var]] <- train_data[, c(var, "target")] %>%
group_by_(.dots = c(var, "target")) %>%
summarise(count = n()) %>%
group_by_(.dots = c(var)) %>%
dplyr::mutate(perc = count/sum(count)) %>%
ungroup() %>%
dplyr::mutate_(.dots = setNames(list(varval), var)) %>%
ggplot(., aes_string(x = var, y = "perc", fill = "target")) +
geom_bar(stat="identity", position = "dodge") +
scale_fill_manual(values = c("#041B2E", "#2BB2AD")) +
scale_y_continuous(labels = percent) +
ylab("") +
theme(legend.position = "none")
}
grid.arrange(do.call(arrangeGrob, plots[c("education", "labor_union", "same_house_1_ago")])
, mylegend, nrow = 2, heights = c (10, 1)
)
```
The dataset being very unbalance no mater the variable we choose the split it by. However, we clearly that the share of people in the +$50k bucket is much higher for people with higher education. Actually, for some particular education levels, it is more than 50% of the population (PhD and Prof school degree).
You can plot all the charts, 3 by 3 running:
```{r all_cat_plots, eval=FALSE}
marrangeGrob(plots[1:12], nrow = 3, ncol = 1)
marrangeGrob(plots[13:25], nrow = 3, ncol = 1)
marrangeGrob(plots[26:35], nrow = 3, ncol = 1)
```
## Continuous variables
Now, let's have a look at the continuous variables. We will plot histograms of these variables.
```{r continuous_vars_plot, warning=FALSE, message=FALSE, eval=TRUE, fig.align="center"}
# continuous variables in the set
continuous_vars <- names(train_data)[!sapply(train_data, is.factor)]
# create a list containing all the histograms of the continuous variables
plots <- list()
for (var in continuous_vars) {
plots[[var]] <- train_data[, c(var, "target")] %>%
ggplot(., aes_string(var, fill = "target")) +
geom_histogram(position = "dodge", color = "white") +
#scale_y_log10() +
ylab(var) +
scale_fill_manual(values = c("#041B2E", "#2BB2AD")) +
theme(legend.position = "none")
}
# Plot all the histograms in one plot
grid.arrange(do.call(arrangeGrob, plots)
, mylegend, nrow = 2, heights = c (10, 1)
, top = "Histograms of all continuous variables in the train set"
)
```
For most of the variables, we can't barely see anything, because too many elements are in 0.
Let's try to exclude elements with 0, to have a better look of the rest of the histograms.
```{r continuous_vars_plot_2, warning=FALSE, message=FALSE, eval=TRUE, fig.align="center"}
plots <- list()
for (var in continuous_vars) {
cond <- interp(~ var > 0, var = as.name(var))
plot_data <- train_data[, c(var, "target")] %>%
dplyr::filter_(cond)
plots[[var]] <- plot_data %>%
ggplot(., aes_string(var, fill = "target")) +
geom_histogram(position = "dodge", color = "white") +
ylab(var) +
scale_fill_manual(values = c("#041B2E", "#2BB2AD")) +
theme(legend.position = "none")
}
grid.arrange(do.call(arrangeGrob, plots)
, mylegend, nrow = 2, heights = c (10, 1)
, top = "Histograms of all continuous variables in the train set"
)
```
Let's focus on the ages density in our data
```{r age_hist_plot, message = FALSE, warning = FALSE, eval=TRUE, fig.align="center"}
ggplot(data = train_data, aes(x = age, fill = target)) +
geom_histogram(color = "white", position = "dodge") +
scale_fill_manual(values = c("#041B2E", "#2BB2AD"))
```
## NAs
We observed already that there is quite a lot of "unkown"/"not in universe" in the data. Are there also NAs in the data and where are they?
Indeed, NAs may break the algorithms we will use the next part of this analysis.
```{r show_nas, eval=TRUE, fig.align="center"}
apply(train_data, MARGIN = 2, FUN = function(x){
sum(is.na(x))
})
```
There are indeed some NAs in the data but they are located in the same variable: "hispanic_origin"
We will deal with this issue in the next part of the analysis.
Now, let's move on to the core of this analysis and let's build our classification model.
# Data Munging
First, we need to load the test data and process the training set and the test set exactly the same way. In order to do so efficiently, we will join the two datasets and execute the different actions on the joint dataset.
## Load test data
We load the test data and apply the same transformations on the categorical variables.
```{r load_test_data, eval=TRUE}
test_data <- data.table::fread(input = "data/census_income_test.csv", header = F, sep = ",")
# rename the columns
names(test_data) <- colnames
# change the right vars to categorical
test_data <- test_data %>%
mutate_each_(funs(as.factor(.))
, categorical_vars)
```
We join the train set and the test set to apply the same transformation to both.
In order to be able to separate them again, we create a variable to differenciate them.
```{r join_data, eval=TRUE}
train_data$train_or_test <- "train"
test_data$train_or_test <- "test"
all_data <- rbind(train_data, test_data)
```
## NAs
There are some NA's in the data.
`r sum(!complete.cases(all_data))` rows have at least 1 NA value.
Does it come from 1 or multiple columns? We repeat the same exercise as above and see that both in the train set and the test set, the NAs come from the same variable ("hispanic_origin").
If we plot the number of elements in the data by this variable:
```{r plot_hispanic_origin, eval=TRUE, fig.align="center"}
ggplot(data = all_data, aes(x = hispanic_origin, fill = hispanic_origin)) +
geom_bar() +
theme(legend.position = "bottom", legend.title = element_blank())
```
A crushing majority of the elements have "All other" as value for this variables. For these rows, we will thus assign the hispanic origin to the value the most elements: "All other"
```{r remove_nas, eval=TRUE}
all_data$hispanic_origin[is.na(all_data$hispanic_origin)] <- "All other"
```
There are no more NAs in the train data.
## Binarisation of “categorical” variables
We change the factor variables into dummy variables the sake of the algorithms used.
```{r dummy_variables, eval=TRUE}
all_data <- all_data %>%
mutate(target = ifelse(target == '50000+.', yes = TRUE, no = FALSE))
all <- list(
data = all_data[, -c(ncol(all_data)-1, ncol(all_data))]
, label = all_data$target
, train_or_test = all_data$train_or_test
)
# transform all the factors into dummy variables
data <- sparse.model.matrix(~.-1, data = all$data)
```
We re-separate the test and the train data using the train_or_test variable we create earlier.
```{r split_data, eval=TRUE}
train <- list(
data = data[all$train_or_test == 'train', ]
, label = all$label[all$train_or_test == 'train']
)
test <- list(
data = data[all$train_or_test == 'test', ]
, label = all$label[all$train_or_test == 'test']
)
```
Now that both are training set and test set are ready, it is time to train our models and choose the best.
# First try: XGboost vs. 1 class SVM
In this part, we will train and test 2 alogorithms, without tuning them much and see which one seems to be the most
promising.
The 2 algorithm that we want to test are:
1. One-class SVM
2. XGboost
## 1 class SVM
1 class SVM is usually used for anomaly detection. Here the dataset is very unbalanced in favor of people
who earn less than \$50k per year. I thought we thus could see the people who earn more as "anomalies" in the data.
Let's see how it works.
```{r train_svm, eval=TRUE}
require(e1071)
x <- train$data[train$label == TRUE, ]
y <- train$label[train$label == TRUE]
model <- svm(x = x, y = y, type = 'one-classification')
summary(model)
```
Let's try our model on the test data and compute some metrics of error over the prediction.
We print the percentage of error in the prediction. However, the dataset is very unbalanced. A very naïve algorithm labelling 0 no matter the input would do pretty good with this metric.
Let's also see how we performed on rows where target == 1.
Finally, we print the entire confusion matrix, both on absolute and on percentage of total. The sum of the 1st diagonale of this matrix give us the percentage of good prediction.
```{r predict_svm_1, eval=TRUE}
pred <- predict(model, test$data)
print_result_metrics(predicted = pred, actual = test$label)
```
## XGboost
Now let's see if we can beat this result using xgboost.
```{r train_xgbst_1, results='hide', eval=TRUE}
xgb_params_1 = list(
objective = "binary:logistic"
, eval_metric = "auc"
, scale_pos_weight = floor(length(train_data$target)/sum(train_data$target == "50000+."))
, stratified = TRUE
)
bst <- xgboost(data = train$data
, label = train$label
, params = xgb_params_1
, nthread = 2
, nrounds = 100
)
```
Let's predict the results for the test data with the xgboost algorithm and show the same metrics as previously.
```{r test_xgboost_1, eval=TRUE}
pred <- predict(bst, test$data)
pred <- as.numeric(pred > 0.5)
print_result_metrics(predicted = pred, actual = test$label)
```
After a first test without any optimization, we can draw the following conclusions:
* The 1 class svm seems to give naturally more false positive
* XGboost seems to be better as it returns very few false negatives (~0.72%) and less false positives
even if, weighting the postive elements in order to rebalance the dataset strongly increased this number.
In the following section of this analysis, we will try to optimize the parameters for the xgboost model.
# XGBoost optimization
## Training plots
First, we plot a few training stats to get a rough idea of the parameters to use:
```{r train_xgbst_2, eval=TRUE, results='hide'}
# use special xgboost data class
dtrain <- xgb.DMatrix(data = train$data, label = train$label)
dtest <- xgb.DMatrix(data = test$data, label = test$label)
# enables to get live data during the training
watchlist <- list(train = dtrain, test = dtest)
xgb_params_2 = list(
objective = "binary:logistic"
, eta = 0.5
, max.depth = 8
, eval_metric = "auc"
, eval_metric = "logloss"
, eval.metric = "error"
, scale_pos_weight = floor(length(train_data$target)/sum(train_data$target == "50000+."))
, stratified = TRUE
, early_stop_rounds = 10
, nfold = 10
, showsd = TRUE
, verbose = TRUE
, colsample_bytree = 1
, min_child_weight = 100
, subsample = 1
)
bst_2 <- xgb.train(data = dtrain
, params = xgb_params_2
, nround = 100
, watchlist = watchlist
)
```
Plot, the "area under the curve" at each training round.
```{r auc_plot, eval=TRUE, fig.align="center"}
bst_2$evaluation_log %>%
dplyr::select(contains("auc")) %>%
dplyr::mutate(iteration_num = 1:n()) %>%
reshape2::melt(., "iteration_num") %>%
ggplot(aes(x = iteration_num, y = value, group = variable, color = variable)) +
geom_line() +
theme_bw()
```
Plot, the prediction "error" at each training round.
```{r error_plot, eval=TRUE, fig.align="center"}
bst_2$evaluation_log %>%
dplyr::select(contains("error")) %>%
dplyr::mutate(iteration_num = 1:n()) %>%
reshape2::melt(., "iteration_num") %>%
ggplot(aes(x = iteration_num, y = value, group = variable, color = variable)) +
geom_line() +
theme_bw()
```
Plot, the "logarithmic loss" at each training round.
```{r logloss_plot, eval=TRUE, fig.align="center"}
bst_2$evaluation_log %>%
dplyr::select(contains("logloss")) %>%
dplyr::mutate(iteration_num = 1:n()) %>%
reshape2::melt(., "iteration_num") %>%
ggplot(aes(x = iteration_num, y = value, group = variable, color = variable)) +
geom_line() +
theme_bw()
```
Now let's see how we performed with this configuration.
```{r test_xgbst_2, eval=TRUE}
pred <- predict(bst_2, dtest)
pred <- as.numeric(pred > 0.5)
print_result_metrics(predicted = pred, actual = test$label)
```
## Parameters tuning using caret
Let's tune the hyper parameters:
```{r caret_search, eval=FALSE}
# Data frame of parameters we want to test the model for:
xgb_grid_1 <- expand.grid(
eta = c(.1, 0.5, 1)
, max_depth = c(4, 8, 10, 20)
, nrounds = 100
, colsample_bytree = 1
, min_child_weight = c(1, 5, 10, 20)
, subsample = 1
, gamma = 0
)
watchlist <- list(train = dtrain, test = dtest)
# pack the training control parameters
xgb_trcontrol_1 = caret::trainControl(
method = "repeatedcv",
repeats = 2,
number = 2,
verboseIter = TRUE,
returnData = FALSE,
returnResamp = "all",
classProbs = TRUE,
summaryFunction = twoClassSummary,
allowParallel = TRUE
)
train$label <- factor(train$label, labels = c("no", "yes"))
set.seed(27)
xgb_train_1 <- caret::train(
x = data.matrix(train$data)
, y = train$label
, trControl = xgb_trcontrol_1
, tuneGrid = xgb_grid_1
, method = "xgbTree"
, verbose = T
, metric = "ROC"
, nthread = 3
, scale_pos_weight = floor(length(train_data$target)/sum(train_data$target == "50000+."))
, stratified = TRUE
, early_stop_rounds = 10
, nfold = 10
)
xgb_train_1$results %>%
ggplot(aes(x = min_child_weight, y = max_depth, size = ROC, color = ROC)) +
geom_point() +
theme_bw() +
scale_size_continuous(guide = "none")
```
[Caret Plot Result](presentation/caret_2.jpeg)
We now have a set of "optimal" hyper-parameters to use in our xgboost model. Let's train a model using these parameters and see how they perform.
We could then use.
```{r train_xgboost_3, eval=FALSE, results='hide'}
bst_3 <- xgb.train(data = dtrain
, params = xgb_train_1$bestTune
, nround = 100
, watchlist = watchlist
, eval_metric = "auc"
, eval_metric = "logloss"
, eval.metric = "error"
, scale_pos_weight = floor(length(train_data$target)/sum(train_data$target == "50000+."))
, stratified = TRUE
, early_stop_rounds = 10
, nfold = 10
, showsd = TRUE
, verbose = TRUE
)
```
However, for the purpose of knitting this presentation, we will directly use the result of caret.
The search gave us the following result:
```
Selecting tuning parameters
Fitting nrounds = 100, max_depth = 10, eta = 0.1, gamma = 0, colsample_bytree = 1, min_child_weight = 20, subsample = 1 on full training set
```
We use this set of hyper-parameters to train our model.
```{r train_xgbst_opt, eval=TRUE, results='hide'}
# parameters list based on the result of caret.
xgb_params_opt = list(
objective = "binary:logistic"
, eta = 0.1
, max.depth = 10
, eval_metric = "auc"
, eval_metric = "logloss"
, eval.metric = "error"
, scale_pos_weight = floor(length(train_data$target)/sum(train_data$target == "50000+."))
, stratified = TRUE
, early_stop_rounds = 10
, nfold = 10
, showsd = TRUE
, verbose = TRUE
, colsample_bytree = 1
, min_child_weight = 20
, subsample = 1
, gamma = 0
)
bst_opt <- xgb.train(
data = dtrain
, params = xgb_params_opt
, nround = 100
, watchlist = watchlist
)
```
Finally we test our model a last time:
```{r test_xgboost_3, eval=TRUE}
pred <- predict(bst_opt, dtest)
pred <- as.numeric(pred > 0.5)
print_result_metrics(predicted = pred, actual = test$label)
```
## Analyse results
One interesting thing to see is to get a notion of the importance of each variable in the result.
```{r feature_importance, eval=TRUE, fig.align="center"}
importance <- xgb.importance(feature_names = colnames(train$data), model = bst_opt)
xgb.plot.importance(importance_matrix = importance, top_n = 20)
```
# Conclusion
In this analysis, we saw all the classic steps of building quickly a simple ml model.
XGboost worked very well in the beginning and we improved the performance using the right hyper parameters.
It worked decently on the test set and should now be confronted to more "real" data to confirm its performance.