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

Set Up Import Data *Import the cleaned data from Module 7

library(h2o)
## Warning: package 'h2o' was built under R version 4.3.3
## 
## ----------------------------------------------------------------------
## 
## 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.2     ✔ 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.5     ✔ workflows    1.1.3
## ✔ modeldata    1.2.0     ✔ workflowsets 1.0.1
## ✔ parsnip      1.1.1     ✔ yardstick    1.2.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 suppressPackageStartupMessages() to eliminate package startup messages
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:         1 hours 44 minutes 
##     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_OPend_eji420 
##     H2O cluster total nodes:    1 
##     H2O cluster total memory:   3.28 GB 
##     H2O cluster total cores:    12 
##     H2O cluster allowed cores:  12 
##     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 ucrt)
## 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 = 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)

auto_ml_models_h2o <- h2o.automl(
    x = x,
    y = y, 
    training_frame    = train_h2o,
    validation_frame  = valid_h2o, 
    leaderboard_frame = test_h2o, 
    max_runtime_secs  = 30,
    exclude_algos     = "DeepLearning",
    # nfolds            = 5,
    seed              = 2345   
)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |====                                                                  |   6%
## 13:41:34.263: 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.
## 13:41:34.263: AutoML: XGBoost is not available; skipping it.
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |======================================================================| 100%

Examine the output of h2o.automl

