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.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ 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.2.0 ──
## ✔ broom        1.0.5      ✔ rsample      1.2.1 
## ✔ dials        1.2.1      ✔ tune         1.2.0 
## ✔ infer        1.0.7      ✔ workflows    1.1.4 
## ✔ modeldata    1.3.0      ✔ workflowsets 1.1.0 
## ✔ parsnip      1.2.1      ✔ yardstick    1.3.1 
## ✔ recipes      1.0.10     
## ── 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()
## • Learn how to get started at https://www.tidymodels.org/start/
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:         49 minutes 23 seconds 
##     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 18 days 
##     H2O cluster name:           H2O_started_from_R_maddie_qns693 
##     H2O cluster total nodes:    1 
##     H2O cluster total memory:   1.68 GB 
##     H2O cluster total cores:    4 
##     H2O cluster allowed cores:  4 
##     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.3 (2024-02-29)
## Warning in h2o.clusterInfo(): 
## Your H2O cluster version is (4 months and 18 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.h2o <- h2o.splitFrame(as.h2o(train_tbl), ratios = c(0.85), seed = 2345)
##   |                                                                              |                                                                      |   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, 
    max_models        = 10, 
    exclude_algos     = "DeepLearning",
    nfolds            = 5, 
    seed              = 3456   
)
##   |                                                                              |                                                                      |   0%
## 12:08:10.450: 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.  |                                                                              |====                                                                  |   5%  |                                                                              |=======                                                               |  10%  |                                                                              |===========                                                           |  15%  |                                                                              |==============                                                        |  21%  |                                                                              |====================                                                  |  28%  |                                                                              |======================================================================| 100%

