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)
##
## ----------------------------------------------------------------------
##
## Your next step is to start H2O:
## > h2o.init()
##
## For H2O package documentation, ask for help:
## > ??h2o
##
## After starting H2O, you can use the Web UI at http://localhost:54321
## For more information visit https://docs.h2o.ai
##
## ----------------------------------------------------------------------
##
## Attaching package: 'h2o'
## The following objects are masked from 'package:stats':
##
## cor, sd, var
## The following objects are masked from 'package:base':
##
## &&, %*%, %in%, ||, apply, as.factor, as.numeric, colnames,
## colnames<-, ifelse, is.character, is.factor, is.numeric, log,
## log10, log1p, log2, round, signif, trunc
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ lubridate::day() masks h2o::day()
## ✖ dplyr::filter() masks stats::filter()
## ✖ lubridate::hour() masks h2o::hour()
## ✖ dplyr::lag() masks stats::lag()
## ✖ lubridate::month() masks h2o::month()
## ✖ lubridate::week() masks h2o::week()
## ✖ lubridate::year() masks h2o::year()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidymodels)
## ── Attaching packages ────────────────────────────────────── tidymodels 1.2.0 ──
## ✔ broom 1.0.5 ✔ rsample 1.2.1
## ✔ dials 1.2.1 ✔ tune 1.2.1
## ✔ infer 1.0.7 ✔ workflows 1.1.4
## ✔ modeldata 1.4.0 ✔ workflowsets 1.1.0
## ✔ parsnip 1.2.1 ✔ yardstick 1.3.1
## ✔ recipes 1.0.10
## Warning: package 'modeldata' was built under R version 4.3.3
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ scales::discard() masks purrr::discard()
## ✖ dplyr::filter() masks stats::filter()
## ✖ recipes::fixed() masks stringr::fixed()
## ✖ dplyr::lag() masks stats::lag()
## ✖ yardstick::spec() masks readr::spec()
## ✖ recipes::step() masks stats::step()
## • Use tidymodels_prefer() to resolve common conflicts.
library(tidyquant)
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
##
## ######################### Warning from 'xts' package ##########################
## # #
## # The dplyr lag() function breaks how base R's lag() function is supposed to #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
## # source() into this session won't work correctly. #
## # #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
## # dplyr from breaking base R's lag() function. #
## # #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
## # #
## ###############################################################################
##
## Attaching package: 'xts'
##
## The following objects are masked from 'package:dplyr':
##
## first, last
##
##
## Attaching package: 'PerformanceAnalytics'
##
## The following object is masked from 'package:graphics':
##
## legend
##
## Loading required package: quantmod
## Loading required package: TTR
##
## Attaching package: 'TTR'
##
## The following object is masked from 'package:dials':
##
## momentum
##
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
data <- read_csv("../00_data/data_wrangled/data_clean.csv") %>%
# h2o requires all variables to be either numeric or factors
mutate(across(where(is.character), factor))
## Rows: 1470 Columns: 32
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): Attrition, BusinessTravel, Department, EducationField, Gender, Job...
## dbl (24): Age, DailyRate, DistanceFromHome, Education, EmployeeNumber, Envir...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
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 h2o
h2o.init()
## Connection successful!
##
## R is connected to the H2O cluster:
## H2O cluster uptime: 2 hours 8 minutes
## H2O cluster timezone: America/New_York
## H2O data parsing timezone: UTC
## H2O cluster version: 3.44.0.3
## H2O cluster version age: 11 months
## H2O cluster name: H2O_started_from_R_johnnymckinnon_fhp551
## H2O cluster total nodes: 1
## H2O cluster total memory: 2.97 GB
## H2O cluster total cores: 12
## H2O cluster allowed cores: 12
## H2O cluster healthy: TRUE
## H2O Connection ip: localhost
## H2O Connection port: 54321
## H2O Connection proxy: NA
## H2O Internal Security: FALSE
## R Version: R version 4.3.2 (2023-10-31)
## Warning in h2o.clusterInfo():
## Your H2O cluster version is (11 months) 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.h20 <- h2o.splitFrame(as.h2o(train_tbl), ratios = c(0.85), seed = 2345)
##
|
| | 0%
|
|======================================================================| 100%
train_h2o <- split.h20[[1]]
valid_h2o <- split.h20[[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%
|
|==== | 5%
## 15:02:36.56: 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.
|
|============= | 18%
|
|====================== | 31%
|
|======================================================================| 100%
Examine the output of h2o.automl
models_h2o %>% typeof()
## [1] "S4"
models_h2o %>% slotNames()
## [1] "project_name" "leader" "leaderboard" "event_log"
## [5] "modeling_steps" "training_info"
models_h2o@leaderboard
## model_id auc logloss
## 1 GBM_1_AutoML_5_20241121_150236 0.8552319 0.3243584
## 2 GLM_1_AutoML_5_20241121_150236 0.8400216 0.3186222
## 3 StackedEnsemble_BestOfFamily_1_AutoML_5_20241121_150236 0.8386731 0.3679170
## 4 StackedEnsemble_AllModels_1_AutoML_5_20241121_150236 0.8330097 0.3360015
## 5 XGBoost_1_AutoML_5_20241121_150236 0.8303128 0.3350992
## 6 GBM_2_AutoML_5_20241121_150236 0.8120820 0.3397394
## aucpr mean_per_class_error rmse mse
## 1 0.6161812 0.2221683 0.3118296 0.09723772
## 2 0.6515822 0.2369741 0.3064601 0.09391777
## 3 0.6224065 0.2087379 0.3035404 0.09213679
## 4 0.6167542 0.2087379 0.3044454 0.09268702
## 5 0.5727296 0.2367314 0.3163680 0.10008873
## 6 0.5663229 0.2165858 0.3174311 0.10076251
##
## [12 rows x 7 columns]
models_h2o@leader
## Model Details:
## ==============
##
## H2OBinomialModel: gbm
## Model ID: GBM_1_AutoML_5_20241121_150236
## Model Summary:
## number_of_trees number_of_internal_trees model_size_in_bytes min_depth
## 1 59 59 7760 3
## max_depth mean_depth min_leaves max_leaves mean_leaves
## 1 5 3.93220 5 7 5.81356
##
##
## H2OBinomialMetrics: gbm
## ** Reported on training data. **
##
## MSE: 0.07760747
## RMSE: 0.2785812
## LogLoss: 0.2692952
## Mean Per-Class Error: 0.1906261
## AUC: 0.9218063
## AUCPR: 0.795637
## Gini: 0.8436125
## R^2: 0.4223142
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## No Yes Error Rate
## No 766 22 0.027919 =22/788
## Yes 53 97 0.353333 =53/150
## Totals 819 119 0.079957 =75/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.333741 0.721190 97
## 2 max f2 0.189332 0.756155 179
## 3 max f0point5 0.439043 0.781938 63
## 4 max accuracy 0.346929 0.920043 91
## 5 max precision 0.852824 1.000000 0
## 6 max recall 0.039666 1.000000 359
## 7 max specificity 0.852824 1.000000 0
## 8 max absolute_mcc 0.333741 0.681408 97
## 9 max min_per_class_accuracy 0.193072 0.846447 176
## 10 max mean_per_class_accuracy 0.221420 0.851937 152
## 11 max tns 0.852824 788.000000 0
## 12 max fns 0.852824 149.000000 0
## 13 max fps 0.007684 788.000000 399
## 14 max tps 0.039666 150.000000 359
## 15 max tnr 0.852824 1.000000 0
## 16 max fnr 0.852824 0.993333 0
## 17 max fpr 0.007684 1.000000 399
## 18 max tpr 0.039666 1.000000 359
##
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: gbm
## ** Reported on validation data. **
## ** Validation metrics **
##
## MSE: 0.1054871
## RMSE: 0.3247877
## LogLoss: 0.3436335
## Mean Per-Class Error: 0.2551743
## AUC: 0.8295207
## AUCPR: 0.5567645
## Gini: 0.6590414
## R^2: 0.2367413
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## No Yes Error Rate
## No 122 14 0.102941 =14/136
## Yes 11 16 0.407407 =11/27
## Totals 133 30 0.153374 =25/163
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.309375 0.561404 29
## 2 max f2 0.126346 0.666667 71
## 3 max f0point5 0.342225 0.569106 23
## 4 max accuracy 0.541568 0.865031 4
## 5 max precision 0.842469 1.000000 0
## 6 max recall 0.035645 1.000000 142
## 7 max specificity 0.842469 1.000000 0
## 8 max absolute_mcc 0.309375 0.469734 29
## 9 max min_per_class_accuracy 0.219496 0.703704 44
## 10 max mean_per_class_accuracy 0.126346 0.767974 71
## 11 max tns 0.842469 136.000000 0
## 12 max fns 0.842469 26.000000 0
## 13 max fps 0.009418 136.000000 162
## 14 max tps 0.035645 27.000000 142
## 15 max tnr 0.842469 1.000000 0
## 16 max fnr 0.842469 0.962963 0
## 17 max fpr 0.009418 1.000000 162
## 18 max tpr 0.035645 1.000000 142
##
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## H2OBinomialMetrics: gbm
## ** Reported on cross-validation data. **
## ** 5-fold cross-validation on training data (Metrics computed for combined holdout predictions) **
##
## MSE: 0.1021651
## RMSE: 0.3196328
## LogLoss: 0.3464857
## Mean Per-Class Error: 0.2604484
## AUC: 0.8034052
## AUCPR: 0.5856122
## Gini: 0.6068105
## R^2: 0.2395148
##
## Confusion Matrix (vertical: actual; across: predicted) for F1-optimal threshold:
## No Yes Error Rate
## No 719 69 0.087563 =69/788
## Yes 65 85 0.433333 =65/150
## Totals 784 154 0.142857 =134/938
##
## Maximum Metrics: Maximum metrics at their respective thresholds
## metric threshold value idx
## 1 max f1 0.274891 0.559211 116
## 2 max f2 0.162481 0.604925 211
## 3 max f0point5 0.351807 0.622605 74
## 4 max accuracy 0.405894 0.879531 50
## 5 max precision 0.846770 1.000000 0
## 6 max recall 0.012518 1.000000 395
## 7 max specificity 0.846770 1.000000 0
## 8 max absolute_mcc 0.351807 0.487870 74
## 9 max min_per_class_accuracy 0.167255 0.733503 206
## 10 max mean_per_class_accuracy 0.197244 0.741015 177
## 11 max tns 0.846770 788.000000 0
## 12 max fns 0.846770 149.000000 0
## 13 max fps 0.005852 788.000000 399
## 14 max tps 0.012518 150.000000 395
## 15 max tnr 0.846770 1.000000 0
## 16 max fnr 0.846770 0.993333 0
## 17 max fpr 0.005852 1.000000 399
## 18 max tpr 0.012518 1.000000 395
##
## Gains/Lift Table: Extract with `h2o.gainsLift(<model>, <data>)` or `h2o.gainsLift(<model>, valid=<T/F>, xval=<T/F>)`
## Cross-Validation Metrics Summary:
## mean sd cv_1_valid cv_2_valid cv_3_valid
## accuracy 0.874206 0.015736 0.893617 0.867021 0.856383
## auc 0.800818 0.046494 0.841983 0.763080 0.753165
## err 0.125794 0.015736 0.106383 0.132979 0.143617
## err_count 23.600000 2.966479 20.000000 25.000000 27.000000
## f0point5 0.607235 0.055991 0.669014 0.576923 0.538462
## f1 0.583766 0.061648 0.655172 0.545455 0.509091
## f2 0.567463 0.093249 0.641892 0.517241 0.482759
## lift_top_group 6.253334 0.018257 6.266667 6.266667 6.266667
## logloss 0.347126 0.028586 0.322462 0.375521 0.372290
## max_per_class_error 0.440000 0.118790 0.366667 0.500000 0.533333
## mcc 0.516979 0.067355 0.592861 0.470996 0.428220
## mean_per_class_accuracy 0.747000 0.050090 0.788186 0.718354 0.698523
## mean_per_class_error 0.253000 0.050090 0.211814 0.281646 0.301477
## mse 0.102380 0.009717 0.092129 0.112453 0.110710
## pr_auc 0.582737 0.089843 0.704703 0.500874 0.490292
## precision 0.627903 0.077290 0.678571 0.600000 0.560000
## r2 0.237864 0.073080 0.313040 0.161491 0.174484
## recall 0.560000 0.118790 0.633333 0.500000 0.466667
## rmse 0.319678 0.015247 0.303527 0.335340 0.332732
## specificity 0.934000 0.027641 0.943038 0.936709 0.930380
## cv_4_valid cv_5_valid
## accuracy 0.887701 0.866310
## auc 0.789172 0.856688
## err 0.112299 0.133690
## err_count 21.000000 25.000000
## f0point5 0.660377 0.591398
## f1 0.571429 0.637681
## f2 0.503597 0.691824
## lift_top_group 6.233333 6.233333
## logloss 0.352718 0.312637
## max_per_class_error 0.533333 0.266667
## mcc 0.528187 0.564630
## mean_per_class_accuracy 0.717410 0.812527
## mean_per_class_error 0.282590 0.187473
## mse 0.104156 0.092451
## pr_auc 0.588982 0.628833
## precision 0.736842 0.564103
## r2 0.226700 0.313605
## recall 0.466667 0.733333
## rmse 0.322733 0.304058
## specificity 0.968153 0.891720
?h2o.getModel
?h2o.saveModel
?h2o.loadModel
#h2o.getModel("DeepLearning_grid_1_AutoML_2_20241121_133626_model_1") %>%
# h2o.saveModel("h2o_models/")
best_model <- h2o.loadModel("h2o_models/DeepLearning_grid_1_AutoML_2_20241121_133626_model_1")
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)
## # A tibble: 369 × 35
## predict No Yes Age Attrition BusinessTravel DailyRate Department
## <fct> <dbl> <dbl> <dbl> <fct> <fct> <dbl> <fct>
## 1 No 0.999 0.00127 59 No Travel_Rarely 1324 Research …
## 2 No 0.997 0.00296 35 No Travel_Rarely 809 Research …
## 3 No 0.999 0.00147 34 No Travel_Rarely 1346 Research …
## 4 No 0.996 0.00410 22 No Non-Travel 1123 Research …
## 5 No 1.00 0.0000856 53 No Travel_Rarely 1219 Sales
## 6 No 0.992 0.00806 24 No Non-Travel 673 Research …
## 7 No 0.994 0.00618 21 No Travel_Rarely 391 Research …
## 8 No 0.986 0.0140 34 Yes Travel_Rarely 699 Research …
## 9 No 1.00 0.000413 53 No Travel_Rarely 1282 Research …
## 10 Yes 0.173 0.827 32 Yes Travel_Frequent… 1125 Research …
## # ℹ 359 more rows
## # ℹ 27 more variables: DistanceFromHome <dbl>, Education <dbl>,
## # EducationField <fct>, EmployeeNumber <dbl>, EnvironmentSatisfaction <dbl>,
## # Gender <fct>, HourlyRate <dbl>, JobInvolvement <dbl>, JobLevel <dbl>,
## # JobRole <fct>, JobSatisfaction <dbl>, MaritalStatus <fct>,
## # MonthlyIncome <dbl>, MonthlyRate <dbl>, NumCompaniesWorked <dbl>,
## # OverTime <fct>, PercentSalaryHike <dbl>, PerformanceRating <dbl>, …
?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] "DeepLearning_grid_1_AutoML_2_20241121_133626_model_1"
##
## $model$type
## [1] "Key<Model>"
##
## $model$URL
## [1] "/3/Models/DeepLearning_grid_1_AutoML_2_20241121_133626_model_1"
##
##
## $model_checksum
## [1] "6379834007049046048"
##
## $frame
## $frame$name
## [1] "test_tbl_sid_bc10_3"
##
##
## $frame_checksum
## [1] "-54413681510283746"
##
## $description
## NULL
##
## $scoring_time
## [1] 1.732219e+12
##
## $predictions
## NULL
##
## $MSE
## [1] 0.1093536
##
## $RMSE
## [1] 0.3306865
##
## $nobs
## [1] 369
##
## $custom_metric_name
## NULL
##
## $custom_metric_value
## [1] 0
##
## $r2
## [1] 0.1968883
##
## $logloss
## [1] 0.4254079
##
## $AUC
## [1] 0.8612729
##
## $pr_auc
## [1] 0.6567892
##
## $Gini
## [1] 0.7225458
##
## $mean_per_class_error
## [1] 0.213835
##
## $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 285 24 0.0777 = 24 / 309
## Yes 21 39 0.3500 = 21 / 60
## Totals 306 63 0.1220 = 45 / 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.950075 0.032787 0.020747 0.078125 0.840108 1.000000 0.016667 1.000000
## 2 0.885005 0.064516 0.041322 0.147059 0.842818 1.000000 0.033333 1.000000
## 3 0.826749 0.095238 0.061728 0.208333 0.845528 1.000000 0.050000 1.000000
## 4 0.826089 0.125000 0.081967 0.263158 0.848238 1.000000 0.066667 1.000000
## 5 0.821489 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.000015 0.283019 0.496689 0.197889 0.176152 0.164835 1.000000
## 365 0.000015 0.282353 0.495868 0.197368 0.173442 0.164384 1.000000
## 366 0.000014 0.281690 0.495050 0.196850 0.170732 0.163934 1.000000
## 367 0.000007 0.281030 0.494234 0.196335 0.168022 0.163488 1.000000
## 368 0.000002 0.280374 0.493421 0.195822 0.165312 0.163043 1.000000
## 369 0.000001 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.069048 0.634146 62
## 2 max f2 0.020304 0.688202 115
## 3 max f0point5 0.160223 0.648148 38
## 4 max accuracy 0.160223 0.883469 38
## 5 max precision 0.950075 1.000000 0
## 6 max recall 0.000200 1.000000 334
## 7 max specificity 0.950075 1.000000 0
## 8 max absolute_mcc 0.069048 0.561268 62
## 9 max min_per_class_accuracy 0.024396 0.783333 109
## 10 max mean_per_class_accuracy 0.020304 0.799919 115
## 11 max tns 0.950075 309.000000 0
## 12 max fns 0.950075 59.000000 0
## 13 max fps 0.000001 309.000000 368
## 14 max tps 0.000200 60.000000 334
## 15 max tnr 0.950075 1.000000 0
## 16 max fnr 0.950075 0.983333 0
## 17 max fpr 0.000001 1.000000 368
## 18 max tpr 0.000200 1.000000 334
##
## $gains_lift_table
## Gains/Lift Table: Avg response rate: 16.26 %, avg score: 5.97 %
## group cumulative_data_fraction lower_threshold lift cumulative_lift
## 1 1 0.01084011 0.822961 6.150000 6.150000
## 2 2 0.02168022 0.641202 6.150000 6.150000
## 3 3 0.03252033 0.490929 6.150000 6.150000
## 4 4 0.04065041 0.425484 4.100000 5.740000
## 5 5 0.05149051 0.384706 3.075000 5.178947
## 6 6 0.10027100 0.164682 3.416667 4.321622
## 7 7 0.15176152 0.082523 2.913158 3.843750
## 8 8 0.20054201 0.057009 1.708333 3.324324
## 9 9 0.30081301 0.023574 1.163514 2.604054
## 10 10 0.40108401 0.012386 0.831081 2.160811
## 11 11 0.50135501 0.006135 0.166216 1.761892
## 12 12 0.59891599 0.003663 0.341667 1.530543
## 13 13 0.69918699 0.001752 0.498649 1.382558
## 14 14 0.79945799 0.000820 0.000000 1.209153
## 15 15 0.89972900 0.000223 0.166216 1.092922
## 16 16 1.00000000 0.000001 0.166216 1.000000
## response_rate score cumulative_response_rate cumulative_score
## 1 1.000000 0.871980 1.000000 0.871980
## 2 1.000000 0.731122 1.000000 0.801551
## 3 1.000000 0.565466 1.000000 0.722856
## 4 0.666667 0.455384 0.933333 0.669361
## 5 0.500000 0.415449 0.842105 0.615906
## 6 0.555556 0.228958 0.702703 0.427661
## 7 0.473684 0.122418 0.625000 0.324096
## 8 0.277778 0.067969 0.540541 0.261795
## 9 0.189189 0.036998 0.423423 0.186863
## 10 0.135135 0.017172 0.351351 0.144440
## 11 0.027027 0.008820 0.286486 0.117316
## 12 0.055556 0.004662 0.248869 0.098965
## 13 0.081081 0.002785 0.224806 0.085172
## 14 0.000000 0.001274 0.196610 0.074649
## 15 0.027027 0.000477 0.177711 0.066383
## 16 0.027027 0.000095 0.162602 0.059736
## capture_rate cumulative_capture_rate gain cumulative_gain
## 1 0.066667 0.066667 515.000000 515.000000
## 2 0.066667 0.133333 515.000000 515.000000
## 3 0.066667 0.200000 515.000000 515.000000
## 4 0.033333 0.233333 310.000000 474.000000
## 5 0.033333 0.266667 207.500000 417.894737
## 6 0.166667 0.433333 241.666667 332.162162
## 7 0.150000 0.583333 191.315789 284.375000
## 8 0.083333 0.666667 70.833333 232.432432
## 9 0.116667 0.783333 16.351351 160.405405
## 10 0.083333 0.866667 -16.891892 116.081081
## 11 0.016667 0.883333 -83.378378 76.189189
## 12 0.033333 0.916667 -65.833333 53.054299
## 13 0.050000 0.966667 -50.135135 38.255814
## 14 0.000000 0.966667 -100.000000 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.133333
## 3 0.200000
## 4 0.230097
## 5 0.256958
## 6 0.397735
## 7 0.515372
## 8 0.556634
## 9 0.576214
## 10 0.555987
## 11 0.456149
## 12 0.379450
## 13 0.319417
## 14 0.199676
## 15 0.099838
## 16 0.000000
h2o.auc(best_model)
## [1] 0.8757022
h2o.confusionMatrix(performance_h2o)
## Confusion Matrix (vertical: actual; across: predicted) for max f1 @ threshold = 0.0690475085435842:
## No Yes Error Rate
## No 285 24 0.077670 =24/309
## Yes 21 39 0.350000 =21/60
## Totals 306 63 0.121951 =45/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.950075 0.032787 0.020747 0.078125 0.840108 1.000000 0.016667 1.000000
## 2 0.885005 0.064516 0.041322 0.147059 0.842818 1.000000 0.033333 1.000000
## 3 0.826749 0.095238 0.061728 0.208333 0.845528 1.000000 0.050000 1.000000
## 4 0.826089 0.125000 0.081967 0.263158 0.848238 1.000000 0.066667 1.000000
## 5 0.821489 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.000015 0.283019 0.496689 0.197889 0.176152 0.164835 1.000000
## 365 0.000015 0.282353 0.495868 0.197368 0.173442 0.164384 1.000000
## 366 0.000014 0.281690 0.495050 0.196850 0.170732 0.163934 1.000000
## 367 0.000007 0.281030 0.494234 0.196335 0.168022 0.163488 1.000000
## 368 0.000002 0.280374 0.493421 0.195822 0.165312 0.163043 1.000000
## 369 0.000001 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