Goal is to automate building and tuning a classification model to predict climbers deaths, using the h2o::h2o.automl.

Set up

Import data

Import the cleaned data from Module 7.

library(h2o)
## 
## ----------------------------------------------------------------------
## 
## Your next step is to start H2O:
##     > h2o.init()
## 
## For H2O package documentation, ask for help:
##     > ??h2o
## 
## After starting H2O, you can use the Web UI at http://localhost:54321
## For more information visit https://docs.h2o.ai
## 
## ----------------------------------------------------------------------
## 
## Attaching package: 'h2o'
## The following objects are masked from 'package:stats':
## 
##     cor, sd, var
## The following objects are masked from 'package:base':
## 
##     &&, %*%, %in%, ||, apply, as.factor, as.numeric, colnames,
##     colnames<-, ifelse, is.character, is.factor, is.numeric, log,
##     log10, log1p, log2, round, signif, trunc
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ lubridate::day()   masks h2o::day()
## ✖ dplyr::filter()    masks stats::filter()
## ✖ lubridate::hour()  masks h2o::hour()
## ✖ dplyr::lag()       masks stats::lag()
## ✖ lubridate::month() masks h2o::month()
## ✖ lubridate::week()  masks h2o::week()
## ✖ lubridate::year()  masks h2o::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidymodels)
## ── Attaching packages ────────────────────────────────────── tidymodels 1.1.1 ──
## ✔ broom        1.0.5     ✔ rsample      1.2.0
## ✔ dials        1.2.0     ✔ tune         1.1.2
## ✔ infer        1.0.6     ✔ workflows    1.1.3
## ✔ modeldata    1.3.0     ✔ workflowsets 1.0.1
## ✔ parsnip      1.1.1     ✔ yardstick    1.3.0
## ✔ recipes      1.0.8     
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ scales::discard() masks purrr::discard()
## ✖ dplyr::filter()   masks stats::filter()
## ✖ recipes::fixed()  masks stringr::fixed()
## ✖ dplyr::lag()      masks stats::lag()
## ✖ yardstick::spec() masks readr::spec()
## ✖ recipes::step()   masks stats::step()
## • Use tidymodels_prefer() to resolve common conflicts.
library(tidyquant)
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## 
## Attaching package: 'PerformanceAnalytics'
## 
## The following object is masked from 'package:graphics':
## 
##     legend
## 
## Loading required package: quantmod
## Loading required package: TTR
## 
## Attaching package: 'TTR'
## 
## The following object is masked from 'package:dials':
## 
##     momentum
## 
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
data <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/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.
factors_vec <- data %>% select(year, age, highpoint_metres, death_height_metres, injury_height_metres) %>%
    names()

# Treating missing values
data_clean <- data %>% 
    select(-death_cause, -injury_type, -death_height_metres, - injury_height_metres) %>%
    drop_na() %>%
    
    # Mutate logical Variables
    mutate(died = case_when(died == "TRUE" ~ "died", died == "FALSE" ~ "no")) %>%
    
    mutate(across(where(is.logical), as.factor)) %>%

    # Recode "died"
    mutate(died = if_else(died == "TRUE", "deaths", died))

Split data

set.seed(1234)

data_split <- initial_split(data, strata = "died")
train_tbl <- training(data_split)
test_tbl <- testing(data_split)

Recipes

recipe_obj <- recipe(died ~ ., data = train_tbl) %>%
    
    # Remove zero variance variables
    step_zv(all_predictors()) 

Model

