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.7     ✔ 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.1.0
## Warning: package 'broom' was built under R version 4.3.3
## Warning: package 'modeldata' was built under R version 4.3.3
## Warning: package 'recipes' 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()
## • Dig deeper into tidy modeling with R at https://www.tmwr.org
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))
## New names:
## Rows: 1470 Columns: 33
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (8): Attrition, BusinessTravel, Department, EducationField, Gender, Job... dbl
## (25): ...1, Age, DailyRate, DistanceFromHome, Education, EmployeeNumber,...
## ℹ 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.
## • `` -> `...1`

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:         4 hours 56 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 30 days 
##     H2O cluster name:           H2O_started_from_R_jordanlanowy_fhp551 
##     H2O cluster total nodes:    1 
##     H2O cluster total memory:   1.30 GB 
##     H2O cluster total cores:    8 
##     H2O cluster allowed cores:  8 
##     H2O cluster healthy:        TRUE 
##     H2O Connection ip:          localhost 
##     H2O Connection port:        54321 
##     H2O Connection proxy:       NA 
##     H2O Internal Security:      FALSE 
##     R Version:                  R version 4.3.2 (2023-10-31)
## Warning in h2o.clusterInfo(): 
## Your H2O cluster version is (10 months and 30 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 = 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%
  |                                                                            
  |==                                                                    |   3%
## 17:56:20.765: 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.
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |======================================================================| 100%

Examine the output of h2o.automl