Examine the output of h20.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                          GBM_1_AutoML_5_20240509_120810 0.8552319 0.3243584
## 2                          GLM_1_AutoML_5_20240509_120810 0.8400216 0.3186222
## 3 StackedEnsemble_BestOfFamily_1_AutoML_5_20240509_120810 0.8386731 0.3679170
## 4    StackedEnsemble_AllModels_1_AutoML_5_20240509_120810 0.8330097 0.3360015
## 5                      XGBoost_1_AutoML_5_20240509_120810 0.8303128 0.3350992
## 6                          GBM_2_AutoML_5_20240509_120810 0.8120820 0.3397394
##       aucpr mean_per_class_error      rmse        mse
## 1 0.6161812            0.2221683 0.3118296 0.09723772
## 2 0.6515822            0.2369741 0.3064601 0.09391777
## 3 0.6224065            0.2087379 0.3035404 0.09213679
## 4 0.6167542            0.2087379 0.3044454 0.09268702
## 5 0.5727296            0.2367314 0.3163680 0.10008873
## 6 0.5663229            0.2165858 0.3174311 0.10076251
## 
## [12 rows x 7 columns]
models_h2o@leader
## Model Details:
## ==============
## 
## H2OBinomialModel: gbm
## Model ID:  GBM_1_AutoML_5_20240509_120810 
## Model Summary: 
##   number_of_trees number_of_internal_trees model_size_in_bytes min_depth
## 1              59                       59                7762         3
##   max_depth mean_depth min_leaves max_leaves mean_leaves
## 1         5    3.93220          5          7     5.81356
## 
## 
## H2OBinomialMetrics: gbm
## ** Reported on training data. **
## 
## MSE:  0.07760747
## RMSE:  0.2785812
## LogLoss:  0.2692952
## Mean Per-Class Error:  0.1906261
## AUC:  0.9218063
## AUCPR:  0.795637
## Gini:  0.8436125
## R^2:  0.4223142
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##         No Yes    Error     Rate
## No     766  22 0.027919  =22/788
## Yes     53  97 0.353333  =53/150
## Totals 819 119 0.079957  =75/938
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.333741   0.721190  97
## 2                       max f2  0.189332   0.756155 179
## 3                 max f0point5  0.439043   0.781938  63
## 4                 max accuracy  0.346929   0.920043  91
## 5                max precision  0.852824   1.000000   0
## 6                   max recall  0.039666   1.000000 359
## 7              max specificity  0.852824   1.000000   0
## 8             max absolute_mcc  0.333741   0.681408  97
## 9   max min_per_class_accuracy  0.193072   0.846447 176
## 10 max mean_per_class_accuracy  0.221420   0.851937 152
## 11                     max tns  0.852824 788.000000   0
## 12                     max fns  0.852824 149.000000   0
## 13                     max fps  0.007684 788.000000 399
## 14                     max tps  0.039666 150.000000 359
## 15                     max tnr  0.852824   1.000000   0
## 16                     max fnr  0.852824   0.993333   0
## 17                     max fpr  0.007684   1.000000 399
## 18                     max tpr  0.039666   1.000000 359
## 
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: gbm
## ** Reported on validation data. **
## ** Validation metrics **
## 
## MSE:  0.1054871
## RMSE:  0.3247877
## LogLoss:  0.3436335
## Mean Per-Class Error:  0.2551743
## AUC:  0.8295207
## AUCPR:  0.5567645
## Gini:  0.6590414
## R^2:  0.2367413
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##         No Yes    Error     Rate
## No     122  14 0.102941  =14/136
## Yes     11  16 0.407407   =11/27
## Totals 133  30 0.153374  =25/163
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.309375   0.561404  29
## 2                       max f2  0.126346   0.666667  71
## 3                 max f0point5  0.342225   0.569106  23
## 4                 max accuracy  0.541568   0.865031   4
## 5                max precision  0.842469   1.000000   0
## 6                   max recall  0.035645   1.000000 142
## 7              max specificity  0.842469   1.000000   0
## 8             max absolute_mcc  0.309375   0.469734  29
## 9   max min_per_class_accuracy  0.219496   0.703704  44
## 10 max mean_per_class_accuracy  0.126346   0.767974  71
## 11                     max tns  0.842469 136.000000   0
## 12                     max fns  0.842469  26.000000   0
## 13                     max fps  0.009418 136.000000 162
## 14                     max tps  0.035645  27.000000 142
## 15                     max tnr  0.842469   1.000000   0
## 16                     max fnr  0.842469   0.962963   0
## 17                     max fpr  0.009418   1.000000 162
## 18                     max tpr  0.035645   1.000000 142
## 
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: gbm
## ** Reported on cross-validation data. **
## ** 5-fold cross-validation on training data (Metrics computed for combined holdout predictions) **
## 
## MSE:  0.1021651
## RMSE:  0.3196328
## LogLoss:  0.3464857
## Mean Per-Class Error:  0.2604484
## AUC:  0.8034052
## AUCPR:  0.5856122
## Gini:  0.6068105
## R^2:  0.2395148
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##         No Yes    Error      Rate
## No     719  69 0.087563   =69/788
## Yes     65  85 0.433333   =65/150
## Totals 784 154 0.142857  =134/938
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.274891   0.559211 116
## 2                       max f2  0.162481   0.604925 211
## 3                 max f0point5  0.351807   0.622605  74
## 4                 max accuracy  0.405894   0.879531  50
## 5                max precision  0.846770   1.000000   0
## 6                   max recall  0.012518   1.000000 395
## 7              max specificity  0.846770   1.000000   0
## 8             max absolute_mcc  0.351807   0.487870  74
## 9   max min_per_class_accuracy  0.167255   0.733503 206
## 10 max mean_per_class_accuracy  0.197244   0.741015 177
## 11                     max tns  0.846770 788.000000   0
## 12                     max fns  0.846770 149.000000   0
## 13                     max fps  0.005852 788.000000 399
## 14                     max tps  0.012518 150.000000 395
## 15                     max tnr  0.846770   1.000000   0
## 16                     max fnr  0.846770   0.993333   0
## 17                     max fpr  0.005852   1.000000 399
## 18                     max tpr  0.012518   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
## accuracy                 0.874206 0.015736   0.893617   0.867021   0.856383
## auc                      0.800818 0.046494   0.841983   0.763080   0.753165
## err                      0.125794 0.015736   0.106383   0.132979   0.143617
## err_count               23.600000 2.966479  20.000000  25.000000  27.000000
## f0point5                 0.607235 0.055991   0.669014   0.576923   0.538462
## f1                       0.583766 0.061648   0.655172   0.545455   0.509091
## f2                       0.567463 0.093249   0.641892   0.517241   0.482759
## lift_top_group           6.253334 0.018257   6.266667   6.266667   6.266667
## logloss                  0.347126 0.028586   0.322462   0.375521   0.372290
## max_per_class_error      0.440000 0.118790   0.366667   0.500000   0.533333
## mcc                      0.516979 0.067355   0.592861   0.470996   0.428220
## mean_per_class_accuracy  0.747000 0.050090   0.788186   0.718354   0.698523
## mean_per_class_error     0.253000 0.050090   0.211814   0.281646   0.301477
## mse                      0.102380 0.009717   0.092129   0.112453   0.110710
## pr_auc                   0.582737 0.089843   0.704703   0.500874   0.490292
## precision                0.627903 0.077290   0.678571   0.600000   0.560000
## r2                       0.237864 0.073080   0.313040   0.161491   0.174484
## recall                   0.560000 0.118790   0.633333   0.500000   0.466667
## rmse                     0.319678 0.015247   0.303527   0.335340   0.332732
## specificity              0.934000 0.027641   0.943038   0.936709   0.930380
##                         cv_4_valid cv_5_valid
## accuracy                  0.887701   0.866310
## auc                       0.789172   0.856688
## err                       0.112299   0.133690
## err_count                21.000000  25.000000
## f0point5                  0.660377   0.591398
## f1                        0.571429   0.637681
## f2                        0.503597   0.691824
## lift_top_group            6.233333   6.233333
## logloss                   0.352718   0.312637
## max_per_class_error       0.533333   0.266667
## mcc                       0.528187   0.564630
## mean_per_class_accuracy   0.717410   0.812527
## mean_per_class_error      0.282590   0.187473
## mse                       0.104156   0.092451
## pr_auc                    0.588982   0.628833
## precision                 0.736842   0.564103
## r2                        0.226700   0.313605
## recall                    0.466667   0.733333
## rmse                      0.322733   0.304058
## specificity               0.968153   0.891720

