Goal is to automate building and tuning a classification model to predict employee attrition, 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()
## • Search for functions across packages at https://www.tidymodels.org/find/
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 <- read_csv("../00_data/data_wrangled/data_clean.csv") %>%
    
    # h2o requires all variables to be either numeric or factors
    mutate(across(where(is.character), factor))
## Rows: 1470 Columns: 32
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (8): Attrition, BusinessTravel, Department, EducationField, Gender, Job...
## dbl (24): Age, DailyRate, DistanceFromHome, Education, EmployeeNumber, Envir...
## 
## ℹ 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.

Split data

set.seed(1234)

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

Recipes

recipe_obj <- recipe(Attrition ~ ., 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.99 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 <- "Attrition"
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%
  |                                                                            
  |===                                                                   |   4%
## 11:38:38.567: 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.
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================| 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   logloss
## 1 StackedEnsemble_BestOfFamily_1_AutoML_19_20240430_113838 0.8295038 0.3281184
## 2                          GLM_1_AutoML_19_20240430_113838 0.8269687 0.3310361
## 3 StackedEnsemble_BestOfFamily_3_AutoML_19_20240430_113838 0.8242179 0.3323141
## 4 StackedEnsemble_BestOfFamily_2_AutoML_19_20240430_113838 0.8236246 0.3333811
## 5    StackedEnsemble_AllModels_2_AutoML_19_20240430_113838 0.8209817 0.3325003
## 6                      XGBoost_1_AutoML_19_20240430_113838 0.8194714 0.3426538
##       aucpr mean_per_class_error      rmse        mse
## 1 0.9515786            0.2946602 0.3097197 0.09592630
## 2 0.9469916            0.2796117 0.3081993 0.09498682
## 3 0.9478006            0.3013754 0.3106001 0.09647245
## 4 0.9458118            0.3013754 0.3102831 0.09627562
## 5 0.9475893            0.3097087 0.3114966 0.09703014
## 6 0.9479057            0.2877023 0.3186393 0.10153097
## 
## [29 rows x 7 columns]
models_h2o@leader
## Model Details:
## ==============
## 
## H2OBinomialModel: stackedensemble
## Model ID:  StackedEnsemble_BestOfFamily_1_AutoML_19_20240430_113838 
## Model Summary for Stacked Ensemble: 
##                                     key            value
## 1                     Stacking strategy cross_validation
## 2  Number of base models (used / total)              3/3
## 3      # GBM base models (used / total)              1/1
## 4  # XGBoost base models (used / total)              1/1
## 5      # GLM base models (used / total)              1/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.07243405
## RMSE:  0.2691357
## LogLoss:  0.2560715
## Mean Per-Class Error:  0.2006612
## AUC:  0.9131483
## AUCPR:  0.9752321
## Gini:  0.8262966
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        Left  No    Error     Rate
## Left     95  59 0.383117  =59/154
## No       14 755 0.018205  =14/769
## Totals  109 814 0.079090  =73/923
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.563305   0.953885 300
## 2                       max f2  0.387781   0.973316 339
## 3                 max f0point5  0.634497   0.945223 279
## 4                 max accuracy  0.612028   0.920910 286
## 5                max precision  0.998821   1.000000   0
## 6                   max recall  0.307987   1.000000 356
## 7              max specificity  0.998821   1.000000   0
## 8             max absolute_mcc  0.612028   0.698562 286
## 9   max min_per_class_accuracy  0.805352   0.831169 196
## 10 max mean_per_class_accuracy  0.749296   0.846035 230
## 11                     max tns  0.998821 154.000000   0
## 12                     max fns  0.998821 767.000000   0
## 13                     max fps  0.043550 154.000000 399
## 14                     max tps  0.307987 769.000000 356
## 15                     max tnr  0.998821   1.000000   0
## 16                     max fnr  0.998821   0.997399   0
## 17                     max fpr  0.043550   1.000000 399
## 18                     max tpr  0.307987   1.000000 356
## 
## 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.06682641
## RMSE:  0.258508
## LogLoss:  0.2484445
## Mean Per-Class Error:  0.1835905
## AUC:  0.8824684
## AUCPR:  0.9741389
## Gini:  0.7649369
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        Left  No    Error     Rate
## Left     15   8 0.347826    =8/23
## No        3 152 0.019355   =3/155
## Totals   18 160 0.061798  =11/178
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.555140   0.965079 159
## 2                       max f2  0.481337   0.983503 167
## 3                 max f0point5  0.650284   0.963303 151
## 4                 max accuracy  0.555140   0.938202 159
## 5                max precision  0.997148   1.000000   0
## 6                   max recall  0.481337   1.000000 167
## 7              max specificity  0.997148   1.000000   0
## 8             max absolute_mcc  0.555140   0.704066 159
## 9   max min_per_class_accuracy  0.810037   0.819355 130
## 10 max mean_per_class_accuracy  0.650284   0.865498 151
## 11                     max tns  0.997148  23.000000   0
## 12                     max fns  0.997148 154.000000   0
## 13                     max fps  0.031089  23.000000 177
## 14                     max tps  0.481337 155.000000 167
## 15                     max tnr  0.997148   1.000000   0
## 16                     max fnr  0.997148   0.993548   0
## 17                     max fpr  0.031089   1.000000 177
## 18                     max tpr  0.481337   1.000000 167
## 
## 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.09599907
## RMSE:  0.3098372
## LogLoss:  0.3301214
## Mean Per-Class Error:  0.3045615
## AUC:  0.8371304
## AUCPR:  0.9469827
## Gini:  0.6742607
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        Left  No    Error      Rate
## Left     64  90 0.584416   =90/154
## No       19 750 0.024707   =19/769
## Totals   83 840 0.118093  =109/923
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.514072   0.932256 328
## 2                       max f2  0.317557   0.965995 373
## 3                 max f0point5  0.744478   0.919350 236
## 4                 max accuracy  0.514072   0.881907 328
## 5                max precision  0.998861   1.000000   0
## 6                   max recall  0.220023   1.000000 387
## 7              max specificity  0.998861   1.000000   0
## 8             max absolute_mcc  0.661111   0.517520 276
## 9   max min_per_class_accuracy  0.833929   0.754226 182
## 10 max mean_per_class_accuracy  0.744478   0.778486 236
## 11                     max tns  0.998861 154.000000   0
## 12                     max fns  0.998861 766.000000   0
## 13                     max fps  0.059958 154.000000 399
## 14                     max tps  0.220023 769.000000 387
## 15                     max tnr  0.998861   1.000000   0
## 16                     max fnr  0.998861   0.996099   0
## 17                     max fpr  0.059958   1.000000 399
## 18                     max tpr  0.220023   1.000000 387
## 
## 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.886466 0.014695   0.876405   0.890000   0.867021   0.895288
## auc        0.838469 0.022919   0.862905   0.806471   0.858289   0.829881
## err        0.113534 0.014695   0.123596   0.110000   0.132979   0.104712
## err_count 21.000000 3.316625  22.000000  22.000000  25.000000  20.000000
## f0point5   0.908853 0.012312   0.899873   0.906183   0.900243   0.908046
##           cv_5_valid
## accuracy    0.903614
## auc         0.834800
## err         0.096386
## err_count  16.000000
## f0point5    0.929919
## 
## ---
##                         mean        sd cv_1_valid cv_2_valid cv_3_valid
## precision           0.892254  0.015649   0.881988   0.885417   0.886228
## r2                  0.306176  0.042649   0.340557   0.251995   0.333107
## recall              0.982436  0.017299   0.979310   1.000000   0.961039
## residual_deviance 121.534590 13.034665 117.335590 133.204570 125.354195
## rmse                0.309476  0.005866   0.315580   0.308821   0.314318
## specificity         0.405205  0.086548   0.424242   0.266667   0.441176
##                   cv_4_valid cv_5_valid
## precision           0.887641   0.920000
## r2                  0.337306   0.267915
## recall              1.000000   0.971831
## residual_deviance 130.846920 100.931660
## rmse                0.307758   0.300900
## specificity         0.393939   0.500000
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: 369 × 35
##    predict   Left    No   Age Attrition BusinessTravel    DailyRate Department  
##    <fct>    <dbl> <dbl> <dbl> <fct>     <fct>                 <dbl> <fct>       
##  1 No      0.436  0.564    41 Left      Travel_Rarely          1102 Sales       
##  2 No      0.0234 0.977    49 No        Travel_Frequently       279 Research & …
##  3 No      0.391  0.609    33 No        Travel_Frequently      1392 Research & …
##  4 No      0.251  0.749    59 No        Travel_Rarely          1324 Research & …
##  5 No      0.0807 0.919    38 No        Travel_Frequently       216 Research & …
##  6 No      0.368  0.632    29 No        Travel_Rarely           153 Research & …
##  7 No      0.0431 0.957    34 No        Travel_Rarely          1346 Research & …
##  8 Left    0.888  0.112    28 Left      Travel_Rarely           103 Research & …
##  9 No      0.310  0.690    22 No        Non-Travel             1123 Research & …
## 10 No      0.0308 0.969    53 No        Travel_Rarely          1219 Sales       
## # ℹ 359 more rows
## # ℹ 27 more variables: DistanceFromHome <dbl>, Education <dbl>,
## #   EducationField <fct>, EmployeeNumber <dbl>, EnvironmentSatisfaction <dbl>,
## #   Gender <fct>, HourlyRate <dbl>, JobInvolvement <dbl>, JobLevel <dbl>,
## #   JobRole <fct>, JobSatisfaction <dbl>, MaritalStatus <fct>,
## #   MonthlyIncome <dbl>, MonthlyRate <dbl>, NumCompaniesWorked <dbl>,
## #   OverTime <fct>, PercentSalaryHike <dbl>, PerformanceRating <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_19_20240430_113838"
## 
## $model$type
## [1] "Key<Model>"
## 
## $model$URL
## [1] "/3/Models/StackedEnsemble_BestOfFamily_1_AutoML_19_20240430_113838"
## 
## 
## $model_checksum
## [1] "-4116832895039817680"
## 
## $frame
## $frame$name
## [1] "test_tbl_sid_bf5c_3"
## 
## 
## $frame_checksum
## [1] "-54192601206779456"
## 
## $description
## NULL
## 
## $scoring_time
## [1] 1.714492e+12
## 
## $predictions
## NULL
## 
## $MSE
## [1] 0.0959263
## 
## $RMSE
## [1] 0.3097197
## 
## $nobs
## [1] 369
## 
## $custom_metric_name
## NULL
## 
## $custom_metric_value
## [1] 0
## 
## $r2
## [1] 0.2955005
## 
## $logloss
## [1] 0.3281184
## 
## $AUC
## [1] 0.8295038
## 
## $pr_auc
## [1] 0.9515786
## 
## $Gini
## [1] 0.6590076
## 
## $mean_per_class_error
## [1] 0.2946602
## 
## $domain
## [1] "Left" "No"  
## 
## $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
##        Left  No  Error       Rate
## Left     26  34 0.5667 =  34 / 60
## No        7 302 0.0227 =  7 / 309
## Totals   33 336 0.1111 = 41 / 369
## 
## 
## $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.998336 0.006452 0.004042 0.015974 0.165312  1.000000 0.003236    1.000000
## 2  0.998329 0.012862 0.008078 0.031546 0.168022  1.000000 0.006472    1.000000
## 3  0.998118 0.019231 0.012107 0.046729 0.170732  1.000000 0.009709    1.000000
## 4  0.997497 0.025559 0.016129 0.061538 0.173442  1.000000 0.012945    1.000000
## 5  0.997362 0.031847 0.020145 0.075988 0.176152  1.000000 0.016181    1.000000
##   absolute_mcc min_per_class_accuracy mean_per_class_accuracy tns fns fps tps
## 1     0.022971               0.003236                0.501618  60 308   0   1
## 2     0.032530               0.006472                0.503236  60 307   0   2
## 3     0.039895               0.009709                0.504854  60 306   0   3
## 4     0.046130               0.012945                0.506472  60 305   0   4
## 5     0.051645               0.016181                0.508091  60 304   0   5
##        tnr      fnr      fpr      tpr idx
## 1 1.000000 0.996764 0.000000 0.003236   0
## 2 1.000000 0.993528 0.000000 0.006472   1
## 3 1.000000 0.990291 0.000000 0.009709   2
## 4 1.000000 0.987055 0.000000 0.012945   3
## 5 1.000000 0.983819 0.000000 0.016181   4
## 
## ---
##     threshold       f1       f2 f0point5 accuracy precision   recall
## 364  0.193350 0.918276 0.965625 0.875354 0.850949  0.848901 1.000000
## 365  0.162010 0.916914 0.965022 0.873375 0.848238  0.846575 1.000000
## 366  0.131237 0.915556 0.964419 0.871404 0.845528  0.844262 1.000000
## 367  0.112196 0.914201 0.963818 0.869443 0.842818  0.841962 1.000000
## 368  0.042625 0.912851 0.963217 0.867490 0.840108  0.839674 1.000000
## 369  0.040768 0.911504 0.962617 0.865546 0.837398  0.837398 1.000000
##     specificity absolute_mcc min_per_class_accuracy mean_per_class_accuracy tns
## 364    0.083333     0.265973               0.083333                0.541667   5
## 365    0.066667     0.237568               0.066667                0.533333   4
## 366    0.050000     0.205458               0.050000                0.525000   3
## 367    0.033333     0.167527               0.033333                0.516667   2
## 368    0.016667     0.118299               0.016667                0.508333   1
## 369    0.000000     0.000000               0.000000                0.500000   0
##     fns fps tps      tnr      fnr      fpr      tpr idx
## 364   0  55 309 0.083333 0.000000 0.916667 1.000000 363
## 365   0  56 309 0.066667 0.000000 0.933333 1.000000 364
## 366   0  57 309 0.050000 0.000000 0.950000 1.000000 365
## 367   0  58 309 0.033333 0.000000 0.966667 1.000000 366
## 368   0  59 309 0.016667 0.000000 0.983333 1.000000 367
## 369   0  60 309 0.000000 0.000000 1.000000 1.000000 368
## 
## $max_criteria_and_metric_scores
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.431163   0.936434 335
## 2                       max f2  0.333800   0.969163 352
## 3                 max f0point5  0.608785   0.918627 315
## 4                 max accuracy  0.431163   0.888889 335
## 5                max precision  0.998336   1.000000   0
## 6                   max recall  0.227134   1.000000 360
## 7              max specificity  0.998336   1.000000   0
## 8             max absolute_mcc  0.431163   0.531045 335
## 9   max min_per_class_accuracy  0.840526   0.750000 246
## 10 max mean_per_class_accuracy  0.814673   0.759628 264
## 11                     max tns  0.998336  60.000000   0
## 12                     max fns  0.998336 308.000000   0
## 13                     max fps  0.040768  60.000000 368
## 14                     max tps  0.227134 309.000000 360
## 15                     max tnr  0.998336   1.000000   0
## 16                     max fnr  0.998336   0.996764   0
## 17                     max fpr  0.040768   1.000000 368
## 18                     max tpr  0.227134   1.000000 360
## 
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 83.74 %, avg score: 82.94 %
##    group cumulative_data_fraction lower_threshold     lift cumulative_lift
## 1      1               0.01084011        0.997405 1.194175        1.194175
## 2      2               0.02168022        0.996422 1.194175        1.194175
## 3      3               0.03252033        0.995477 1.194175        1.194175
## 4      4               0.04065041        0.993970 1.194175        1.194175
## 5      5               0.05149051        0.992949 1.194175        1.194175
## 6      6               0.10027100        0.988886 1.127832        1.161900
## 7      7               0.15176152        0.984330 1.131323        1.151526
## 8      8               0.20054201        0.979802 1.194175        1.161900
## 9      9               0.30081301        0.967011 1.129625        1.151141
## 10    10               0.40108401        0.949897 1.129625        1.145762
## 11    11               0.50135501        0.919002 1.097350        1.136080
## 12    12               0.59891599        0.880412 1.127832        1.134736
## 13    13               0.69918699        0.818078 1.000525        1.115489
## 14    14               0.79945799        0.714733 1.000525        1.101070
## 15    15               0.89972900        0.489309 0.871425        1.075477
## 16    16               1.00000000        0.040768 0.322750        1.000000
##    response_rate    score cumulative_response_rate cumulative_score
## 1       1.000000 0.998070                 1.000000         0.998070
## 2       1.000000 0.997113                 1.000000         0.997591
## 3       1.000000 0.995820                 1.000000         0.997001
## 4       1.000000 0.994451                 1.000000         0.996491
## 5       1.000000 0.993601                 1.000000         0.995882
## 6       0.944444 0.990790                 0.972973         0.993405
## 7       0.947368 0.987058                 0.964286         0.991252
## 8       1.000000 0.982354                 0.972973         0.989087
## 9       0.945946 0.972292                 0.963964         0.983489
## 10      0.945946 0.957669                 0.959459         0.977034
## 11      0.918919 0.937192                 0.951351         0.969065
## 12      0.944444 0.896925                 0.950226         0.957314
## 13      0.837838 0.851016                 0.934109         0.942070
## 14      0.837838 0.778395                 0.922034         0.921541
## 15      0.729730 0.610855                 0.900602         0.886916
## 16      0.270270 0.313308                 0.837398         0.829400
##    capture_rate cumulative_capture_rate       gain cumulative_gain
## 1      0.012945                0.012945  19.417476       19.417476
## 2      0.012945                0.025890  19.417476       19.417476
## 3      0.012945                0.038835  19.417476       19.417476
## 4      0.009709                0.048544  19.417476       19.417476
## 5      0.012945                0.061489  19.417476       19.417476
## 6      0.055016                0.116505  12.783172       16.189976
## 7      0.058252                0.174757  13.132345       15.152566
## 8      0.058252                0.233010  19.417476       16.189976
## 9      0.113269                0.346278  12.962477       15.114143
## 10     0.113269                0.459547  12.962477       14.576227
## 11     0.110032                0.569579   9.734978       13.607977
## 12     0.110032                0.679612  12.783172       13.473619
## 13     0.100324                0.779935   0.052480       11.548882
## 14     0.100324                0.880259   0.052480       10.106961
## 15     0.087379                0.967638 -12.857518        7.547666
## 16     0.032362                1.000000 -67.725007        0.000000
##    kolmogorov_smirnov
## 1            0.012945
## 2            0.025890
## 3            0.038835
## 4            0.048544
## 5            0.061489
## 6            0.099838
## 7            0.141424
## 8            0.199676
## 9            0.279612
## 10           0.359547
## 11           0.419579
## 12           0.496278
## 13           0.496602
## 14           0.496926
## 15           0.417638
## 16           0.000000
## 
## $residual_deviance
## [1] 242.1514
## 
## $null_deviance
## [1] 327.6898
## 
## $AIC
## [1] 250.1514
## 
## $loglikelihood
## [1] 0
## 
## $null_degrees_of_freedom
## [1] 368
## 
## $residual_degrees_of_freedom
## [1] 365
h2o.auc(best_model)
## [1] 0.9131483
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.431163495747449:
##        Left  No    Error     Rate
## Left     26  34 0.566667   =34/60
## No        7 302 0.022654   =7/309
## Totals   33 336 0.111111  =41/369
h2o.metric(performance_h2o) %>% as_tibble() %>% filter(threshold %>% between(0.43, 0.44))
## # A tibble: 1 × 20
##   threshold    f1    f2 f0point5 accuracy precision recall specificity
##       <dbl> <dbl> <dbl>    <dbl>    <dbl>     <dbl>  <dbl>       <dbl>
## 1     0.431 0.936 0.961    0.913    0.889     0.899  0.977       0.433
## # ℹ 12 more variables: 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>