models_h2o %>% typeof()
## [1] "S4"
models_h2o %>% slotNames()
## [1] "project_name"   "leader"         "leaderboard"    "event_log"     
## [5] "modeling_steps" "training_info"
models_h2o@leaderboard
##                                                   model_id       auc   logloss
## 1 StackedEnsemble_BestOfFamily_1_AutoML_11_20241119_175620 0.8482740 0.3094056
## 2    StackedEnsemble_AllModels_1_AutoML_11_20241119_175620 0.8451996 0.3148845
## 3                          GLM_1_AutoML_11_20241119_175620 0.8399137 0.3186238
## 4                          GBM_1_AutoML_11_20241119_175620 0.8374326 0.3322943
## 5                      XGBoost_2_AutoML_11_20241119_175620 0.8278857 0.3299205
## 6                      XGBoost_1_AutoML_11_20241119_175620 0.8270766 0.3411288
##       aucpr mean_per_class_error      rmse        mse
## 1 0.6530560            0.2133495 0.3006395 0.09038409
## 2 0.6165789            0.2339806 0.3040087 0.09242130
## 3 0.6509898            0.2557443 0.3064529 0.09391340
## 4 0.5820366            0.2418285 0.3163850 0.10009950
## 5 0.6008391            0.2441748 0.3092394 0.09562904
## 6 0.5284256            0.2654531 0.3208495 0.10294437
## 
## [12 rows x 7 columns]
models_h2o@leader
## Model Details:
## ==============
## 
## H2OBinomialModel: stackedensemble
## Model ID:  StackedEnsemble_BestOfFamily_1_AutoML_11_20241119_175620 
## Model Summary for Stacked Ensemble: 
##                                     key            value
## 1                     Stacking strategy cross_validation
## 2  Number of base models (used / total)              4/5
## 3      # GBM base models (used / total)              1/1
## 4  # XGBoost base models (used / total)              1/1
## 5      # GLM base models (used / total)              1/1
## 6      # DRF base models (used / total)              1/2
## 7                 Metalearner algorithm              GLM
## 8    Metalearner fold assignment scheme           Random
## 9                    Metalearner nfolds                5
## 10              Metalearner fold_column               NA
## 11   Custom metalearner hyperparameters             None
## 
## 
## H2OBinomialMetrics: stackedensemble
## ** Reported on training data. **
## 
## MSE:  0.0489028
## RMSE:  0.2211398
## LogLoss:  0.1843305
## Mean Per-Class Error:  0.1157107
## AUC:  0.9671277
## AUCPR:  0.91407
## Gini:  0.9342555
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##         No Yes    Error     Rate
## No     779   9 0.011421   =9/788
## Yes     33 117 0.220000  =33/150
## Totals 812 126 0.044776  =42/938
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.388860   0.847826 109
## 2                       max f2  0.227183   0.862944 158
## 3                 max f0point5  0.407536   0.904762 103
## 4                 max accuracy  0.407536   0.955224 103
## 5                max precision  0.965939   1.000000   0
## 6                   max recall  0.049723   1.000000 314
## 7              max specificity  0.965939   1.000000   0
## 8             max absolute_mcc  0.388860   0.826102 109
## 9   max min_per_class_accuracy  0.206539   0.914975 170
## 10 max mean_per_class_accuracy  0.227183   0.920338 158
## 11                     max tns  0.965939 788.000000   0
## 12                     max fns  0.965939 149.000000   0
## 13                     max fps  0.000130 788.000000 399
## 14                     max tps  0.049723 150.000000 314
## 15                     max tnr  0.965939   1.000000   0
## 16                     max fnr  0.965939   0.993333   0
## 17                     max fpr  0.000130   1.000000 399
## 18                     max tpr  0.049723   1.000000 314
## 
## 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.09471161
## RMSE:  0.3077525
## LogLoss:  0.3085773
## Mean Per-Class Error:  0.1996187
## AUC:  0.8651961
## AUCPR:  0.6140732
## Gini:  0.7303922
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##         No Yes    Error     Rate
## No     122  14 0.102941  =14/136
## Yes      8  19 0.296296    =8/27
## Totals 130  33 0.134969  =22/163
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.300237   0.633333  32
## 2                       max f2  0.277669   0.689655  36
## 3                 max f0point5  0.476573   0.631579  16
## 4                 max accuracy  0.476573   0.877301  16
## 5                max precision  0.966238   1.000000   0
## 6                   max recall  0.035832   1.000000 119
## 7              max specificity  0.966238   1.000000   0
## 8             max absolute_mcc  0.300237   0.555809  32
## 9   max min_per_class_accuracy  0.220842   0.777778  44
## 10 max mean_per_class_accuracy  0.277669   0.807870  36
## 11                     max tns  0.966238 136.000000   0
## 12                     max fns  0.966238  26.000000   0
## 13                     max fps  0.000099 136.000000 162
## 14                     max tps  0.035832  27.000000 119
## 15                     max tnr  0.966238   1.000000   0
## 16                     max fnr  0.966238   0.962963   0
## 17                     max fpr  0.000099   1.000000 162
## 18                     max tpr  0.035832   1.000000 119
## 
## 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.09528276
## RMSE:  0.3086791
## LogLoss:  0.3328032
## Mean Per-Class Error:  0.2453723
## AUC:  0.8242851
## AUCPR:  0.608214
## Gini:  0.6485702
## 
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
##         No Yes    Error      Rate
## No     727  61 0.077411   =61/788
## Yes     62  88 0.413333   =62/150
## Totals 789 149 0.131130  =123/938
## 
## Maximum Metrics: Maximum metrics at their respective thresholds
##                         metric threshold      value idx
## 1                       max f1  0.309176   0.588629 113
## 2                       max f2  0.189945   0.630734 180
## 3                 max f0point5  0.482884   0.628019  53
## 4                 max accuracy  0.482884   0.880597  53
## 5                max precision  0.972574   1.000000   0
## 6                   max recall  0.000738   1.000000 398
## 7              max specificity  0.972574   1.000000   0
## 8             max absolute_mcc  0.309176   0.510638 113
## 9   max min_per_class_accuracy  0.160674   0.746667 199
## 10 max mean_per_class_accuracy  0.215192   0.764340 164
## 11                     max tns  0.972574 788.000000   0
## 12                     max fns  0.972574 149.000000   0
## 13                     max fps  0.000094 788.000000 399
## 14                     max tps  0.000738 150.000000 398
## 15                     max tnr  0.972574   1.000000   0
## 16                     max fnr  0.972574   0.993333   0
## 17                     max fpr  0.000094   1.000000 399
## 18                     max tpr  0.000738   1.000000 398
## 
## 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.844706 0.066918   0.904306   0.880829   0.850000   0.857143
## auc        0.821823 0.039724   0.853186   0.764524   0.864662   0.819169
## err        0.155294 0.066918   0.095694   0.119171   0.150000   0.142857
## err_count 28.200000 8.871302  20.000000  23.000000  27.000000  28.000000
## f0point5   0.564303 0.115758   0.741758   0.547445   0.543478   0.570652
##           cv_5_valid
## accuracy    0.731250
## auc         0.807574
## err         0.268750
## err_count  43.000000
## f0point5    0.418182
## 
## ---
##                         mean        sd cv_1_valid cv_2_valid cv_3_valid
## precision           0.544427  0.135546   0.750000   0.535714   0.512821
## r2                  0.276706  0.077089   0.369137   0.212622   0.336482
## recall              0.706583  0.093637   0.710526   0.600000   0.714286
## residual_deviance 124.462150 13.618898 141.060060 125.348150 106.857640
## rmse                0.310251  0.016827   0.306345   0.297961   0.295226
## specificity         0.869619  0.095023   0.947368   0.922619   0.875000
##                   cv_4_valid cv_5_valid
## precision           0.552632   0.370968
## r2                  0.275453   0.189838
## recall              0.656250   0.851852
## residual_deviance 133.345600 115.699300
## rmse                0.314611   0.337112
## specificity         0.896341   0.706767

