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.1     ✔ 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.1 
## ✔ infer        1.0.7      ✔ workflows    1.1.4 
## ✔ modeldata    1.4.0      ✔ workflowsets 1.1.0 
## ✔ parsnip      1.2.1      ✔ yardstick    1.3.1 
## ✔ recipes      1.0.10
## Warning: package 'modeldata' was built under R version 4.3.3
## ── 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

h2o.init()
##  Connection successful!
## 
## R is connected to the H2O cluster: 
##     H2O cluster uptime:         1 hours 55 minutes 
##     H2O cluster timezone:       America/New_York 
##     H2O data parsing timezone:  UTC 
##     H2O cluster version:        3.44.0.3 
##     H2O cluster version age:    10 months and 28 days 
##     H2O cluster name:           H2O_started_from_R_kajsabergstrand_fhp551 
##     H2O cluster total nodes:    1 
##     H2O cluster total memory:   1.51 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.2 (2023-10-31)
## Warning in h2o.clusterInfo(): 
## Your H2O cluster version is (10 months and 28 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%
## 17:12:21.205: 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.
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |======================================================================| 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                          GBM_1_AutoML_9_20241117_171221 0.8552319 0.3243584
## 2                          GLM_1_AutoML_9_20241117_171221 0.8400216 0.3186222
## 3 StackedEnsemble_BestOfFamily_1_AutoML_9_20241117_171221 0.8386731 0.3679170
## 4    StackedEnsemble_AllModels_1_AutoML_9_20241117_171221 0.8330097 0.3360015
## 5                      XGBoost_1_AutoML_9_20241117_171221 0.8303128 0.3350992
## 6                          GBM_2_AutoML_9_20241117_171221 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_9_20241117_171221 
## Model Summary: 
##   number_of_trees number_of_internal_trees model_size_in_bytes min_depth
## 1              59                       59                7757         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("StackedEnsemble_BestOfFamily_1_AutoML_1_20241117_153337") %>%
    h2o.saveModel("h2o_models/")
