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.3.3
##
## ----------------------------------------------------------------------
##
## Your next step is to start H2O:
## > h2o.init()
##
## For H2O package documentation, ask for help:
## > ??h2o
##
## After starting H2O, you can use the Web UI at http://localhost:54321
## For more information visit https://docs.h2o.ai
##
## ----------------------------------------------------------------------
##
## Attaching package: 'h2o'
## The following objects are masked from 'package:stats':
##
## cor, sd, var
## The following objects are masked from 'package:base':
##
## %*%, %in%, &&, ||, apply, as.factor, as.numeric, colnames,
## colnames<-, ifelse, is.character, is.factor, is.numeric, log,
## log10, log1p, log2, round, signif, trunc
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.3.3
## Warning: package 'forcats' was built under R version 4.3.3
## ── 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)
## Warning: package 'tidymodels' was built under R version 4.3.3
## ── Attaching packages ────────────────────────────────────── tidymodels 1.2.0 ──
## ✔ broom 1.0.7 ✔ rsample 1.2.1
## ✔ dials 1.3.0 ✔ 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 'dials' was built under R version 4.3.3
## Warning: package 'infer' was built under R version 4.3.3
## Warning: package 'modeldata' was built under R version 4.3.3
## Warning: package 'parsnip' was built under R version 4.3.3
## Warning: package 'recipes' was built under R version 4.3.3
## Warning: package 'rsample' was built under R version 4.3.3
## Warning: package 'tune' was built under R version 4.3.3
## Warning: package 'workflows' was built under R version 4.3.3
## Warning: package 'workflowsets' was built under R version 4.3.3
## Warning: package 'yardstick' 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))
## 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`
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()
##
## H2O is not running yet, starting it now...
##
## Note: In case of errors look at the following log files:
## C:\Users\ktqua\AppData\Local\Temp\RtmpqKPwds\file55ac1ebf3ed8/h2o_ktqua_started_from_r.out
## C:\Users\ktqua\AppData\Local\Temp\RtmpqKPwds\file55ac4eae336/h2o_ktqua_started_from_r.err
##
##
## Starting H2O JVM and connecting: Connection successful!
##
## R is connected to the H2O cluster:
## H2O cluster uptime: 3 seconds 150 milliseconds
## H2O cluster timezone: America/New_York
## H2O data parsing timezone: UTC
## H2O cluster version: 3.44.0.3
## H2O cluster version age: 11 months and 1 day
## H2O cluster name: H2O_started_from_R_ktqua_qxv383
## H2O cluster total nodes: 1
## H2O cluster total memory: 3.91 GB
## H2O cluster total cores: 16
## H2O cluster allowed cores: 16
## 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 ucrt)
## Warning in h2o.clusterInfo():
## Your H2O cluster version is (11 months and 1 day) 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
train_tbl_h2o <- as.h2o(train_tbl)
##
|
| | 0%
|
|======================================================================| 100%
split.h2o <- h2o.splitFrame(train_tbl_h2o, ratios = c(0.85), seed = 2345)
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%
|
|=== | 4%
## 20:29:34.928: 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.
## 20:29:34.943: AutoML: XGBoost is not available; skipping it.
|
|============ | 17%
|
|============================================ | 62%
|
|======================================================================| 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_1_20241121_202934 0.8288565 0.3392932
## 2 GLM_1_AutoML_1_20241121_202934 0.8260518 0.3319037
## 3 StackedEnsemble_AllModels_1_AutoML_1_20241121_202934 0.8222222 0.3361570
## 4 DRF_1_AutoML_1_20241121_202934 0.8020227 0.4419085
## 5 GBM_1_AutoML_1_20241121_202934 0.8019417 0.3517160
## 6 GBM_grid_1_AutoML_1_20241121_202934_model_1 0.7985437 0.3524093
## aucpr mean_per_class_error rmse mse
## 1 0.9460236 0.2997573 0.3090969 0.09554089
## 2 0.9465804 0.2930421 0.3082312 0.09500649
## 3 0.9452940 0.3013754 0.3134806 0.09827006
## 4 0.9410867 0.4048544 0.3299790 0.10888611
## 5 0.9481301 0.3328479 0.3265760 0.10665191
## 6 0.9474605 0.3462783 0.3266327 0.10668889
##
## [12 rows x 7 columns]
models_h2o@leader
## Model Details:
## ==============
##
## H2OBinomialModel: stackedensemble
## Model ID: StackedEnsemble_BestOfFamily_1_AutoML_1_20241121_202934
## Model Summary for Stacked Ensemble:
## key value
## 1 Stacking strategy cross_validation
## 2 Number of base models (used / total) 3/4
## 3 # GBM base models (used / total) 1/1
## 4 # GLM base models (used / total) 1/1
## 5 # DRF base models (used / total) 1/2
## 6 Metalearner algorithm GLM
## 7 Metalearner fold assignment scheme Random
## 8 Metalearner nfolds 5
## 9 Metalearner fold_column NA
## 10 Custom metalearner hyperparameters None
##
##
## H2OBinomialMetrics: stackedensemble
## ** Reported on training data. **
##
## MSE: 0.05472327
## RMSE: 0.2339301
## LogLoss: 0.1990737
## Mean Per-Class Error: 0.130469
## AUC: 0.9561709
## AUCPR: 0.9890278
## Gini: 0.9123418
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 119 39 0.246835 =39/158
## No 11 769 0.014103 =11/780
## Totals 130 808 0.053305 =50/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.563126 0.968514 286
## 2 max f2 0.424132 0.982593 318
## 3 max f0point5 0.715327 0.962749 249
## 4 max accuracy 0.563126 0.946695 286
## 5 max precision 0.999876 1.000000 0
## 6 max recall 0.390761 1.000000 330
## 7 max specificity 0.999876 1.000000 0
## 8 max absolute_mcc 0.563126 0.800533 286
## 9 max min_per_class_accuracy 0.776402 0.898718 218
## 10 max mean_per_class_accuracy 0.776402 0.898726 218
## 11 max tns 0.999876 158.000000 0
## 12 max fns 0.999876 732.000000 0
## 13 max fps 0.024789 158.000000 399
## 14 max tps 0.390761 780.000000 330
## 15 max tnr 0.999876 1.000000 0
## 16 max fnr 0.999876 0.938462 0
## 17 max fpr 0.024789 1.000000 399
## 18 max tpr 0.390761 1.000000 330
##
## 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.08696747
## RMSE: 0.2949025
## LogLoss: 0.3298427
## Mean Per-Class Error: 0.3684211
## AUC: 0.7386696
## AUCPR: 0.9427951
## Gini: 0.4773392
##
## 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.310327 0.953642 157
## 2 max f2 0.310327 0.980926 157
## 3 max f0point5 0.538763 0.935829 150
## 4 max accuracy 0.310327 0.914110 157
## 5 max precision 0.999969 1.000000 0
## 6 max recall 0.310327 1.000000 157
## 7 max specificity 0.999969 1.000000 0
## 8 max absolute_mcc 0.310327 0.489735 157
## 9 max min_per_class_accuracy 0.881049 0.631579 97
## 10 max mean_per_class_accuracy 0.661916 0.718019 139
## 11 max tns 0.999969 19.000000 0
## 12 max fns 0.999969 143.000000 0
## 13 max fps 0.058503 19.000000 162
## 14 max tps 0.310327 144.000000 157
## 15 max tnr 0.999969 1.000000 0
## 16 max fnr 0.999969 0.993056 0
## 17 max fpr 0.058503 1.000000 162
## 18 max tpr 0.310327 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.09504906
## RMSE: 0.3083003
## LogLoss: 0.3283702
## Mean Per-Class Error: 0.3469409
## AUC: 0.8451883
## AUCPR: 0.952665
## Gini: 0.6903765
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## Left No Error Rate
## Left 51 107 0.677215 =107/158
## No 13 767 0.016667 =13/780
## Totals 64 874 0.127932 =120/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.421707 0.927449 343
## 2 max f2 0.268651 0.965108 383
## 3 max f0point5 0.703795 0.927590 253
## 4 max accuracy 0.614485 0.876333 291
## 5 max precision 0.999867 1.000000 0
## 6 max recall 0.268651 1.000000 383
## 7 max specificity 0.999867 1.000000 0
## 8 max absolute_mcc 0.684976 0.554688 262
## 9 max min_per_class_accuracy 0.827524 0.765385 183
## 10 max mean_per_class_accuracy 0.732193 0.799221 238
## 11 max tns 0.999867 158.000000 0
## 12 max fns 0.999867 760.000000 0
## 13 max fps 0.044803 158.000000 399
## 14 max tps 0.268651 780.000000 383
## 15 max tnr 0.999867 1.000000 0
## 16 max fnr 0.999867 0.974359 0
## 17 max fpr 0.044803 1.000000 399
## 18 max tpr 0.268651 1.000000 383
##
## 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.892513 0.024769 0.899038 0.871134 0.888268 0.872449
## auc 0.859858 0.044319 0.831594 0.811667 0.858730 0.869284
## err 0.107487 0.024769 0.100962 0.128866 0.111732 0.127551
## err_count 20.400000 5.727129 21.000000 25.000000 20.000000 25.000000
## f0point5 0.918882 0.016566 0.915066 0.895062 0.920699 0.922330
## cv_5_valid
## accuracy 0.931677
## auc 0.928014
## err 0.068323
## err_count 11.000000
## f0point5 0.941255
##
## ---
## mean sd cv_1_valid cv_2_valid cv_3_valid
## precision 0.907401 0.019894 0.896040 0.878788 0.913333
## r2 0.313655 0.062929 0.255385 0.254291 0.371593
## recall 0.968977 0.031686 1.000000 0.966667 0.951389
## residual_deviance 122.249830 32.741760 121.950640 168.284100 121.450485
## rmse 0.306703 0.037777 0.290017 0.361622 0.314400
## specificity 0.488000 0.163039 0.222222 0.545455 0.628571
## cv_4_valid cv_5_valid
## precision 0.921212 0.927632
## r2 0.300016 0.386990
## recall 0.926829 1.000000
## residual_deviance 123.850624 75.713326
## rmse 0.309232 0.258245
## specificity 0.593750 0.450000
?h2o.getModel
## starting httpd help server ... done
?h2o.saveModel
?h2o.loadModel
# h2o.getModel("GLM_1_AutoML_2_20241121_141202") %>% h2o.saveModel("h2o_models/")
best_model <- h2o.loadModel("h2o_models/StackedEnsemble_BestOfFamily_3_AutoML_2_20241121_141202")
predictions <- h2o.predict(best_model, newdata = test_h2o)
##
|
| | 0%
|
|======================================================================| 100%
prediction_tbl <- predictions %>%
as_tibble()
prediction_tbl %>%
bind_cols(test_tbl)
## New names:
## • `...1` -> `...4`
## # A tibble: 369 × 36
## predict Left No ...4 Age Attrition BusinessTravel DailyRate
## <fct> <dbl> <dbl> <dbl> <dbl> <fct> <fct> <dbl>
## 1 No 0.553 0.447 1 41 Left Travel_Rarely 1102
## 2 No 0.0163 0.984 2 49 No Travel_Frequently 279
## 3 No 0.286 0.714 4 33 No Travel_Frequently 1392
## 4 No 0.188 0.812 7 59 No Travel_Rarely 1324
## 5 No 0.0636 0.936 9 38 No Travel_Frequently 216
## 6 No 0.295 0.705 12 29 No Travel_Rarely 153
## 7 No 0.0512 0.949 14 34 No Travel_Rarely 1346
## 8 Left 0.853 0.147 15 28 Left Travel_Rarely 103
## 9 No 0.316 0.684 18 22 No Non-Travel 1123
## 10 No 0.0230 0.977 19 53 No Travel_Rarely 1219
## # ℹ 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>, …
?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_3_AutoML_2_20241121_141202"
##
## $model$type
## [1] "Key<Model>"
##
## $model$URL
## [1] "/3/Models/StackedEnsemble_BestOfFamily_3_AutoML_2_20241121_141202"
##
##
## $model_checksum
## [1] "4156580137228483200"
##
## $frame
## $frame$name
## [1] "test_tbl_sid_8cc4_3"
##
##
## $frame_checksum
## [1] 4.524936e+14
##
## $description
## NULL
##
## $scoring_time
## [1] 1.732239e+12
##
## $predictions
## NULL
##
## $MSE
## [1] 0.09587403
##
## $RMSE
## [1] 0.3096353
##
## $nobs
## [1] 369
##
## $custom_metric_name
## NULL
##
## $custom_metric_value
## [1] 0
##
## $r2
## [1] 0.2958844
##
## $logloss
## [1] 0.3311203
##
## $AUC
## [1] 0.8265912
##
## $pr_auc
## [1] 0.9477099
##
## $Gini
## [1] 0.6531823
##
## $mean_per_class_error
## [1] 0.3064725
##
## $domain
## [1] "Left" "No"
##
## $cm
## $cm$`__meta`
## $cm$`__meta`$schema_version
## [1] 3
##
## $cm$`__meta`$schema_name
## [1] "ConfusionMatrixV3"
##
## $cm$`__meta`$schema_type
## [1] "ConfusionMatrix"
##
##
## $cm$table
## Confusion Matrix: Row labels: Actual class; Column labels: Predicted class
## Left No Error Rate
## Left 24 36 0.6000 = 36 / 60
## No 4 305 0.0129 = 4 / 309
## Totals 28 341 0.1084 = 40 / 369
##
##
## $thresholds_and_metric_scores
## Metrics for Thresholds: Binomial metrics as a function of classification thresholds
## threshold f1 f2 f0point5 accuracy precision recall specificity
## 1 0.998581 0.006452 0.004042 0.015974 0.165312 1.000000 0.003236 1.000000
## 2 0.998521 0.012862 0.008078 0.031546 0.168022 1.000000 0.006472 1.000000
## 3 0.998082 0.019231 0.012107 0.046729 0.170732 1.000000 0.009709 1.000000
## 4 0.997707 0.025559 0.016129 0.061538 0.173442 1.000000 0.012945 1.000000
## 5 0.997307 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.234452 0.918276 0.965625 0.875354 0.850949 0.848901 1.000000
## 365 0.223747 0.916914 0.965022 0.873375 0.848238 0.846575 1.000000
## 366 0.147328 0.915556 0.964419 0.871404 0.845528 0.844262 1.000000
## 367 0.137162 0.914201 0.963818 0.869443 0.842818 0.841962 1.000000
## 368 0.070722 0.912851 0.963217 0.867490 0.840108 0.839674 1.000000
## 369 0.057428 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.392645 0.938462 340
## 2 max f2 0.257868 0.968652 358
## 3 max f0point5 0.683649 0.917372 306
## 4 max accuracy 0.404420 0.891599 338
## 5 max precision 0.998581 1.000000 0
## 6 max recall 0.257868 1.000000 358
## 7 max specificity 0.998581 1.000000 0
## 8 max absolute_mcc 0.404420 0.540731 338
## 9 max min_per_class_accuracy 0.828638 0.763754 249
## 10 max mean_per_class_accuracy 0.854492 0.765939 231
## 11 max tns 0.998581 60.000000 0
## 12 max fns 0.998581 308.000000 0
## 13 max fps 0.057428 60.000000 368
## 14 max tps 0.257868 309.000000 358
## 15 max tnr 0.998581 1.000000 0
## 16 max fnr 0.998581 0.996764 0
## 17 max fpr 0.057428 1.000000 368
## 18 max tpr 0.257868 1.000000 358
##
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 83.74 %, avg score: 82.83 %
## group cumulative_data_fraction lower_threshold lift cumulative_lift
## 1 1 0.01084011 0.997435 1.194175 1.194175
## 2 2 0.02168022 0.996651 1.194175 1.194175
## 3 3 0.03252033 0.995230 1.194175 1.194175
## 4 4 0.04065041 0.994597 1.194175 1.194175
## 5 5 0.05149051 0.993340 1.194175 1.194175
## 6 6 0.10027100 0.989521 1.061489 1.129625
## 7 7 0.15176152 0.983333 1.194175 1.151526
## 8 8 0.20054201 0.977532 1.127832 1.145762
## 9 9 0.30081301 0.961728 1.129625 1.140383
## 10 10 0.40108401 0.945806 1.161900 1.145762
## 11 11 0.50135501 0.912374 1.129625 1.142535
## 12 12 0.59891599 0.869036 1.094660 1.134736
## 13 13 0.69918699 0.818766 0.968250 1.110860
## 14 14 0.79945799 0.722419 1.000525 1.097022
## 15 15 0.89972900 0.493927 0.871425 1.071880
## 16 16 1.00000000 0.057428 0.355025 1.000000
## response_rate score cumulative_response_rate cumulative_score
## 1 1.000000 0.998223 1.000000 0.998223
## 2 1.000000 0.996992 1.000000 0.997607
## 3 1.000000 0.995803 1.000000 0.997006
## 4 1.000000 0.994879 1.000000 0.996581
## 5 1.000000 0.993894 1.000000 0.996015
## 6 0.888889 0.991573 0.945946 0.993854
## 7 1.000000 0.986705 0.964286 0.991428
## 8 0.944444 0.979711 0.959459 0.988578
## 9 0.945946 0.970866 0.954955 0.982674
## 10 0.972973 0.954101 0.959459 0.975531
## 11 0.945946 0.929955 0.956757 0.966416
## 12 0.916667 0.891526 0.950226 0.954216
## 13 0.810811 0.843387 0.930233 0.938322
## 14 0.837838 0.772473 0.918644 0.917521
## 15 0.729730 0.626613 0.897590 0.885100
## 16 0.297297 0.318152 0.837398 0.828252
## 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.116505 0.459547 16.189976 14.576227
## 11 0.113269 0.572816 12.962477 14.253477
## 12 0.106796 0.679612 9.466019 13.473619
## 13 0.097087 0.776699 -3.175020 11.086024
## 14 0.100324 0.877023 0.052480 9.702156
## 15 0.087379 0.964401 -12.857518 7.187975
## 16 0.035599 1.000000 -64.497507 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.359547
## 11 0.439482
## 12 0.496278
## 13 0.476699
## 14 0.477023
## 15 0.397735
## 16 0.000000
##
## $residual_deviance
## [1] 244.3668
##
## $null_deviance
## [1] 327.7324
##
## $AIC
## [1] 252.3668
##
## $loglikelihood
## [1] 0
##
## $null_degrees_of_freedom
## [1] 368
##
## $residual_degrees_of_freedom
## [1] 365
h2o.auc(performance_h2o)
## [1] 0.8265912
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted) for max f1 @ threshold = 0.392644894161019:
## Left No Error Rate
## Left 24 36 0.600000 =36/60
## No 4 305 0.012945 =4/309
## Totals 28 341 0.108401 =40/369
h2o.metric(performance_h2o)
## Metrics for Thresholds: Binomial metrics as a function of classification thresholds
## threshold f1 f2 f0point5 accuracy precision recall specificity
## 1 0.998581 0.006452 0.004042 0.015974 0.165312 1.000000 0.003236 1.000000
## 2 0.998521 0.012862 0.008078 0.031546 0.168022 1.000000 0.006472 1.000000
## 3 0.998082 0.019231 0.012107 0.046729 0.170732 1.000000 0.009709 1.000000
## 4 0.997707 0.025559 0.016129 0.061538 0.173442 1.000000 0.012945 1.000000
## 5 0.997307 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.234452 0.918276 0.965625 0.875354 0.850949 0.848901 1.000000
## 365 0.223747 0.916914 0.965022 0.873375 0.848238 0.846575 1.000000
## 366 0.147328 0.915556 0.964419 0.871404 0.845528 0.844262 1.000000
## 367 0.137162 0.914201 0.963818 0.869443 0.842818 0.841962 1.000000
## 368 0.070722 0.912851 0.963217 0.867490 0.840108 0.839674 1.000000
## 369 0.057428 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