Save and Load

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

h2o.getModel("StackedEnsemble_BestOfFamily_1_AutoML_9_20241119_174925") %>%
    h2o.saveModel("h2o_models/", force = TRUE)
## [1] "/Users/jordanlanowy/Desktop/PSU_DAT3100/11_module13/h2o_models/StackedEnsemble_BestOfFamily_1_AutoML_9_20241119_174925"
best_model <- h2o.loadModel("h2o_models/StackedEnsemble_BestOfFamily_1_AutoML_9_20241119_174925")

Make predictions

predictions <- h2o.predict(best_model, newdata = test_h2o)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
predictions_tbl <- predictions %>%
    as.tibble()
## Warning: `as.tibble()` was deprecated in tibble 2.0.0.
## ℹ Please use `as_tibble()` instead.
## ℹ The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
predictions_tbl %>%
    bind_cols(test_tbl)
## New names:
## • `...1` -> `...4`
## # A tibble: 369 × 36
##    predict    No     Yes  ...4   Age Attrition BusinessTravel    DailyRate
##    <fct>   <dbl>   <dbl> <dbl> <dbl> <fct>     <fct>                 <dbl>
##  1 Yes     0.657 0.343       7    59 No        Travel_Rarely          1324
##  2 No      0.893 0.107      11    35 No        Travel_Rarely           809
##  3 No      0.931 0.0687     14    34 No        Travel_Rarely          1346
##  4 Yes     0.565 0.435      18    22 No        Non-Travel             1123
##  5 No      0.980 0.0199     19    53 No        Travel_Rarely          1219
##  6 No      0.969 0.0307     21    24 No        Non-Travel              673
##  7 No      0.787 0.213      24    21 No        Travel_Rarely           391
##  8 No      0.891 0.109      25    34 Yes       Travel_Rarely           699
##  9 No      0.994 0.00636    26    53 No        Travel_Rarely          1282
## 10 Yes     0.173 0.827      27    32 Yes       Travel_Frequently      1125
## # ℹ 359 more rows
## # ℹ 28 more variables: Department <fct>, 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>, …

Evaluate model