auto_ml_models_h2o %>% typeof()
## [1] "S4"
auto_ml_models_h2o %>% slotNames()
## [1] "project_name"   "leader"         "leaderboard"    "event_log"     
## [5] "modeling_steps" "training_info"
auto_ml_models_h2o@leaderboard
##                                                  model_id       auc   logloss
## 1 StackedEnsemble_BestOfFamily_4_AutoML_4_20240509_134134 0.8333333 0.3238283
## 2 StackedEnsemble_BestOfFamily_6_AutoML_4_20240509_134134 0.8319849 0.3242757
## 3 StackedEnsemble_BestOfFamily_3_AutoML_4_20240509_134134 0.8315534 0.3252497
## 4 StackedEnsemble_BestOfFamily_2_AutoML_4_20240509_134134 0.8314995 0.3255053
## 5    StackedEnsemble_AllModels_1_AutoML_4_20240509_134134 0.8307443 0.3256959
## 6    StackedEnsemble_AllModels_2_AutoML_4_20240509_134134 0.8300431 0.3259411
##       aucpr mean_per_class_error      rmse        mse
## 1 0.9538473            0.3064725 0.3066953 0.09406199
## 2 0.9528834            0.3064725 0.3068768 0.09417339
## 3 0.9531354            0.3064725 0.3076645 0.09465747
## 4 0.9529747            0.3064725 0.3074807 0.09454440
## 5 0.9523748            0.3097087 0.3086613 0.09527180
## 6 0.9520009            0.3097087 0.3089480 0.09544890
## 
## [44 rows x 7 columns]
auto_ml_models_h2o@leader
## Model Details:
## ==============
## 
## H2OBinomialModel: stackedensemble
## Model ID:  StackedEnsemble_BestOfFamily_4_AutoML_4_20240509_134134 
## Model Summary for Stacked Ensemble: 
##                                     key            value
## 1                     Stacking strategy cross_validation
## 2  Number of base models (used / total)              4/4
## 3      # GBM base models (used / total)              1/1
## 4      # GLM base models (used / total)              1/1
## 5      # DRF base models (used / total)              2/2
## 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.04489875
## RMSE:  0.2118933
## LogLoss:  0.1672862
## Mean Per-Class Error:  0.08248189
## AUC:  0.9789573
## AUCPR:  0.9951373
## Gini:  0.9579146
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        Left  No    Error     Rate
## Left    132  22 0.142857  =22/154
## No       17 752 0.022107  =17/769
## Totals  149 774 0.042254  =39/923
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.668934   0.974725 265
## 2                       max f2  0.456431   0.987417 307
## 3                 max f0point5  0.737840   0.974182 245
## 4                 max accuracy  0.668934   0.957746 265
## 5                max precision  0.999976   1.000000   0
## 6                   max recall  0.456431   1.000000 307
## 7              max specificity  0.999976   1.000000   0
## 8             max absolute_mcc  0.668934   0.846185 265
## 9   max min_per_class_accuracy  0.777629   0.922078 226
## 10 max mean_per_class_accuracy  0.788963   0.929167 219
## 11                     max tns  0.999976 154.000000   0
## 12                     max fns  0.999976 617.000000   0
## 13                     max fps  0.023142 154.000000 399
## 14                     max tps  0.456431 769.000000 307
## 15                     max tnr  0.999976   1.000000   0
## 16                     max fnr  0.999976   0.802341   0
## 17                     max fpr  0.023142   1.000000 399
## 18                     max tpr  0.456431   1.000000 307
## 
## 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.06996255
## RMSE:  0.2645043
## LogLoss:  0.2984903
## Mean Per-Class Error:  0.1497896
## AUC:  0.8670407
## AUCPR:  0.9565844
## Gini:  0.7340813
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        Left  No    Error     Rate
## Left     17   6 0.260870    =6/23
## No        6 149 0.038710   =6/155
## Totals   23 155 0.067416  =12/178
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.586154   0.961290 154
## 2                       max f2  0.404018   0.978535 171
## 3                 max f0point5  0.586154   0.961290 154
## 4                 max accuracy  0.586154   0.932584 154
## 5                max precision  0.999997   1.000000   0
## 6                   max recall  0.404018   1.000000 171
## 7              max specificity  0.999997   1.000000   0
## 8             max absolute_mcc  0.586154   0.700421 154
## 9   max min_per_class_accuracy  0.784170   0.819355 130
## 10 max mean_per_class_accuracy  0.679918   0.859046 149
## 11                     max tns  0.999997  23.000000   0
## 12                     max fns  0.999997 154.000000   0
## 13                     max fps  0.026599  23.000000 177
## 14                     max tps  0.404018 155.000000 171
## 15                     max tnr  0.999997   1.000000   0
## 16                     max fnr  0.999997   0.993548   0
## 17                     max fpr  0.026599   1.000000 177
## 18                     max tpr  0.404018   1.000000 171
## 
## 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.09674361
## RMSE:  0.3110364
## LogLoss:  0.3288854
## Mean Per-Class Error:  0.3214455
## AUC:  0.8391696
## AUCPR:  0.9528999
## Gini:  0.6783392
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##        Left  No    Error      Rate
## Left     59  95 0.616883   =95/154
## No       20 749 0.026008   =20/769
## Totals   79 844 0.124594  =115/923
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.502505   0.928704 329
## 2                       max f2  0.323132   0.964979 373
## 3                 max f0point5  0.709835   0.924132 249
## 4                 max accuracy  0.557079   0.875406 317
## 5                max precision  0.999976   1.000000   0
## 6                   max recall  0.154464   1.000000 395
## 7              max specificity  0.999976   1.000000   0
## 8             max absolute_mcc  0.709835   0.528580 249
## 9   max min_per_class_accuracy  0.833415   0.753247 175
## 10 max mean_per_class_accuracy  0.709835   0.784346 249
## 11                     max tns  0.999976 154.000000   0
## 12                     max fns  0.999976 735.000000   0
## 13                     max fps  0.046111 154.000000 399
## 14                     max tps  0.154464 769.000000 395
## 15                     max tnr  0.999976   1.000000   0
## 16                     max fnr  0.999976   0.955787   0
## 17                     max fpr  0.046111   1.000000 399
## 18                     max tpr  0.154464   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.893984 0.005790   0.894444   0.885572   0.891892   0.901042
## auc        0.843693 0.042800   0.907728   0.791124   0.825572   0.854527
## err        0.106016 0.005790   0.105556   0.114428   0.108108   0.098958
## err_count 19.600000 2.190890  19.000000  23.000000  20.000000  19.000000
## f0point5   0.918135 0.012451   0.937500   0.903156   0.919255   0.916856
##           cv_5_valid
## accuracy    0.896970
## auc         0.839513
## err         0.103030
## err_count  17.000000
## f0point5    0.913907
## 
## ---
##                         mean        sd cv_1_valid cv_2_valid cv_3_valid
## precision           0.905055  0.020884   0.938776   0.882979   0.907975
## r2                  0.306485  0.051873   0.368996   0.232403   0.293534
## recall              0.976079  0.026917   0.932432   0.994012   0.967320
## residual_deviance 120.399220 16.393864 106.648430 145.820110 127.008804
## rmse                0.310082  0.013127   0.303703   0.328449   0.317903
## specificity         0.477511  0.151029   0.718750   0.352941   0.531250
##                   cv_4_valid cv_5_valid
## precision           0.899441   0.896104
## r2                  0.339947   0.297544
## recall              0.993827   0.992806
## residual_deviance 115.065250 107.453514
## rmse                0.294989   0.305365
## specificity         0.400000   0.384615
best_model <- auto_ml_models_h2o@leader