## [1] "/Users/kajsabergstrand/Desktop/PSU_DAT3100/11_module13/h2o_models/StackedEnsemble_BestOfFamily_1_AutoML_1_20241117_153337"
best_model <- h2o.loadModel("h2o_models/StackedEnsemble_BestOfFamily_1_AutoML_1_20241117_153337")

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.769 0.231      59 No        Travel_Rarely          1324 Research &…
##  2 No      0.897 0.103      35 No        Travel_Rarely           809 Research &…
##  3 No      0.937 0.0628     34 No        Travel_Rarely          1346 Research &…
##  4 Yes     0.645 0.355      22 No        Non-Travel             1123 Research &…
##  5 No      0.975 0.0254     53 No        Travel_Rarely          1219 Sales      
##  6 No      0.963 0.0373     24 No        Non-Travel              673 Research &…
##  7 No      0.833 0.167      21 No        Travel_Rarely           391 Research &…
##  8 No      0.902 0.0980     34 Yes       Travel_Rarely           699 Research &…
##  9 No      0.996 0.00399    53 No        Travel_Rarely          1282 Research &…
## 10 Yes     0.240 0.760      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

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_1_20241117_153337"
## 
## $model$type
## [1] "Key<Model>"
## 
## $model$URL
## [1] "/3/Models/StackedEnsemble_BestOfFamily_1_AutoML_1_20241117_153337"
## 
## 
## $model_checksum
## [1] "-3339733945895658128"
## 
## $frame
## $frame$name
## [1] "test_tbl_sid_add9_3"
## 
## 
## $frame_checksum
## [1] "-54413681510283746"
## 
## $description
## NULL
## 
## $scoring_time
## [1] 1.731882e+12
## 
## $predictions
## NULL
## 
## $MSE
## [1] 0.09087523
## 
## $RMSE
## [1] 0.3014552
## 
## $nobs
## [1] 369
## 
## $custom_metric_name
## NULL
## 
## $custom_metric_value
## [1] 0
## 
## $r2
## [1] 0.3325964
## 
## $logloss
## [1] 0.3085488
## 
## $AUC
## [1] 0.8531823
## 
## $pr_auc
## [1] 0.6565316
## 
## $Gini
## [1] 0.7063646
## 
## $mean_per_class_error
## [1] 0.1999191
## 
## $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     273  36 0.1165 = 36 / 309
## Yes     17  43 0.2833 =  17 / 60
## Totals 290  79 0.1436 = 53 / 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.932018 0.032787 0.020747 0.078125 0.840108  1.000000 0.016667    1.000000
## 2  0.907443 0.064516 0.041322 0.147059 0.842818  1.000000 0.033333    1.000000
## 3  0.882656 0.095238 0.061728 0.208333 0.845528  1.000000 0.050000    1.000000
## 4  0.783792 0.125000 0.081967 0.263158 0.848238  1.000000 0.066667    1.000000
## 5  0.760070 0.153846 0.102041 0.312500 0.850949  1.000000 0.083333    1.000000
##   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.237568               0.066667                0.533333 309  56   0   4
## 5     0.265973               0.083333                0.541667 309  55   0   5
##        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 1.000000 0.933333 0.000000 0.066667   3
## 5 1.000000 0.916667 0.000000 0.083333   4
## 
## ---
##     threshold       f1       f2 f0point5 accuracy precision   recall
## 364  0.003805 0.283019 0.496689 0.197889 0.176152  0.164835 1.000000
## 365  0.003203 0.282353 0.495868 0.197368 0.173442  0.164384 1.000000
## 366  0.003140 0.281690 0.495050 0.196850 0.170732  0.163934 1.000000
## 367  0.002788 0.281030 0.494234 0.196335 0.168022  0.163488 1.000000
## 368  0.002003 0.280374 0.493421 0.195822 0.165312  0.163043 1.000000
## 369  0.001167 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.251132   0.618705  78
## 2                       max f2  0.251132   0.673981  78
## 3                 max f0point5  0.477329   0.686275  35
## 4                 max accuracy  0.477329   0.891599  35
## 5                max precision  0.932018   1.000000   0
## 6                   max recall  0.012179   1.000000 337
## 7              max specificity  0.932018   1.000000   0
## 8             max absolute_mcc  0.382685   0.550066  47
## 9   max min_per_class_accuracy  0.160704   0.750809 122
## 10 max mean_per_class_accuracy  0.251132   0.800081  78
## 11                     max tns  0.932018 309.000000   0
## 12                     max fns  0.932018  59.000000   0
## 13                     max fps  0.001167 309.000000 368
## 14                     max tps  0.012179  60.000000 337
## 15                     max tnr  0.932018   1.000000   0
## 16                     max fnr  0.932018   0.983333   0
## 17                     max fpr  0.001167   1.000000 368
## 18                     max tpr  0.012179   1.000000 337
## 
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 16,26 %, avg score: 16,15 %
##    group cumulative_data_fraction lower_threshold     lift cumulative_lift
## 1      1               0.01084011        0.767661 6.150000        6.150000
## 2      2               0.02168022        0.706852 6.150000        6.150000
## 3      3               0.03252033        0.688205 4.612500        5.637500
## 4      4               0.04065041        0.625021 4.100000        5.330000
## 5      5               0.05149051        0.579727 4.612500        5.178947
## 6      6               0.10027100        0.459573 4.100000        4.654054
## 7      7               0.15176152        0.318703 1.942105        3.733929
## 8      8               0.20054201        0.257257 2.050000        3.324324
## 9      9               0.30081301        0.173832 0.831081        2.493243
## 10    10               0.40108401        0.120804 0.498649        1.994595
## 11    11               0.50135501        0.090330 0.664865        1.728649
## 12    12               0.59891599        0.059528 0.683333        1.558371
## 13    13               0.69918699        0.040099 0.332432        1.382558
## 14    14               0.79945799        0.028406 0.166216        1.230000
## 15    15               0.89972900        0.013517 0.000000        1.092922
## 16    16               1.00000000        0.001167 0.166216        1.000000
##    response_rate    score cumulative_response_rate cumulative_score
## 1       1.000000 0.876477                 1.000000         0.876477
## 2       1.000000 0.734405                 1.000000         0.805441
## 3       0.750000 0.694560                 0.916667         0.768481
## 4       0.666667 0.663265                 0.866667         0.747437
## 5       0.750000 0.596174                 0.842105         0.715592
## 6       0.666667 0.515460                 0.756757         0.618231
## 7       0.315789 0.385283                 0.607143         0.539195
## 8       0.333333 0.287422                 0.540541         0.477953
## 9       0.135135 0.213649                 0.405405         0.389851
## 10      0.081081 0.148864                 0.324324         0.329604
## 11      0.108108 0.105498                 0.281081         0.284783
## 12      0.111111 0.074809                 0.253394         0.250579
## 13      0.054054 0.049848                 0.224806         0.221792
## 14      0.027027 0.035136                 0.200000         0.198381
## 15      0.000000 0.020744                 0.177711         0.178584
## 16      0.027027 0.007824                 0.162602         0.161462
##    capture_rate cumulative_capture_rate        gain cumulative_gain
## 1      0.066667                0.066667  515.000000      515.000000
## 2      0.066667                0.133333  515.000000      515.000000
## 3      0.050000                0.183333  361.250000      463.750000
## 4      0.033333                0.216667  310.000000      433.000000
## 5      0.050000                0.266667  361.250000      417.894737
## 6      0.200000                0.466667  310.000000      365.405405
## 7      0.100000                0.566667   94.210526      273.392857
## 8      0.100000                0.666667  105.000000      232.432432
## 9      0.083333                0.750000  -16.891892      149.324324
## 10     0.050000                0.800000  -50.135135       99.459459
## 11     0.066667                0.866667  -33.513514       72.864865
## 12     0.066667                0.933333  -31.666667       55.837104
## 13     0.033333                0.966667  -66.756757       38.255814
## 14     0.016667                0.983333  -83.378378       23.000000
## 15     0.000000                0.983333 -100.000000        9.292169
## 16     0.016667                1.000000  -83.378378        0.000000
##    kolmogorov_smirnov
## 1            0.066667
## 2            0.133333
## 3            0.180097
## 4            0.210194
## 5            0.256958
## 6            0.437540
## 7            0.495469
## 8            0.556634
## 9            0.536408
## 10           0.476375
## 11           0.436246
## 12           0.399353
## 13           0.319417
## 14           0.219579
## 15           0.099838
## 16           0.000000
## 
## $residual_deviance
## [1] 227.709
## 
## $null_deviance
## [1] 327.6614
## 
## $AIC
## [1] 235.709
## 
## $loglikelihood
## [1] 0
## 
## $null_degrees_of_freedom
## [1] 368
## 
## $residual_degrees_of_freedom
## [1] 365
h2o.auc(performance_h2o)
## [1] 0.8531823
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.251131874492292:
##         No Yes    Error     Rate
## No     273  36 0.116505  =36/309
## Yes     17  43 0.283333   =17/60
## Totals 290  79 0.143631  =53/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.932018 0.032787 0.020747 0.078125 0.840108  1.000000 0.016667    1.000000
## 2  0.907443 0.064516 0.041322 0.147059 0.842818  1.000000 0.033333    1.000000
## 3  0.882656 0.095238 0.061728 0.208333 0.845528  1.000000 0.050000    1.000000
## 4  0.783792 0.125000 0.081967 0.263158 0.848238  1.000000 0.066667    1.000000
## 5  0.760070 0.153846 0.102041 0.312500 0.850949  1.000000 0.083333    1.000000
##   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.237568               0.066667                0.533333 309  56   0   4
## 5     0.265973               0.083333                0.541667 309  55   0   5
##        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 1.000000 0.933333 0.000000 0.066667   3
## 5 1.000000 0.916667 0.000000 0.083333   4
## 
## ---
##     threshold       f1       f2 f0point5 accuracy precision   recall
## 364  0.003805 0.283019 0.496689 0.197889 0.176152  0.164835 1.000000
## 365  0.003203 0.282353 0.495868 0.197368 0.173442  0.164384 1.000000
## 366  0.003140 0.281690 0.495050 0.196850 0.170732  0.163934 1.000000
## 367  0.002788 0.281030 0.494234 0.196335 0.168022  0.163488 1.000000
## 368  0.002003 0.280374 0.493421 0.195822 0.165312  0.163043 1.000000
## 369  0.001167 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