# Initialize h2o
h2o.init()
##  Connection successful!
## 
## R is connected to the H2O cluster: 
##     H2O cluster uptime:         7 days 1 hours 
##     H2O cluster timezone:       America/New_York 
##     H2O data parsing timezone:  UTC 
##     H2O cluster version:        3.44.0.3 
##     H2O cluster version age:    4 months and 9 days 
##     H2O cluster name:           H2O_started_from_R_Vanessa_vmr042 
##     H2O cluster total nodes:    1 
##     H2O cluster total memory:   0.95 GB 
##     H2O cluster total cores:    8 
##     H2O cluster allowed cores:  8 
##     H2O cluster healthy:        TRUE 
##     H2O Connection ip:          localhost 
##     H2O Connection port:        54321 
##     H2O Connection proxy:       NA 
##     H2O Internal Security:      FALSE 
##     R Version:                  R version 4.3.1 (2023-06-16)
## Warning in h2o.clusterInfo(): 
## Your H2O cluster version is (4 months and 9 days) old. There may be a newer version available.
## Please download and install the latest version from: https://h2o-release.s3.amazonaws.com/h2o/latest_stable.html
# Split training
split.h2o <- h2o.splitFrame(as.h2o(train_tbl), ratios = c(0.85), seed = 2567)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
train_h2o <- split.h2o[[1]]
valid_h2o <- split.h2o[[2]]
test_h2o <- as.h2o(test_tbl)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
y <- "died"
x <- setdiff(names(train_tbl), y)

models_h2o <- h2o.automl(
    x = x,
    y = y, 
    training_frame    = train_h2o, 
    validation_frame  = valid_h2o, 
    leaderboard_frame = test_h2o, 
    max_runtime_secs = 30, 
    nfolds = 5, 
    seed = 2345
)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===                                                                   |   5%
## 11:46:12.169: User specified a validation frame with cross-validation still enabled. Please note that the models will still be validated using cross-validation only, the validation frame will be used to provide purely informative validation metrics on the trained models.
## 11:46:12.735: _train param, Dropping bad and constant columns: [member_id, peak_name, death_cause, peak_id, sex, citizenship, expedition_role, season, expedition_id, injury_type]
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |================                                                      |  23%
## 11:46:19.541: _train param, Dropping bad and constant columns: [member_id, peak_name, death_cause, peak_id, sex, citizenship, expedition_role, season, expedition_id, injury_type]
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |================================                                      |  46%
## 11:46:26.315: _train param, Dropping bad and constant columns: [member_id, peak_name, death_cause, peak_id, sex, citizenship, expedition_role, season, expedition_id, injury_type]
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |====================================================                  |  74%
## 11:46:35.306: _train param, Dropping unused columns: [member_id, peak_name, death_cause, peak_id, sex, citizenship, expedition_role, season, expedition_id, injury_type]
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |======================================================================| 100%

Examine the output of h2o.automl