Save and Load

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

# h2o.getModel("GBM_1_AutoML_4_20240509_120305") %>%
  #h2o.saveModel("h20_models/")

best_model <- h2o.loadModel("h20_models/GBM_1_AutoML_4_20240509_120305")

Make predictions

predictions <- h2o.predict(best_model, newdata = test_h2o)
##   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
predictions_tbl <- predictions %>% 
    as_tibble()

predictions_tbl %>% 
    bind_cols(test_tbl)
## # A tibble: 369 × 35
##    predict    No    Yes   Age Attrition BusinessTravel    DailyRate Department  
##    <fct>   <dbl>  <dbl> <dbl> <fct>     <fct>                 <dbl> <fct>       
##  1 Yes     0.649 0.351     59 No        Travel_Rarely          1324 Research & …
##  2 No      0.813 0.187     35 No        Travel_Rarely           809 Research & …
##  3 No      0.939 0.0608    34 No        Travel_Rarely          1346 Research & …
##  4 Yes     0.589 0.411     22 No        Non-Travel             1123 Research & …
##  5 No      0.920 0.0803    53 No        Travel_Rarely          1219 Sales       
##  6 No      0.945 0.0550    24 No        Non-Travel              673 Research & …
##  7 No      0.757 0.243     21 No        Travel_Rarely           391 Research & …
##  8 No      0.953 0.0471    34 Yes       Travel_Rarely           699 Research & …
##  9 No      0.981 0.0187    53 No        Travel_Rarely          1282 Research & …
## 10 Yes     0.499 0.501     32 Yes       Travel_Frequently      1125 Research & …
## # ℹ 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] "GBM_1_AutoML_4_20240509_120305"
## 
## $model$type
## [1] "Key<Model>"
## 
## $model$URL
## [1] "/3/Models/GBM_1_AutoML_4_20240509_120305"
## 
## 
## $model_checksum
## [1] "6097428537100003408"
## 
## $frame
## $frame$name
## [1] "test_tbl_sid_b418_3"
## 
## 
## $frame_checksum
## [1] "-54413681510283746"
## 
## $description
## NULL
## 
## $scoring_time
## [1] 1.715271e+12
## 
## $predictions
## NULL
## 
## $MSE
## [1] 0.09723772
## 
## $RMSE
## [1] 0.3118296
## 
## $nobs
## [1] 369
## 
## $custom_metric_name
## NULL
## 
## $custom_metric_value
## [1] 0
## 
## $r2
## [1] 0.2858692
## 
## $logloss
## [1] 0.3243584
## 
## $AUC
## [1] 0.8552319
## 
## $pr_auc
## [1] 0.6161812
## 
## $Gini
## [1] 0.7104639
## 
## $mean_per_class_error
## [1] 0.2221683
## 
## $domain
## [1] "No"  "Yes"
## 
## $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
##         No Yes  Error       Rate
## No     285  24 0.0777 = 24 / 309
## Yes     22  38 0.3667 =  22 / 60
## Totals 307  62 0.1247 = 46 / 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.833189 0.032787 0.020747 0.078125 0.840108  1.000000 0.016667    1.000000
## 2  0.815966 0.064516 0.041322 0.147059 0.842818  1.000000 0.033333    1.000000
## 3  0.773643 0.095238 0.061728 0.208333 0.845528  1.000000 0.050000    1.000000
## 4  0.769062 0.093750 0.061475 0.197368 0.842818  0.750000 0.050000    0.996764
## 5  0.699918 0.092308 0.061224 0.187500 0.840108  0.600000 0.050000    0.993528
##   absolute_mcc min_per_class_accuracy mean_per_class_accuracy tns fns fps tps
## 1     0.118299               0.016667                0.508333 309  59   0   1
## 2     0.167527               0.033333                0.516667 309  58   0   2
## 3     0.205458               0.050000                0.525000 309  57   0   3
## 4     0.166643               0.050000                0.523382 308  57   1   3
## 5     0.138926               0.050000                0.521764 307  57   2   3
##        tnr      fnr      fpr      tpr idx
## 1 1.000000 0.983333 0.000000 0.016667   0
## 2 1.000000 0.966667 0.000000 0.033333   1
## 3 1.000000 0.950000 0.000000 0.050000   2
## 4 0.996764 0.950000 0.003236 0.050000   3
## 5 0.993528 0.950000 0.006472 0.050000   4
## 
## ---
##     threshold       f1       f2 f0point5 accuracy precision   recall
## 364  0.014260 0.283019 0.496689 0.197889 0.176152  0.164835 1.000000
## 365  0.013808 0.282353 0.495868 0.197368 0.173442  0.164384 1.000000
## 366  0.010435 0.281690 0.495050 0.196850 0.170732  0.163934 1.000000
## 367  0.010104 0.281030 0.494234 0.196335 0.168022  0.163488 1.000000
## 368  0.009857 0.280374 0.493421 0.195822 0.165312  0.163043 1.000000
## 369  0.007542 0.279720 0.492611 0.195313 0.162602  0.162602 1.000000
##     specificity absolute_mcc min_per_class_accuracy mean_per_class_accuracy tns
## 364    0.016181     0.051645               0.016181                0.508091   5
## 365    0.012945     0.046130               0.012945                0.506472   4
## 366    0.009709     0.039895               0.009709                0.504854   3
## 367    0.006472     0.032530               0.006472                0.503236   2
## 368    0.003236     0.022971               0.003236                0.501618   1
## 369    0.000000     0.000000               0.000000                0.500000   0
##     fns fps tps      tnr      fnr      fpr      tpr idx
## 364   0 304  60 0.016181 0.000000 0.983819 1.000000 363
## 365   0 305  60 0.012945 0.000000 0.987055 1.000000 364
## 366   0 306  60 0.009709 0.000000 0.990291 1.000000 365
## 367   0 307  60 0.006472 0.000000 0.993528 1.000000 366
## 368   0 308  60 0.003236 0.000000 0.996764 1.000000 367
## 369   0 309  60 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.271275   0.622951  61
## 2                       max f2  0.174971   0.692521 120
## 3                 max f0point5  0.413488   0.640244  25
## 4                 max accuracy  0.413488   0.880759  25
## 5                max precision  0.833189   1.000000   0
## 6                   max recall  0.016687   1.000000 359
## 7              max specificity  0.833189   1.000000   0
## 8             max absolute_mcc  0.279919   0.550511  55
## 9   max min_per_class_accuracy  0.188312   0.796117 110
## 10 max mean_per_class_accuracy  0.201228   0.802670 101
## 11                     max tns  0.833189 309.000000   0
## 12                     max fns  0.833189  59.000000   0
## 13                     max fps  0.007542 309.000000 368
## 14                     max tps  0.016687  60.000000 359
## 15                     max tnr  0.833189   1.000000   0
## 16                     max fnr  0.833189   0.983333   0
## 17                     max fpr  0.007542   1.000000 368
## 18                     max tpr  0.016687   1.000000 359
## 
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 16.26 %, avg score: 15.94 %
##    group cumulative_data_fraction lower_threshold     lift cumulative_lift
## 1      1               0.01084011        0.722044 4.612500        4.612500
## 2      2               0.02168022        0.604916 4.612500        4.612500
## 3      3               0.03252033        0.553996 6.150000        5.125000
## 4      4               0.04065041        0.504840 6.150000        5.330000
## 5      5               0.05149051        0.493006 4.612500        5.178947
## 6      6               0.10027100        0.369856 3.416667        4.321622
## 7      7               0.15176152        0.279524 3.236842        3.953571
## 8      8               0.20054201        0.242804 1.366667        3.324324
## 9      9               0.30081301        0.187608 1.329730        2.659459
## 10    10               0.40108401        0.138477 0.332432        2.077703
## 11    11               0.50135501        0.112372 0.498649        1.761892
## 12    12               0.59891599        0.084050 0.170833        1.502715
## 13    13               0.69918699        0.061169 0.498649        1.358721
## 14    14               0.79945799        0.043965 0.332432        1.230000
## 15    15               0.89972900        0.030880 0.000000        1.092922
## 16    16               1.00000000        0.007542 0.166216        1.000000
##    response_rate    score cumulative_response_rate cumulative_score
## 1       0.750000 0.797965                 0.750000         0.797965
## 2       0.750000 0.665700                 0.750000         0.731832
## 3       1.000000 0.575337                 0.833333         0.679667
## 4       1.000000 0.516722                 0.866667         0.647078
## 5       0.750000 0.500101                 0.842105         0.616136
## 6       0.555556 0.412515                 0.702703         0.517077
## 7       0.526316 0.317841                 0.642857         0.449479
## 8       0.222222 0.262525                 0.540541         0.404004
## 9       0.216216 0.214250                 0.432432         0.340752
## 10      0.054054 0.163306                 0.337838         0.296391
## 11      0.081081 0.124491                 0.286486         0.262011
## 12      0.027778 0.095949                 0.244344         0.234960
## 13      0.081081 0.073852                 0.220930         0.211855
## 14      0.054054 0.053558                 0.200000         0.192001
## 15      0.000000 0.037644                 0.177711         0.174799
## 16      0.027027 0.020760                 0.162602         0.159353
##    capture_rate cumulative_capture_rate        gain cumulative_gain
## 1      0.050000                0.050000  361.250000      361.250000
## 2      0.050000                0.100000  361.250000      361.250000
## 3      0.066667                0.166667  515.000000      412.500000
## 4      0.050000                0.216667  515.000000      433.000000
## 5      0.050000                0.266667  361.250000      417.894737
## 6      0.166667                0.433333  241.666667      332.162162
## 7      0.166667                0.600000  223.684211      295.357143
## 8      0.066667                0.666667   36.666667      232.432432
## 9      0.133333                0.800000   32.972973      165.945946
## 10     0.033333                0.833333  -66.756757      107.770270
## 11     0.050000                0.883333  -50.135135       76.189189
## 12     0.016667                0.900000  -82.916667       50.271493
## 13     0.050000                0.950000  -50.135135       35.872093
## 14     0.033333                0.983333  -66.756757       23.000000
## 15     0.000000                0.983333 -100.000000        9.292169
## 16     0.016667                1.000000  -83.378378        0.000000
##    kolmogorov_smirnov
## 1            0.046764
## 2            0.093528
## 3            0.160194
## 4            0.210194
## 5            0.256958
## 6            0.397735
## 7            0.535275
## 8            0.556634
## 9            0.596117
## 10           0.516181
## 11           0.456149
## 12           0.359547
## 13           0.299515
## 14           0.219579
## 15           0.099838
## 16           0.000000
h2o.auc(performance_h2o)
## [1] 0.8552319
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.271274787838988:
##         No Yes    Error     Rate
## No     285  24 0.077670  =24/309
## Yes     22  38 0.366667   =22/60
## Totals 307  62 0.124661  =46/369
h2o.metric(performance_h2o) %>% as_tibble() %>% filter(threshold %>% between (0.27, 0.28))
## # A tibble: 7 × 20
##   threshold    f1    f2 f0point5 accuracy precision recall specificity
##       <dbl> <dbl> <dbl>    <dbl>    <dbl>     <dbl>  <dbl>       <dbl>
## 1     0.280 0.621 0.608    0.634    0.881     0.643  0.6         0.935
## 2     0.278 0.615 0.606    0.625    0.878     0.632  0.6         0.932
## 3     0.275 0.610 0.604    0.616    0.875     0.621  0.6         0.929
## 4     0.274 0.605 0.602    0.608    0.873     0.610  0.6         0.926
## 5     0.273 0.617 0.617    0.617    0.875     0.617  0.617       0.926
## 6     0.272 0.612 0.615    0.609    0.873     0.607  0.617       0.922
## 7     0.271 0.623 0.629    0.617    0.875     0.613  0.633       0.922
## # ℹ 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>