Goal is to automate building and tuning a classification model to predict employee attrition, using the h2o::h2o.automl.
Import the cleaned data from Module 7.
library(h2o)
## Warning: package 'h2o' was built under R version 4.4.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.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.0.4
## ── 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.4.0 ✔ tune 1.2.1
## ✔ infer 1.0.7 ✔ workflows 1.1.4
## ✔ modeldata 1.4.0 ✔ workflowsets 1.1.0
## ✔ parsnip 1.3.0 ✔ yardstick 1.3.2
## ✔ recipes 1.1.1
## ── 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)
## Warning: package 'tidyquant' was built under R version 4.4.3
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Warning: package 'xts' was built under R version 4.4.3
## Warning: package 'zoo' was built under R version 4.4.3
## Warning: package 'quantmod' was built under R version 4.4.3
## Warning: package 'TTR' was built under R version 4.4.3
## Warning: package 'PerformanceAnalytics' was built under R version 4.4.3
## ── Attaching core tidyquant packages ─────────────────────── tidyquant 1.0.11 ──
## ✔ PerformanceAnalytics 2.0.8 ✔ TTR 0.24.4
## ✔ quantmod 0.4.27 ✔ xts 0.14.1
## ── Conflicts ────────────────────────────────────────── tidyquant_conflicts() ──
## ✖ zoo::as.Date() masks base::as.Date()
## ✖ zoo::as.Date.numeric() masks base::as.Date.numeric()
## ✖ scales::col_factor() masks readr::col_factor()
## ✖ lubridate::day() masks h2o::day()
## ✖ scales::discard() masks purrr::discard()
## ✖ dplyr::filter() masks stats::filter()
## ✖ xts::first() masks dplyr::first()
## ✖ recipes::fixed() masks stringr::fixed()
## ✖ lubridate::hour() masks h2o::hour()
## ✖ dplyr::lag() masks stats::lag()
## ✖ xts::last() masks dplyr::last()
## ✖ PerformanceAnalytics::legend() masks graphics::legend()
## ✖ TTR::momentum() masks dials::momentum()
## ✖ lubridate::month() masks h2o::month()
## ✖ yardstick::spec() masks readr::spec()
## ✖ quantmod::summary() masks h2o::summary(), base::summary()
## ✖ 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
data <- read_csv("../00_data/data_wrangled/data_clean.csv") %>%
mutate(Attrition = if_else(Attrition == "Yes", "Left", Attrition)) %>%
# 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.
set.seed(1234)
data_split <- initial_split(data, strata = "Attrition")
train_tbl <- training(data_split)
test_tbl <- testing(data_split)
recipe_obj <- recipe(Attrition ~ ., data = train_tbl) %>%
# Remove zero variance variables
step_zv(all_predictors())
# Initialize h20
h2o.init()
## Connection successful!
##
## R is connected to the H2O cluster:
## H2O cluster uptime: 12 hours 24 minutes
## H2O cluster timezone: America/New_York
## H2O data parsing timezone: UTC
## H2O cluster version: 3.44.0.3
## H2O cluster version age: 1 year, 4 months and 3 days
## H2O cluster name: H2O_started_from_R_sheac_qxv383
## H2O cluster total nodes: 1
## H2O cluster total memory: 1.37 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.4.2 (2024-10-31 ucrt)
## Warning in h2o.clusterInfo():
## Your H2O cluster version is (1 year, 4 months and 3 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_h20 <- 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_h20,
max_runtime_secs = 30,
nfolds = 5,
seed = 3456
)
## | | | 0% | |=== | 4%
## 11:25:41.421: 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.
## 11:25:41.435: AutoML: XGBoost is not available; skipping it. | |========= | 13% | |================ | 23% | |====================== | 32% | |============================= | 41% | |=================================== | 50% | |========================================= | 59% | |================================================ | 68% | |====================================================== | 77% | |=============================================================== | 90% | |===================================================================== | 99% | |======================================================================| 100%
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_4_AutoML_6_20250424_112541 0.8314455 0.3260147
## 2 StackedEnsemble_BestOfFamily_3_AutoML_6_20250424_112541 0.8286408 0.3244964
## 3 StackedEnsemble_BestOfFamily_2_AutoML_6_20250424_112541 0.8283172 0.3241037
## 4 GLM_1_AutoML_6_20250424_112541 0.8261597 0.3318676
## 5 StackedEnsemble_BestOfFamily_1_AutoML_6_20250424_112541 0.8258900 0.3346208
## 6 StackedEnsemble_AllModels_2_AutoML_6_20250424_112541 0.8236785 0.3286664
## aucpr mean_per_class_error rmse mse
## 1 0.9506808 0.2997573 0.3074941 0.09455264
## 2 0.9509546 0.2677994 0.3068511 0.09415761
## 3 0.9504244 0.2677994 0.3068317 0.09414572
## 4 0.9466326 0.2930421 0.3082111 0.09499409
## 5 0.9494447 0.2627023 0.3115649 0.09707267
## 6 0.9491895 0.3148058 0.3100281 0.09611743
##
## [34 rows x 7 columns]
models_h2o@leader
## Model Details:
## ==============
##
## H2OBinomialModel: stackedensemble
## Model ID: StackedEnsemble_BestOfFamily_4_AutoML_6_20250424_112541
## Model Summary for Stacked Ensemble:
## key value
## 1 Stacking strategy cross_validation
## 2 Number of base models (used / total) 5/5
## 3 # GBM base models (used / total) 1/1
## 4 # GLM base models (used / total) 1/1
## 5 # DeepLearning base models (used / total) 1/1
## 6 # DRF base models (used / total) 2/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.06520428
## RMSE: 0.2553513
## LogLoss: 0.2311669
## Mean Per-Class Error: 0.15895
## AUC: 0.9374838
## AUCPR: 0.9836121
## Gini: 0.8749675
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 110 48 0.303797 =48/158
## No 11 769 0.014103 =11/780
## Totals 121 817 0.062900 =59/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.552341 0.963056 293
## 2 max f2 0.433879 0.977661 333
## 3 max f0point5 0.737926 0.953209 237
## 4 max accuracy 0.552341 0.937100 293
## 5 max precision 0.999431 1.000000 0
## 6 max recall 0.313889 1.000000 358
## 7 max specificity 0.999431 1.000000 0
## 8 max absolute_mcc 0.552341 0.761588 293
## 9 max min_per_class_accuracy 0.799611 0.862821 206
## 10 max mean_per_class_accuracy 0.737926 0.871608 237
## 11 max tns 0.999431 158.000000 0
## 12 max fns 0.999431 775.000000 0
## 13 max fps 0.035816 158.000000 399
## 14 max tps 0.313889 780.000000 358
## 15 max tnr 0.999431 1.000000 0
## 16 max fnr 0.999431 0.993590 0
## 17 max fpr 0.035816 1.000000 399
## 18 max tpr 0.313889 1.000000 358
##
## 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.08470985
## RMSE: 0.2910496
## LogLoss: 0.3082252
## Mean Per-Class Error: 0.3684211
## AUC: 0.748538
## AUCPR: 0.9478571
## Gini: 0.497076
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 5 14 0.736842 =14/19
## No 0 144 0.000000 =0/144
## Totals 5 158 0.085890 =14/163
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.304545 0.953642 157
## 2 max f2 0.304545 0.980926 157
## 3 max f0point5 0.563663 0.940860 149
## 4 max accuracy 0.563663 0.914110 149
## 5 max precision 0.999506 1.000000 0
## 6 max recall 0.304545 1.000000 157
## 7 max specificity 0.999506 1.000000 0
## 8 max absolute_mcc 0.563663 0.528183 149
## 9 max min_per_class_accuracy 0.870915 0.645833 98
## 10 max mean_per_class_accuracy 0.563663 0.722953 149
## 11 max tns 0.999506 19.000000 0
## 12 max fns 0.999506 143.000000 0
## 13 max fps 0.084365 19.000000 162
## 14 max tps 0.304545 144.000000 157
## 15 max tnr 0.999506 1.000000 0
## 16 max fnr 0.999506 0.993056 0
## 17 max fpr 0.084365 1.000000 162
## 18 max tpr 0.304545 1.000000 157
##
## 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.09602834
## RMSE: 0.3098844
## LogLoss: 0.3368525
## Mean Per-Class Error: 0.3418939
## AUC: 0.8414841
## AUCPR: 0.9453246
## Gini: 0.6829682
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 53 105 0.664557 =105/158
## No 15 765 0.019231 =15/780
## Totals 68 870 0.127932 =120/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.465007 0.927273 341
## 2 max f2 0.288287 0.966543 378
## 3 max f0point5 0.722615 0.922810 254
## 4 max accuracy 0.597211 0.875267 307
## 5 max precision 0.946145 0.963526 74
## 6 max recall 0.288287 1.000000 378
## 7 max specificity 0.999973 0.993671 0
## 8 max absolute_mcc 0.683781 0.525260 273
## 9 max min_per_class_accuracy 0.827259 0.769231 191
## 10 max mean_per_class_accuracy 0.776041 0.788843 225
## 11 max tns 0.999973 157.000000 0
## 12 max fns 0.999973 768.000000 0
## 13 max fps 0.068648 158.000000 399
## 14 max tps 0.288287 780.000000 378
## 15 max tnr 0.999973 0.993671 0
## 16 max fnr 0.999973 0.984615 0
## 17 max fpr 0.068648 1.000000 399
## 18 max tpr 0.288287 1.000000 378
##
## 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.893267 0.018435 0.890476 0.886010 0.877095 0.887755
## auc 0.838717 0.040077 0.798057 0.868682 0.892262 0.823945
## err 0.106733 0.018435 0.109524 0.113990 0.122905 0.112245
## err_count 20.200000 4.604346 23.000000 22.000000 22.000000 22.000000
## f0point5 0.922107 0.010477 0.917098 0.920365 0.920330 0.912744
## cv_5_valid
## accuracy 0.925000
## auc 0.810642
## err 0.075000
## err_count 12.000000
## f0point5 0.940000
##
## ---
## mean sd cv_1_valid cv_2_valid cv_3_valid
## precision 0.912478 0.011803 0.903061 0.915584 0.917808
## r2 0.290977 0.082476 0.228137 0.376384 0.344062
## recall 0.963375 0.026719 0.977901 0.940000 0.930556
## residual_deviance 125.598250 19.735897 135.778880 140.812440 125.405400
## rmse 0.309254 0.016621 0.303102 0.328610 0.321213
## specificity 0.508616 0.159600 0.344828 0.697674 0.657143
## cv_4_valid cv_5_valid
## precision 0.898305 0.927632
## r2 0.324865 0.181434
## recall 0.975460 0.992958
## residual_deviance 134.272800 91.721700
## rmse 0.307461 0.285882
## specificity 0.454545 0.388889
h2o.getModel("GLM_1_AutoML_5_20250424_103634")
## Model Details:
## ==============
##
## H2OBinomialModel: glm
## Model ID: GLM_1_AutoML_5_20250424_103634
## GLM Model: summary
## family link regularization
## 1 binomial logit Ridge ( lambda = 0.008518 )
## lambda_search
## 1 nlambda = 30, lambda.max = 6.7124, lambda.min = 0.008518, lambda.1se = 0.03556
## number_of_predictors_total number_of_active_predictors number_of_iterations
## 1 52 52 30
## training_frame
## 1 AutoML_5_20250424_103634_training_RTMP_sid_af9d_201
##
## Coefficients: glm coefficients
## names coefficients standardized_coefficients
## 1 Intercept -5.142680 1.767724
## 2 JobRole.Healthcare Representative 0.321331 0.321331
## 3 JobRole.Human Resources -0.065161 -0.065161
## 4 JobRole.Laboratory Technician -0.446654 -0.446654
## 5 JobRole.Manager -0.025882 -0.025882
##
## ---
## names coefficients standardized_coefficients
## 48 TrainingTimesLastYear 0.216898 0.280265
## 49 WorkLifeBalance 0.274133 0.195818
## 50 YearsAtCompany -0.039922 -0.253102
## 51 YearsInCurrentRole 0.109755 0.403564
## 52 YearsSinceLastPromotion -0.147206 -0.473088
## 53 YearsWithCurrManager 0.124474 0.451897
##
## H2OBinomialMetrics: glm
## ** Reported on training data. **
##
## MSE: 0.08440264
## RMSE: 0.2905213
## LogLoss: 0.2934829
## Mean Per-Class Error: 0.2614979
## AUC: 0.8826964
## AUCPR: 0.9635699
## Gini: 0.7653927
## R^2: 0.3974265
## Residual Deviance: 550.5739
## AIC: 656.5739
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 78 80 0.506329 =80/158
## No 13 767 0.016667 =13/780
## Totals 91 847 0.099147 =93/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.526677 0.942840 322
## 2 max f2 0.413690 0.971007 350
## 3 max f0point5 0.695482 0.933264 257
## 4 max accuracy 0.526677 0.900853 322
## 5 max precision 0.999466 1.000000 0
## 6 max recall 0.249509 1.000000 385
## 7 max specificity 0.999466 1.000000 0
## 8 max absolute_mcc 0.526677 0.603164 322
## 9 max min_per_class_accuracy 0.807357 0.814103 197
## 10 max mean_per_class_accuracy 0.807357 0.815279 197
## 11 max tns 0.999466 158.000000 0
## 12 max fns 0.999466 778.000000 0
## 13 max fps 0.043805 158.000000 399
## 14 max tps 0.249509 780.000000 385
## 15 max tnr 0.999466 1.000000 0
## 16 max fnr 0.999466 0.997436 0
## 17 max fpr 0.043805 1.000000 399
## 18 max tpr 0.249509 1.000000 385
##
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: glm
## ** Reported on validation data. **
##
## MSE: 0.08692475
## RMSE: 0.29483
## LogLoss: 0.3030857
## Mean Per-Class Error: 0.3684211
## AUC: 0.7638889
## AUCPR: 0.9583231
## Gini: 0.5277778
## R^2: 0.1558832
## Residual Deviance: 98.80594
## AIC: 204.8059
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 5 14 0.736842 =14/19
## No 0 144 0.000000 =0/144
## Totals 5 158 0.085890 =14/163
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.325763 0.953642 157
## 2 max f2 0.325763 0.980926 157
## 3 max f0point5 0.575959 0.934066 145
## 4 max accuracy 0.453091 0.914110 155
## 5 max precision 0.999070 1.000000 0
## 6 max recall 0.325763 1.000000 157
## 7 max specificity 0.999070 1.000000 0
## 8 max absolute_mcc 0.325763 0.489735 157
## 9 max min_per_class_accuracy 0.876904 0.631944 96
## 10 max mean_per_class_accuracy 0.620794 0.724963 141
## 11 max tns 0.999070 19.000000 0
## 12 max fns 0.999070 143.000000 0
## 13 max fps 0.105333 19.000000 162
## 14 max tps 0.325763 144.000000 157
## 15 max tnr 0.999070 1.000000 0
## 16 max fnr 0.999070 0.993056 0
## 17 max fpr 0.105333 1.000000 162
## 18 max tpr 0.325763 1.000000 157
##
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: glm
## ** Reported on cross-validation data. **
## ** 5-fold cross-validation on training data (Metrics computed for combined holdout predictions) **
##
## MSE: 0.09599129
## RMSE: 0.3098246
## LogLoss: 0.3310776
## Mean Per-Class Error: 0.2901006
## AUC: 0.8417681
## AUCPR: 0.9474195
## Gini: 0.6835362
## R^2: 0.314692
## Residual Deviance: 621.1016
## AIC: 727.1016
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 72 86 0.544304 =86/158
## No 28 752 0.035897 =28/780
## Totals 100 838 0.121535 =114/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.564254 0.929543 316
## 2 max f2 0.294826 0.965064 380
## 3 max f0point5 0.681445 0.919156 274
## 4 max accuracy 0.596011 0.878465 306
## 5 max precision 0.999172 1.000000 0
## 6 max recall 0.260496 1.000000 386
## 7 max specificity 0.999172 1.000000 0
## 8 max absolute_mcc 0.596011 0.525035 306
## 9 max min_per_class_accuracy 0.824523 0.772152 196
## 10 max mean_per_class_accuracy 0.760789 0.780112 236
## 11 max tns 0.999172 158.000000 0
## 12 max fns 0.999172 777.000000 0
## 13 max fps 0.039958 158.000000 399
## 14 max tps 0.260496 780.000000 386
## 15 max tnr 0.999172 1.000000 0
## 16 max fnr 0.999172 0.996154 0
## 17 max fpr 0.039958 1.000000 399
## 18 max tpr 0.260496 1.000000 386
##
## 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.888048 0.018138 0.914894 0.867021 0.893617 0.887701
## auc 0.841059 0.048630 0.910457 0.822716 0.812901 0.869934
## err 0.111952 0.018138 0.085106 0.132979 0.106383 0.112299
## err_count 21.000000 3.391165 16.000000 25.000000 20.000000 21.000000
## f0point5 0.912584 0.015115 0.932927 0.898810 0.920732 0.913462
## cv_5_valid
## accuracy 0.877005
## auc 0.789289
## err 0.122995
## err_count 23.000000
## f0point5 0.896991
##
## ---
## mean sd cv_1_valid cv_2_valid cv_3_valid
## precision 0.897896 0.018836 0.921687 0.883041 0.909639
## r2 0.313790 0.091724 0.450767 0.277413 0.283759
## recall 0.976923 0.010726 0.980769 0.967949 0.967949
## residual_deviance 123.716354 15.462305 101.618470 131.161740 134.643690
## rmse 0.309405 0.020572 0.278521 0.319466 0.318060
## specificity 0.448387 0.120807 0.593750 0.375000 0.531250
## cv_4_valid cv_5_valid
## precision 0.899408 0.875706
## r2 0.349834 0.207177
## recall 0.974359 0.993590
## residual_deviance 113.615730 137.542110
## rmse 0.299857 0.331123
## specificity 0.451613 0.290323
best.model <- h2o.loadModel("h2o_models/StackedEnsemble_BestOfFamily_4_AutoML_5_20250424_103634")
predictions <- h2o.predict(best.model, newdata = test_h20)
## | | | 0% | |======================================================================| 100%
predictions_tbl <- predictions %>%
as.tibble()
## Warning: `as.tibble()` was deprecated in tibble 2.0.0.
## ℹ Please use `as_tibble()` instead.
## ℹ The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
predictions_tbl %>%
bind_cols(test_tbl)
## # A tibble: 369 × 35
## predict Left No Age Attrition BusinessTravel DailyRate Department
## <fct> <dbl> <dbl> <dbl> <fct> <fct> <dbl> <fct>
## 1 No 0.543 0.457 41 Left Travel_Rarely 1102 Sales
## 2 No 0.0203 0.980 49 No Travel_Frequently 279 Research & …
## 3 No 0.287 0.713 33 No Travel_Frequently 1392 Research & …
## 4 No 0.195 0.805 59 No Travel_Rarely 1324 Research & …
## 5 No 0.0635 0.937 38 No Travel_Frequently 216 Research & …
## 6 No 0.315 0.685 29 No Travel_Rarely 153 Research & …
## 7 No 0.0649 0.935 34 No Travel_Rarely 1346 Research & …
## 8 Left 0.863 0.137 28 Left Travel_Rarely 103 Research & …
## 9 No 0.354 0.646 22 No Non-Travel 1123 Research & …
## 10 No 0.0207 0.979 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>, …
performance_h2o <- h2o.performance(best.model, newdata = test_h20)
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_5_20250424_103634"
##
## $model$type
## [1] "Key<Model>"
##
## $model$URL
## [1] "/3/Models/StackedEnsemble_BestOfFamily_4_AutoML_5_20250424_103634"
##
##
## $model_checksum
## [1] "6160410419765183744"
##
## $frame
## $frame$name
## [1] "test_tbl_sid_9db6_3"
##
##
## $frame_checksum
## [1] "-54192601206779456"
##
## $description
## NULL
##
## $scoring_time
## [1] 1.74551e+12
##
## $predictions
## NULL
##
## $MSE
## [1] 0.09459258
##
## $RMSE
## [1] 0.3075591
##
## $nobs
## [1] 369
##
## $custom_metric_name
## NULL
##
## $custom_metric_value
## [1] 0
##
## $r2
## [1] 0.3052956
##
## $logloss
## [1] 0.3255777
##
## $AUC
## [1] 0.8325782
##
## $pr_auc
## [1] 0.951554
##
## $Gini
## [1] 0.6651564
##
## $mean_per_class_error
## [1] 0.2997573
##
## $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 25 35 0.5833 = 35 / 60
## No 5 304 0.0162 = 5 / 309
## Totals 30 339 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.999009 0.006452 0.004042 0.015974 0.165312 1.000000 0.003236 1.000000
## 2 0.998915 0.012862 0.008078 0.031546 0.168022 1.000000 0.006472 1.000000
## 3 0.998491 0.019231 0.012107 0.046729 0.170732 1.000000 0.009709 1.000000
## 4 0.998190 0.025559 0.016129 0.061538 0.173442 1.000000 0.012945 1.000000
## 5 0.998052 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.223651 0.918276 0.965625 0.875354 0.850949 0.848901 1.000000
## 365 0.222842 0.916914 0.965022 0.873375 0.848238 0.846575 1.000000
## 366 0.152141 0.915556 0.964419 0.871404 0.845528 0.844262 1.000000
## 367 0.137085 0.914201 0.963818 0.869443 0.842818 0.841962 1.000000
## 368 0.080428 0.912851 0.963217 0.867490 0.840108 0.839674 1.000000
## 369 0.062590 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.425831 0.938272 338
## 2 max f2 0.260699 0.967439 360
## 3 max f0point5 0.543874 0.920645 325
## 4 max accuracy 0.462280 0.891599 336
## 5 max precision 0.999009 1.000000 0
## 6 max recall 0.260699 1.000000 360
## 7 max specificity 0.999009 1.000000 0
## 8 max absolute_mcc 0.543874 0.549524 325
## 9 max min_per_class_accuracy 0.830086 0.766667 250
## 10 max mean_per_class_accuracy 0.842075 0.778883 239
## 11 max tns 0.999009 60.000000 0
## 12 max fns 0.999009 308.000000 0
## 13 max fps 0.062590 60.000000 368
## 14 max tps 0.260699 309.000000 360
## 15 max tnr 0.999009 1.000000 0
## 16 max fnr 0.999009 0.996764 0
## 17 max fpr 0.062590 1.000000 368
## 18 max tpr 0.260699 1.000000 360
##
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 83.74 %, avg score: 82.81 %
## group cumulative_data_fraction lower_threshold lift cumulative_lift
## 1 1 0.01084011 0.998096 1.194175 1.194175
## 2 2 0.02168022 0.997203 1.194175 1.194175
## 3 3 0.03252033 0.996507 1.194175 1.194175
## 4 4 0.04065041 0.995538 1.194175 1.194175
## 5 5 0.05149051 0.994944 1.194175 1.194175
## 6 6 0.10027100 0.989318 1.061489 1.129625
## 7 7 0.15176152 0.983777 1.194175 1.151526
## 8 8 0.20054201 0.976027 1.127832 1.145762
## 9 9 0.30081301 0.958845 1.129625 1.140383
## 10 10 0.40108401 0.940038 1.194175 1.153831
## 11 11 0.50135501 0.910637 1.097350 1.142535
## 12 12 0.59891599 0.862774 1.127832 1.140140
## 13 13 0.69918699 0.811345 0.968250 1.115489
## 14 14 0.79945799 0.711587 0.968250 1.097022
## 15 15 0.89972900 0.476362 0.935975 1.079074
## 16 16 1.00000000 0.062590 0.290475 1.000000
## response_rate score cumulative_response_rate cumulative_score
## 1 1.000000 0.998651 1.000000 0.998651
## 2 1.000000 0.997730 1.000000 0.998190
## 3 1.000000 0.996856 1.000000 0.997746
## 4 1.000000 0.995996 1.000000 0.997396
## 5 1.000000 0.995354 1.000000 0.996966
## 6 0.888889 0.991413 0.945946 0.994265
## 7 1.000000 0.986741 0.964286 0.991712
## 8 0.944444 0.978524 0.959459 0.988504
## 9 0.945946 0.968713 0.954955 0.981907
## 10 1.000000 0.950419 0.966216 0.974035
## 11 0.918919 0.928836 0.956757 0.964995
## 12 0.944444 0.889548 0.954751 0.952705
## 13 0.810811 0.840571 0.934109 0.936624
## 14 0.810811 0.768402 0.918644 0.915525
## 15 0.783784 0.622739 0.903614 0.882895
## 16 0.243243 0.336124 0.837398 0.828070
## 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.051780 0.113269 6.148867 12.962477
## 7 0.061489 0.174757 19.417476 15.152566
## 8 0.055016 0.229773 12.783172 14.576227
## 9 0.113269 0.343042 12.962477 14.038310
## 10 0.119741 0.462783 19.417476 15.383102
## 11 0.110032 0.572816 9.734978 14.253477
## 12 0.110032 0.682848 12.783172 14.013970
## 13 0.097087 0.779935 -3.175020 11.548882
## 14 0.097087 0.877023 -3.175020 9.702156
## 15 0.093851 0.970874 -6.402519 7.907358
## 16 0.029126 1.000000 -70.952506 0.000000
## kolmogorov_smirnov
## 1 0.012945
## 2 0.025890
## 3 0.038835
## 4 0.048544
## 5 0.061489
## 6 0.079935
## 7 0.141424
## 8 0.179773
## 9 0.259709
## 10 0.379450
## 11 0.439482
## 12 0.516181
## 13 0.496602
## 14 0.477023
## 15 0.437540
## 16 0.000000
##
## $residual_deviance
## [1] 240.2764
##
## $null_deviance
## [1] 327.7324
##
## $AIC
## [1] 252.2764
##
## $loglikelihood
## [1] 0
##
## $null_degrees_of_freedom
## [1] 368
##
## $residual_degrees_of_freedom
## [1] 363
h2o.auc(performance_h2o)
## [1] 0.8325782
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted) for max f1 @ threshold = 0.425831482222289:
## Left No Error Rate
## Left 25 35 0.583333 =35/60
## No 5 304 0.016181 =5/309
## Totals 30 339 0.108401 =40/369