models_h2o %>% typeof()
## [1] "S4"
models_h2o %>% slotNames()
## [1] "project_name"   "leader"         "leaderboard"    "event_log"     
## [5] "modeling_steps" "training_info"
models_h2o@leaderboard
##                                                   model_id       auc
## 1 StackedEnsemble_BestOfFamily_1_AutoML_21_20240430_114612 0.9940374
## 2                          GBM_1_AutoML_21_20240430_114612 0.9939811
## 3                      XGBoost_1_AutoML_21_20240430_114612 0.9927011
## 4                          GLM_1_AutoML_21_20240430_114612 0.6664706
##       logloss      aucpr mean_per_class_error       rmse          mse
## 1 0.011331425 0.98504766           0.01666667 0.04026143 0.0016209828
## 2 0.003175255 0.98464480           0.01666667 0.02144955 0.0004600831
## 3 0.004010885 0.98150554           0.01666667 0.02178677 0.0004746633
## 4 0.070858804 0.05070241           0.42197380 0.11725982 0.0137498658
## 
## [4 rows x 7 columns]
models_h2o@leader
## Model Details:
## ==============
## 
## H2OBinomialModel: stackedensemble
## Model ID:  StackedEnsemble_BestOfFamily_1_AutoML_21_20240430_114612 
## Model Summary for Stacked Ensemble: 
##                                     key            value
## 1                     Stacking strategy cross_validation
## 2  Number of base models (used / total)              2/3
## 3      # GBM base models (used / total)              1/1
## 4  # XGBoost base models (used / total)              1/1
## 5      # GLM base models (used / total)              0/1
## 6                 Metalearner algorithm              GLM
## 7    Metalearner fold assignment scheme           Random
## 8                    Metalearner nfolds                5
## 9               Metalearner fold_column               NA
## 10   Custom metalearner hyperparameters             None
## 
## 
## H2OBinomialMetrics: stackedensemble
## ** Reported on training data. **
## 
## MSE:  0.001482344
## RMSE:  0.03850123
## LogLoss:  0.01062543
## Mean Per-Class Error:  0.007093331
## AUC:  0.9999169
## AUCPR:  0.9958875
## Gini:  0.9998338
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        FALSE TRUE    Error     Rate
## FALSE   9788    1 0.000102  =1/9789
## TRUE       2  140 0.014085   =2/142
## Totals  9790  141 0.000302  =3/9931
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold       value idx
## 1                       max f1  0.042904    0.989399 121
## 2                       max f2  0.042904    0.987306 121
## 3                 max f0point5  0.055867    0.995702 119
## 4                 max accuracy  0.055867    0.999698 119
## 5                max precision  0.885481    1.000000   0
## 6                   max recall  0.018184    1.000000 153
## 7              max specificity  0.885481    1.000000   0
## 8             max absolute_mcc  0.042904    0.989252 121
## 9   max min_per_class_accuracy  0.018184    0.993666 153
## 10 max mean_per_class_accuracy  0.018184    0.996833 153
## 11                     max tns  0.885481 9789.000000   0
## 12                     max fns  0.885481  141.000000   0
## 13                     max fps  0.003120 9789.000000 399
## 14                     max tps  0.018184  142.000000 153
## 15                     max tnr  0.885481    1.000000   0
## 16                     max fnr  0.885481    0.992958   0
## 17                     max fpr  0.003120    1.000000 399
## 18                     max tpr  0.018184    1.000000 153
## 
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: stackedensemble
## ** Reported on validation data. **
## 
## MSE:  0.00177014
## RMSE:  0.04207304
## LogLoss:  0.01214736
## Mean Per-Class Error:  0.0141844
## AUC:  0.9945695
## AUCPR:  0.982806
## Gini:  0.989139
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        FALSE TRUE    Error     Rate
## FALSE   8536    0 0.000000  =0/8536
## TRUE       4  137 0.028369   =4/141
## Totals  8540  137 0.000461  =4/8677
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold       value idx
## 1                       max f1  0.627327    0.985612 124
## 2                       max f2  0.627327    0.977175 124
## 3                 max f0point5  0.627327    0.994194 124
## 4                 max accuracy  0.627327    0.999539 124
## 5                max precision  0.912168    1.000000   0
## 6                   max recall  0.004021    1.000000 343
## 7              max specificity  0.912168    1.000000   0
## 8             max absolute_mcc  0.627327    0.985483 124
## 9   max min_per_class_accuracy  0.015016    0.985816 170
## 10 max mean_per_class_accuracy  0.027117    0.988600 134
## 11                     max tns  0.912168 8536.000000   0
## 12                     max fns  0.912168  140.000000   0
## 13                     max fps  0.003120 8536.000000 399
## 14                     max tps  0.004021  141.000000 343
## 15                     max tnr  0.912168    1.000000   0
## 16                     max fnr  0.912168    0.992908   0
## 17                     max fpr  0.003120    1.000000 399
## 18                     max tpr  0.004021    1.000000 343
## 
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: stackedensemble
## ** Reported on cross-validation data. **
## ** 5-fold cross-validation on training data (Metrics computed for combined holdout predictions) **
## 
## MSE:  0.0005149152
## RMSE:  0.02269174
## LogLoss:  0.004125167
## Mean Per-Class Error:  0.01798561
## AUC:  0.9937849
## AUCPR:  0.9742133
## Gini:  0.9875699
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        FALSE TRUE    Error       Rate
## FALSE  48017    0 0.000000   =0/48017
## TRUE      25  670 0.035971    =25/695
## Totals 48042  670 0.000513  =25/48712
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold        value idx
## 1                       max f1  0.957948     0.981685 140
## 2                       max f2  0.957948     0.971014 140
## 3                 max f0point5  0.957948     0.992593 140
## 4                 max accuracy  0.957948     0.999487 140
## 5                max precision  0.999450     1.000000   0
## 6                   max recall  0.000264     1.000000 395
## 7              max specificity  0.999450     1.000000   0
## 8             max absolute_mcc  0.957948     0.981594 140
## 9   max min_per_class_accuracy  0.002879     0.976050 273
## 10 max mean_per_class_accuracy  0.957948     0.982014 140
## 11                     max tns  0.999450 48017.000000   0
## 12                     max fns  0.999450   694.000000   0
## 13                     max fps  0.000221 48017.000000 399
## 14                     max tps  0.000264   695.000000 395
## 15                     max tnr  0.999450     1.000000   0
## 16                     max fnr  0.999450     0.998561   0
## 17                     max fpr  0.000221     1.000000 399
## 18                     max tpr  0.000264     1.000000 395
## 
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## Cross-Validation Metrics Summary: 
##               mean       sd cv_1_valid cv_2_valid cv_3_valid cv_4_valid
## accuracy  0.999487 0.000072   0.999385   0.999484   0.999492   0.999588
## auc       0.994158 0.004146   0.988600   0.993990   0.992179   0.999463
## err       0.000513 0.000072   0.000615   0.000516   0.000508   0.000412
## err_count 5.000000 0.707107   6.000000   5.000000   5.000000   4.000000
## f0point5  0.992560 0.001162   0.990991   0.992424   0.993548   0.993837
##           cv_5_valid
## accuracy    0.999485
## auc         0.996560
## err         0.000515
## err_count   5.000000
## f0point5    0.992000
## 
## ---
##                        mean        sd cv_1_valid cv_2_valid cv_3_valid
## precision          1.000000  0.000000   1.000000   1.000000   1.000000
## r2                 0.963301  0.005646   0.955734   0.962662   0.967950
## recall             0.963895  0.005475   0.956522   0.963235   0.968553
## residual_deviance 79.477200 15.236052 100.412210  78.300640  81.349570
## rmse               0.022628  0.001624   0.024838   0.022727   0.022559
## specificity        1.000000  0.000000   1.000000   1.000000   1.000000
##                   cv_4_valid cv_5_valid
## precision           1.000000   1.000000
## r2                  0.969656   0.960502
## recall              0.969925   0.961240
## residual_deviance  57.449340  79.874245
## rmse                0.020255   0.022763
## specificity         1.000000   1.000000
best_model <- models_h2o@leader