?h2o.performance
performance_h2o <- h2o.performance(best_model, newdata = test_h2o)
typeof(performance_h2o)
## [1] "S4"
slotNames(performance_h2o)
## [1] "algorithm" "on_train"  "on_valid"  "on_xval"   "metrics"
performance_h2o@metrics
## $model
## $model$`__meta`
## $model$`__meta`$schema_version
## [1] 3
## 
## $model$`__meta`$schema_name
## [1] "ModelKeyV3"
## 
## $model$`__meta`$schema_type
## [1] "Key<Model>"
## 
## 
## $model$name
## [1] "StackedEnsemble_BestOfFamily_1_AutoML_9_20241119_174925"
## 
## $model$type
## [1] "Key<Model>"
## 
## $model$URL
## [1] "/3/Models/StackedEnsemble_BestOfFamily_1_AutoML_9_20241119_174925"
## 
## 
## $model_checksum
## [1] "7206720806778980384"
## 
## $frame
## $frame$name
## [1] "test_tbl_sid_bc2c_3"
## 
## 
## $frame_checksum
## [1] 3.637474e+13
## 
## $description
## NULL
## 
## $scoring_time
## [1] 1.732057e+12
## 
## $predictions
## NULL
## 
## $MSE
## [1] 0.09038409
## 
## $RMSE
## [1] 0.3006395
## 
## $nobs
## [1] 369
## 
## $custom_metric_name
## NULL
## 
## $custom_metric_value
## [1] 0
## 
## $r2
## [1] 0.3362035
## 
## $logloss
## [1] 0.3094056
## 
## $AUC
## [1] 0.848274
## 
## $pr_auc
## [1] 0.653056
## 
## $Gini
## [1] 0.696548
## 
## $mean_per_class_error
## [1] 0.2133495
## 
## $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     275  34 0.1100 = 34 / 309
## Yes     19  41 0.3167 =  19 / 60
## Totals 294  75 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.946561 0.032787 0.020747 0.078125 0.840108  1.000000 0.016667    1.000000
## 2  0.916826 0.064516 0.041322 0.147059 0.842818  1.000000 0.033333    1.000000
## 3  0.909689 0.095238 0.061728 0.208333 0.845528  1.000000 0.050000    1.000000
## 4  0.853838 0.125000 0.081967 0.263158 0.848238  1.000000 0.066667    1.000000
## 5  0.827380 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.003074 0.283019 0.496689 0.197889 0.176152  0.164835 1.000000
## 365  0.002808 0.282353 0.495868 0.197368 0.173442  0.164384 1.000000
## 366  0.002462 0.281690 0.495050 0.196850 0.170732  0.163934 1.000000
## 367  0.001719 0.281030 0.494234 0.196335 0.168022  0.163488 1.000000
## 368  0.001592 0.280374 0.493421 0.195822 0.165312  0.163043 1.000000
## 369  0.000644 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.250087   0.607407  74
## 2                       max f2  0.220399   0.661538  84
## 3                 max f0point5  0.534969   0.684524  26
## 4                 max accuracy  0.534969   0.888889  26
## 5                max precision  0.946561   1.000000   0
## 6                   max recall  0.011745   1.000000 334
## 7              max specificity  0.946561   1.000000   0
## 8             max absolute_mcc  0.441968   0.535812  41
## 9   max min_per_class_accuracy  0.173318   0.766667 111
## 10 max mean_per_class_accuracy  0.220399   0.790372  84
## 11                     max tns  0.946561 309.000000   0
## 12                     max fns  0.946561  59.000000   0
## 13                     max fps  0.000644 309.000000 368
## 14                     max tps  0.011745  60.000000 334
## 15                     max tnr  0.946561   1.000000   0
## 16                     max fnr  0.946561   0.983333   0
## 17                     max fpr  0.000644   1.000000 368
## 18                     max tpr  0.011745   1.000000 334
## 
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 16.26 %, avg score: 16.34 %
##    group cumulative_data_fraction lower_threshold     lift cumulative_lift
## 1      1               0.01084011        0.835847 6.150000        6.150000
## 2      2               0.02168022        0.742746 4.612500        5.381250
## 3      3               0.03252033        0.723694 6.150000        5.637500
## 4      4               0.04065041        0.646998 6.150000        5.740000
## 5      5               0.05149051        0.628951 6.150000        5.826316
## 6      6               0.10027100        0.476425 3.075000        4.487838
## 7      7               0.15176152        0.336226 2.265789        3.733929
## 8      8               0.20054201        0.250234 2.050000        3.324324
## 9      9               0.30081301        0.173418 0.831081        2.493243
## 10    10               0.40108401        0.119383 0.664865        2.036149
## 11    11               0.50135501        0.084869 0.664865        1.761892
## 12    12               0.59891599        0.057271 0.170833        1.502715
## 13    13               0.69918699        0.038274 0.498649        1.358721
## 14    14               0.79945799        0.023599 0.166216        1.209153
## 15    15               0.89972900        0.012188 0.166216        1.092922
## 16    16               1.00000000        0.000644 0.166216        1.000000
##    response_rate    score cumulative_response_rate cumulative_score
## 1       1.000000 0.906729                 1.000000         0.906729
## 2       0.750000 0.766581                 0.875000         0.836655
## 3       1.000000 0.734122                 0.916667         0.802477
## 4       1.000000 0.674551                 0.933333         0.776892
## 5       1.000000 0.640403                 0.947368         0.748158
## 6       0.500000 0.543477                 0.729730         0.648583
## 7       0.368421 0.403110                 0.607143         0.565297
## 8       0.333333 0.289878                 0.540541         0.498303
## 9       0.135135 0.210474                 0.405405         0.402360
## 10      0.108108 0.148500                 0.331081         0.338895
## 11      0.108108 0.101709                 0.286486         0.291458
## 12      0.027778 0.069848                 0.244344         0.255359
## 13      0.081081 0.049021                 0.220930         0.225767
## 14      0.027027 0.030137                 0.196610         0.201231
## 15      0.027027 0.018449                 0.177711         0.180861
## 16      0.027027 0.007168                 0.162602         0.163444
##    capture_rate cumulative_capture_rate       gain cumulative_gain
## 1      0.066667                0.066667 515.000000      515.000000
## 2      0.050000                0.116667 361.250000      438.125000
## 3      0.066667                0.183333 515.000000      463.750000
## 4      0.050000                0.233333 515.000000      474.000000
## 5      0.066667                0.300000 515.000000      482.631579
## 6      0.150000                0.450000 207.500000      348.783784
## 7      0.116667                0.566667 126.578947      273.392857
## 8      0.100000                0.666667 105.000000      232.432432
## 9      0.083333                0.750000 -16.891892      149.324324
## 10     0.066667                0.816667 -33.513514      103.614865
## 11     0.066667                0.883333 -33.513514       76.189189
## 12     0.016667                0.900000 -82.916667       50.271493
## 13     0.050000                0.950000 -50.135135       35.872093
## 14     0.016667                0.966667 -83.378378       20.915254
## 15     0.016667                0.983333 -83.378378        9.292169
## 16     0.016667                1.000000 -83.378378        0.000000
##    kolmogorov_smirnov
## 1            0.066667
## 2            0.113430
## 3            0.180097
## 4            0.230097
## 5            0.296764
## 6            0.417638
## 7            0.495469
## 8            0.556634
## 9            0.536408
## 10           0.496278
## 11           0.456149
## 12           0.359547
## 13           0.299515
## 14           0.199676
## 15           0.099838
## 16           0.000000
## 
## $residual_deviance
## [1] 228.3414
## 
## $null_deviance
## [1] 327.6614
## 
## $AIC
## [1] 238.3414
## 
## $loglikelihood
## [1] 0
## 
## $null_degrees_of_freedom
## [1] 368
## 
## $residual_degrees_of_freedom
## [1] 364
h2o.auc(performance_h2o)
## [1] 0.848274
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted)  for max f1 @ threshold = 0.250087463682527:
##         No Yes    Error     Rate
## No     275  34 0.110032  =34/309
## Yes     19  41 0.316667   =19/60
## Totals 294  75 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.946561 0.032787 0.020747 0.078125 0.840108  1.000000 0.016667    1.000000
## 2  0.916826 0.064516 0.041322 0.147059 0.842818  1.000000 0.033333    1.000000
## 3  0.909689 0.095238 0.061728 0.208333 0.845528  1.000000 0.050000    1.000000
## 4  0.853838 0.125000 0.081967 0.263158 0.848238  1.000000 0.066667    1.000000
## 5  0.827380 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.003074 0.283019 0.496689 0.197889 0.176152  0.164835 1.000000
## 365  0.002808 0.282353 0.495868 0.197368 0.173442  0.164384 1.000000
## 366  0.002462 0.281690 0.495050 0.196850 0.170732  0.163934 1.000000
## 367  0.001719 0.281030 0.494234 0.196335 0.168022  0.163488 1.000000
## 368  0.001592 0.280374 0.493421 0.195822 0.165312  0.163043 1.000000
## 369  0.000644 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