Save and Load

?h2o.getModel
## starting httpd help server ... done
?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()

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 Left    0.584  0.416    41 Left      Travel_Rarely          1102 Sales       
##  2 No      0.0214 0.979    49 No        Travel_Frequently       279 Research & …
##  3 No      0.253  0.747    33 No        Travel_Frequently      1392 Research & …
##  4 No      0.144  0.856    59 No        Travel_Rarely          1324 Research & …
##  5 No      0.0733 0.927    38 No        Travel_Frequently       216 Research & …
##  6 No      0.291  0.709    29 No        Travel_Rarely           153 Research & …
##  7 No      0.0367 0.963    34 No        Travel_Rarely          1346 Research & …
##  8 Left    0.873  0.127    28 Left      Travel_Rarely           103 Research & …
##  9 No      0.275  0.725    22 No        Non-Travel             1123 Research & …
## 10 No      0.0236 0.976    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_4_AutoML_4_20240509_134134"
## 
## $model$type
## [1] "Key<Model>"
## 
## $model$URL
## [1] "/3/Models/StackedEnsemble_BestOfFamily_4_AutoML_4_20240509_134134"
## 
## 
## $model_checksum
## [1] "2117851016217035208"
## 
## $frame
## $frame$name
## [1] "test_tbl_sid_8c13_3"
## 
## 
## $frame_checksum
## [1] "-54192601206779456"
## 
## $description
## NULL
## 
## $scoring_time
## [1] 1.715277e+12
## 
## $predictions
## NULL
## 
## $MSE
## [1] 0.09406199
## 
## $RMSE
## [1] 0.3066953
## 
## $nobs
## [1] 369
## 
## $custom_metric_name
## NULL
## 
## $custom_metric_value
## [1] 0
## 
## $r2
## [1] 0.3091923
## 
## $logloss
## [1] 0.3238283
## 
## $AUC
## [1] 0.8333333
## 
## $pr_auc
## [1] 0.9538473
## 
## $Gini
## [1] 0.6666667
## 
## $mean_per_class_error
## [1] 0.3064725
## 
## $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     24  36 0.6000 =  36 / 60
## No        4 305 0.0129 =  4 / 309
## Totals   28 341 0.1084 = 40 / 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.999998 0.006452 0.004042 0.015974 0.165312  1.000000 0.003236    1.000000
## 2  0.999998 0.012862 0.008078 0.031546 0.168022  1.000000 0.006472    1.000000
## 3  0.999997 0.019231 0.012107 0.046729 0.170732  1.000000 0.009709    1.000000
## 4  0.999996 0.025559 0.016129 0.061538 0.173442  1.000000 0.012945    1.000000
## 5  0.999996 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.234042 0.918276 0.965625 0.875354 0.850949  0.848901 1.000000
## 365  0.158869 0.916914 0.965022 0.873375 0.848238  0.846575 1.000000
## 366  0.126905 0.915556 0.964419 0.871404 0.845528  0.844262 1.000000
## 367  0.124947 0.914201 0.963818 0.869443 0.842818  0.841962 1.000000
## 368  0.048284 0.912851 0.963217 0.867490 0.840108  0.839674 1.000000
## 369  0.045413 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.435557   0.938462 340
## 2                       max f2  0.340441   0.970477 355
## 3                 max f0point5  0.666511   0.922330 308
## 4                 max accuracy  0.528663   0.891599 328
## 5                max precision  0.999998   1.000000   0
## 6                   max recall  0.340441   1.000000 355
## 7              max specificity  0.999998   1.000000   0
## 8             max absolute_mcc  0.528663   0.555055 328
## 9   max min_per_class_accuracy  0.840259   0.750000 246
## 10 max mean_per_class_accuracy  0.675604   0.764644 304
## 11                     max tns  0.999998  60.000000   0
## 12                     max fns  0.999998 308.000000   0
## 13                     max fps  0.045413  60.000000 368
## 14                     max tps  0.340441 309.000000 355
## 15                     max tnr  0.999998   1.000000   0
## 16                     max fnr  0.999998   0.996764   0
## 17                     max fpr  0.045413   1.000000 368
## 18                     max tpr  0.340441   1.000000 355
## 
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 83.74 %, avg score: 83.08 %
##    group cumulative_data_fraction lower_threshold     lift cumulative_lift
## 1      1               0.01084011        0.999996 1.194175        1.194175
## 2      2               0.02168022        0.999994 1.194175        1.194175
## 3      3               0.03252033        0.999989 1.194175        1.194175
## 4      4               0.04065041        0.999983 1.194175        1.194175
## 5      5               0.05149051        0.999971 1.194175        1.194175
## 6      6               0.10027100        0.991533 1.194175        1.194175
## 7      7               0.15176152        0.987561 1.068472        1.151526
## 8      8               0.20054201        0.979202 1.127832        1.145762
## 9      9               0.30081301        0.966820 1.161900        1.151141
## 10    10               0.40108401        0.941108 1.129625        1.145762
## 11    11               0.50135501        0.911912 1.097350        1.136080
## 12    12               0.59891599        0.872145 1.127832        1.134736
## 13    13               0.69918699        0.807201 0.968250        1.110860
## 14    14               0.79945799        0.709356 1.032800        1.101070
## 15    15               0.89972900        0.507787 0.871425        1.075477
## 16    16               1.00000000        0.045413 0.322750        1.000000
##    response_rate    score cumulative_response_rate cumulative_score
## 1       1.000000 0.999997                 1.000000         0.999997
## 2       1.000000 0.999996                 1.000000         0.999997
## 3       1.000000 0.999991                 1.000000         0.999995
## 4       1.000000 0.999988                 1.000000         0.999993
## 5       1.000000 0.999979                 1.000000         0.999990
## 6       1.000000 0.995097                 1.000000         0.997610
## 7       0.894737 0.989513                 0.964286         0.994863
## 8       0.944444 0.983520                 0.959459         0.992104
## 9       0.972973 0.972680                 0.963964         0.985629
## 10      0.945946 0.953924                 0.959459         0.977703
## 11      0.918919 0.928769                 0.951351         0.967916
## 12      0.944444 0.892965                 0.950226         0.955707
## 13      0.810811 0.845607                 0.930233         0.939917
## 14      0.864865 0.763413                 0.922034         0.917779
## 15      0.729730 0.624195                 0.900602         0.885061
## 16      0.270270 0.344003                 0.837398         0.830808
##    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.058252                0.119741  19.417476       19.417476
## 7      0.055016                0.174757   6.847215       15.152566
## 8      0.055016                0.229773  12.783172       14.576227
## 9      0.116505                0.346278  16.189976       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.097087                0.776699  -3.175020       11.086024
## 14     0.103560                0.880259   3.279979       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.119741
## 7            0.141424
## 8            0.179773
## 9            0.279612
## 10           0.359547
## 11           0.419579
## 12           0.496278
## 13           0.476699
## 14           0.496926
## 15           0.417638
## 16           0.000000
## 
## $residual_deviance
## [1] 238.9853
## 
## $null_deviance
## [1] 327.6898
## 
## $AIC
## [1] 248.9853
## 
## $loglikelihood
## [1] 0
## 
## $null_degrees_of_freedom
## [1] 368
## 
## $residual_degrees_of_freedom
## [1] 364
h2o.auc(performance_h2o)
## [1] 0.8333333
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.435557215433683:
##        Left  No    Error     Rate
## Left     24  36 0.600000   =36/60
## No        4 305 0.012945   =4/309
## Totals   28 341 0.108401  =40/369
h2o.metric(performance_h2o)
## Metrics for Thresholds: Binomial metrics as a function of classification thresholds
##   threshold       f1       f2 f0point5 accuracy precision   recall specificity
## 1  0.999998 0.006452 0.004042 0.015974 0.165312  1.000000 0.003236    1.000000
## 2  0.999998 0.012862 0.008078 0.031546 0.168022  1.000000 0.006472    1.000000
## 3  0.999997 0.019231 0.012107 0.046729 0.170732  1.000000 0.009709    1.000000
## 4  0.999996 0.025559 0.016129 0.061538 0.173442  1.000000 0.012945    1.000000
## 5  0.999996 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.234042 0.918276 0.965625 0.875354 0.850949  0.848901 1.000000
## 365  0.158869 0.916914 0.965022 0.873375 0.848238  0.846575 1.000000
## 366  0.126905 0.915556 0.964419 0.871404 0.845528  0.844262 1.000000
## 367  0.124947 0.914201 0.963818 0.869443 0.842818  0.841962 1.000000
## 368  0.048284 0.912851 0.963217 0.867490 0.840108  0.839674 1.000000
## 369  0.045413 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