Save and Load

?h2o.getModel
?h2o.saveModel
?h2o.loadModel

# h2o.getModel("GLM_1_AutoML_4_20240423_111307") %>%
   # h2o.saveModel("h2o_models/")

# best_model <- h2o.loadModel("h2o_models/GLM_1_AutoML_4_20240423_111307")

Make predictions

predictions <- h2o.predict(best_model, newdata = test_h2o)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
predictions_tbl <- predictions %>%
    as.tibble()
## Warning: `as.tibble()` was deprecated in tibble 2.0.0.
## ℹ Please use `as_tibble()` instead.
## ℹ The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
predictions_tbl %>%
    bind_cols(test_tbl)
## # A tibble: 19,130 × 24
##    predict FALSE.   TRUE. expedition_id member_id peak_id peak_name  year season
##    <fct>    <dbl>   <dbl> <chr>         <chr>     <chr>   <chr>     <dbl> <chr> 
##  1 FALSE    0.994 0.00552 AMAD78301     AMAD7830… AMAD    Ama Dabl…  1978 Autumn
##  2 FALSE    0.995 0.00487 AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
##  3 FALSE    0.993 0.00682 AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
##  4 FALSE    0.987 0.0135  AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
##  5 FALSE    0.993 0.00657 AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
##  6 FALSE    0.996 0.00392 AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
##  7 FALSE    0.995 0.00470 AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
##  8 FALSE    0.996 0.00394 AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
##  9 FALSE    0.992 0.00758 AMAD79101     AMAD7910… AMAD    Ama Dabl…  1979 Spring
## 10 FALSE    0.996 0.00402 AMAD79301     AMAD7930… AMAD    Ama Dabl…  1979 Autumn
## # ℹ 19,120 more rows
## # ℹ 15 more variables: sex <chr>, age <dbl>, citizenship <chr>,
## #   expedition_role <chr>, hired <lgl>, highpoint_metres <dbl>, success <lgl>,
## #   solo <lgl>, oxygen_used <lgl>, died <lgl>, death_cause <chr>,
## #   death_height_metres <dbl>, injured <lgl>, injury_type <chr>,
## #   injury_height_metres <dbl>

Evaluate model

?h2o.performance
performance_h2o <- h2o.performance(best_model, newdata = test_h2o)
typeof(performance_h2o)
## [1] "S4"
slotNames(performance_h2o)
## [1] "algorithm" "on_train"  "on_valid"  "on_xval"   "metrics"
performance_h2o@metrics
## $model
## $model$`__meta`
## $model$`__meta`$schema_version
## [1] 3
## 
## $model$`__meta`$schema_name
## [1] "ModelKeyV3"
## 
## $model$`__meta`$schema_type
## [1] "Key<Model>"
## 
## 
## $model$name
## [1] "StackedEnsemble_BestOfFamily_1_AutoML_21_20240430_114612"
## 
## $model$type
## [1] "Key<Model>"
## 
## $model$URL
## [1] "/3/Models/StackedEnsemble_BestOfFamily_1_AutoML_21_20240430_114612"
## 
## 
## $model_checksum
## [1] "2571579368806993928"
## 
## $frame
## $frame$name
## [1] "test_tbl_sid_9611_3"
## 
## 
## $frame_checksum
## [1] "678340420273909232"
## 
## $description
## NULL
## 
## $scoring_time
## [1] 1.714492e+12
## 
## $predictions
## NULL
## 
## $MSE
## [1] 0.001620983
## 
## $RMSE
## [1] 0.04026143
## 
## $nobs
## [1] 19130
## 
## $custom_metric_name
## NULL
## 
## $custom_metric_value
## [1] 0
## 
## $r2
## [1] 0.8835062
## 
## $logloss
## [1] 0.01133142
## 
## $AUC
## [1] 0.9940374
## 
## $pr_auc
## [1] 0.9850477
## 
## $Gini
## [1] 0.9880747
## 
## $mean_per_class_error
## [1] 0.01666667
## 
## $domain
## [1] "FALSE" "TRUE" 
## 
## $cm
## $cm$`__meta`
## $cm$`__meta`$schema_version
## [1] 3
## 
## $cm$`__meta`$schema_name
## [1] "ConfusionMatrixV3"
## 
## $cm$`__meta`$schema_type
## [1] "ConfusionMatrix"
## 
## 
## $cm$table
## Confusion Matrix: Row labels: Actual class; Column labels: Predicted class
##        FALSE TRUE  Error         Rate
## FALSE  18860    0 0.0000 = 0 / 18,860
## TRUE       9  261 0.0333 =    9 / 270
## Totals 18869  261 0.0005 = 9 / 19,130
## 
## 
## $thresholds_and_metric_scores
## Metrics for Thresholds: Binomial metrics as a function of classification thresholds
##   threshold       f1       f2 f0point5 accuracy precision   recall specificity
## 1  0.915912 0.007380 0.004625 0.018248 0.985938  1.000000 0.003704    1.000000
## 2  0.897616 0.014706 0.009242 0.035971 0.985991  1.000000 0.007407    1.000000
## 3  0.889059 0.021978 0.013850 0.053191 0.986043  1.000000 0.011111    1.000000
## 4  0.888402 0.029197 0.018450 0.069930 0.986095  1.000000 0.014815    1.000000
## 5  0.887458 0.036364 0.023041 0.086207 0.986147  1.000000 0.018519    1.000000
##   absolute_mcc min_per_class_accuracy mean_per_class_accuracy   tns fns fps tps
## 1     0.060429               0.003704                0.501852 18860 269   0   1
## 2     0.085461               0.007407                0.503704 18860 268   0   2
## 3     0.104671               0.011111                0.505556 18860 267   0   3
## 4     0.120867               0.014815                0.507407 18860 266   0   4
## 5     0.135137               0.018519                0.509259 18860 265   0   5
##        tnr      fnr      fpr      tpr idx
## 1 1.000000 0.996296 0.000000 0.003704   0
## 2 1.000000 0.992593 0.000000 0.007407   1
## 3 1.000000 0.988889 0.000000 0.011111   2
## 4 1.000000 0.985185 0.000000 0.014815   3
## 5 1.000000 0.981481 0.000000 0.018519   4
## 
## ---
##     threshold       f1       f2 f0point5 accuracy precision   recall
## 395  0.003238 0.029462 0.070537 0.018619 0.070099  0.014951 1.000000
## 396  0.003215 0.029026 0.069537 0.018341 0.055724  0.014727 1.000000
## 397  0.003190 0.028584 0.068521 0.018058 0.040669  0.014499 1.000000
## 398  0.003169 0.028284 0.067832 0.017867 0.030214  0.014345 1.000000
## 399  0.003153 0.028042 0.067275 0.017712 0.021589  0.014220 1.000000
## 400  0.003137 0.027835 0.066799 0.017580 0.014114  0.014114 1.000000
##     specificity absolute_mcc min_per_class_accuracy mean_per_class_accuracy
## 395    0.056787     0.029138               0.056787                0.528393
## 396    0.042206     0.024931               0.042206                0.521103
## 397    0.026935     0.019762               0.026935                0.513468
## 398    0.016331     0.015306               0.016331                0.508165
## 399    0.007582     0.010384               0.007582                0.503791
## 400    0.000000     0.000000               0.000000                0.500000
##      tns fns   fps tps      tnr      fnr      fpr      tpr idx
## 395 1071   0 17789 270 0.056787 0.000000 0.943213 1.000000 394
## 396  796   0 18064 270 0.042206 0.000000 0.957794 1.000000 395
## 397  508   0 18352 270 0.026935 0.000000 0.973065 1.000000 396
## 398  308   0 18552 270 0.016331 0.000000 0.983669 1.000000 397
## 399  143   0 18717 270 0.007582 0.000000 0.992418 1.000000 398
## 400    0   0 18860 270 0.000000 0.000000 1.000000 1.000000 399
## 
## $max_criteria_and_metric_scores
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold        value idx
## 1                       max f1  0.586446     0.983051 176
## 2                       max f2  0.031377     0.980755 181
## 3                 max f0point5  0.586446     0.993151 176
## 4                 max accuracy  0.586446     0.999530 176
## 5                max precision  0.915912     1.000000   0
## 6                   max recall  0.003644     1.000000 372
## 7              max specificity  0.915912     1.000000   0
## 8             max absolute_mcc  0.586446     0.982958 176
## 9   max min_per_class_accuracy  0.017392     0.985185 211
## 10 max mean_per_class_accuracy  0.031377     0.990582 181
## 11                     max tns  0.915912 18860.000000   0
## 12                     max fns  0.915912   269.000000   0
## 13                     max fps  0.003137 18860.000000 399
## 14                     max tps  0.003644   270.000000 372
## 15                     max tnr  0.915912     1.000000   0
## 16                     max fnr  0.915912     0.996296   0
## 17                     max fpr  0.003137     1.000000 399
## 18                     max tpr  0.003644     1.000000 372
## 
## $gains_lift_table
## Gains/Lift Table: Avg response rate:  1.41 %, avg score:  1.45 %
##    group cumulative_data_fraction lower_threshold      lift cumulative_lift
## 1      1               0.01003659        0.681112 70.851852       70.851852
## 2      2               0.02002091        0.017363 27.450456       49.207814
## 3      3               0.03037114        0.012151  0.000000       32.438197
## 4      4               0.04004182        0.010209  0.000000       24.603907
## 5      5               0.05013068        0.008637  0.000000       19.652338
## 6      6               0.10000000        0.006689  0.074268        9.888889
## 7      7               0.15018296        0.005893  0.000000        6.584561
## 8      8               0.20010455        0.005731  0.000000        4.941861
## 9      9               0.30000000        0.005532  0.000000        3.296296
## 10    10               0.40000000        0.004474  0.000000        2.472222
## 11    11               0.50000000        0.003958  0.074074        1.992593
## 12    12               0.60000000        0.003690  0.000000        1.660494
## 13    13               0.70000000        0.003533  0.037037        1.428571
## 14    14               0.80000000        0.003410  0.000000        1.250000
## 15    15               0.90000000        0.003290  0.000000        1.111111
## 16    16               1.00000000        0.003097  0.000000        1.000000
##    response_rate    score cumulative_response_rate cumulative_score
## 1       1.000000 0.738970                 1.000000         0.738970
## 2       0.387435 0.252440                 0.694517         0.496340
## 3       0.000000 0.014398                 0.457831         0.332098
## 4       0.000000 0.011022                 0.347258         0.254554
## 5       0.000000 0.009252                 0.277372         0.205187
## 6       0.001048 0.007472                 0.139571         0.106588
## 7       0.000000 0.006193                 0.092934         0.073041
## 8       0.000000 0.005802                 0.069749         0.056267
## 9       0.000000 0.005619                 0.046524         0.039402
## 10      0.000000 0.005066                 0.034893         0.030818
## 11      0.001045 0.004189                 0.028123         0.025492
## 12      0.000000 0.003811                 0.023436         0.021878
## 13      0.000523 0.003610                 0.020163         0.019269
## 14      0.000000 0.003470                 0.017642         0.017294
## 15      0.000000 0.003354                 0.015682         0.015745
## 16      0.000000 0.003214                 0.014114         0.014492
##    capture_rate cumulative_capture_rate        gain cumulative_gain
## 1      0.711111                0.711111 6985.185185     6985.185185
## 2      0.274074                0.985185 2645.045569     4820.781356
## 3      0.000000                0.985185 -100.000000     3143.819723
## 4      0.000000                0.985185 -100.000000     2360.390678
## 5      0.000000                0.985185 -100.000000     1865.233847
## 6      0.003704                0.988889  -92.573181      888.888889
## 7      0.000000                0.988889 -100.000000      558.456124
## 8      0.000000                0.988889 -100.000000      394.186114
## 9      0.000000                0.988889 -100.000000      229.629630
## 10     0.000000                0.988889 -100.000000      147.222222
## 11     0.007407                0.996296  -92.592593       99.259259
## 12     0.000000                0.996296 -100.000000       66.049383
## 13     0.003704                1.000000  -96.296296       42.857143
## 14     0.000000                1.000000 -100.000000       25.000000
## 15     0.000000                1.000000 -100.000000       11.111111
## 16     0.000000                1.000000 -100.000000        0.000000
##    kolmogorov_smirnov
## 1            0.711111
## 2            0.978982
## 3            0.968483
## 4            0.958674
## 5            0.948441
## 6            0.901614
## 7            0.850713
## 8            0.800077
## 9            0.698751
## 10           0.597319
## 11           0.503401
## 12           0.401970
## 13           0.304295
## 14           0.202863
## 15           0.101432
## 16           0.000000
## 
## $residual_deviance
## [1] 433.5403
## 
## $null_deviance
## [1] 2836.923
## 
## $AIC
## [1] 439.5403
## 
## $loglikelihood
## [1] 0
## 
## $null_degrees_of_freedom
## [1] 19129
## 
## $residual_degrees_of_freedom
## [1] 19127
h2o.auc(best_model)
## [1] 0.9999169
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.586446376329621:
##        FALSE TRUE    Error      Rate
## FALSE  18860    0 0.000000  =0/18860
## TRUE       9  261 0.033333    =9/270
## Totals 18869  261 0.000470  =9/19130
h2o.metric(performance_h2o) %>% as_tibble() %>% filter(threshold %>% between(0.98, 0.99))
## # A tibble: 0 × 20
## # ℹ 20 variables: threshold <dbl>, f1 <dbl>, f2 <dbl>, f0point5 <dbl>,
## #   accuracy <dbl>, precision <dbl>, recall <dbl>, specificity <dbl>,
## #   absolute_mcc <dbl>, min_per_class_accuracy <dbl>,
## #   mean_per_class_accuracy <dbl>, tns <dbl>, fns <dbl>, fps <dbl>, tps <dbl>,
## #   tnr <dbl>, fnr <dbl>, fpr <dbl>, tpr <dbl>, idx <int>