Evaluate a set of TT models on a model shelf
Source:R/complete_tt.R, R/make_tt_stats.R
shelf_make_tt_stats.RdThis function first generates several cuts of a shelf data -
each cut is the original shelf data (shelf$data) with only the first
n_var most important features left. Each such cut is then split into 75%
train and 25% test parts. For more details see shelf_make_tt_data_cuts(),
as this function is used under the hood.
We fit a set of models (see tt_get_model_specs()) on train and evaluate
them on test. The result costitutes a dataframe with the following columns:
name,spec- name and specification of a TT model as intt_get_model_specs()n_var,trainandtest- number of features selected, train and test data cut as inshelf_make_tt_data_cuts()model- model that was fit ontrainbased onspecspecificationpred-testbut with predicted class and class probability columns attachedaccuracy,brier- numeric scores calculated onpredconfusion_matrix- confusion matrix for actual segment vs predicted segment
So essentially we generate all combinations of a shelf_make_tt_data_cuts()
output and a tt_get_model_specs() output and then fit and evaluate all
the TT models on each of the data cut.
shelf_make_complete_tt_stats() is wrapper for evaluating complete typing
tools, i.e. models using all available features.
Usage
shelf_make_complete_tt_stats(shelf, models = NULL)
shelf_make_tt_stats(shelf, n_var = c(5, 8, 10, 12, 15), models = NULL)Arguments
- shelf
A rack shelf, or in other words, a row of a model rack extracted with
rack_extract_shelf().- models
A vector of TT model names. By default, when this parameter is set to NULL, the full list of supported models is taken:
"xgboost" model from
xgboostpackage"lda" model from
MASSpackage"lightgbm" model from
lightgbmpackage"rf" (random forest) model from
rangerpackage"glmnet" model from
glmnetpackage"svm_rbf" model from
kernlabpackage
- n_var
An integer vector describing different numbers of features to try for training typing tools. Features are taken based on their importance, most important always go first.
Examples
shelf_make_tt_stats(example_seg_shelf)
#> # A tibble: 30 × 10
#> name spec n_var train test model pred accuracy brier
#> <chr> <list> <dbl> <list> <list> <list> <list> <dbl> <dbl>
#> 1 glmnet <spec[+]> 5 <tibble> <tibble> <fit[+]> <tibble> 0.843 0.138
#> 2 glmnet <spec[+]> 8 <tibble> <tibble> <fit[+]> <tibble> 0.803 0.148
#> 3 glmnet <spec[+]> 10 <tibble> <tibble> <fit[+]> <tibble> 0.838 0.144
#> 4 glmnet <spec[+]> 12 <tibble> <tibble> <fit[+]> <tibble> 0.838 0.136
#> 5 glmnet <spec[+]> 15 <tibble> <tibble> <fit[+]> <tibble> 0.737 0.156
#> 6 lda <spec[+]> 5 <tibble> <tibble> <fit[+]> <tibble> 0.716 0.172
#> 7 lda <spec[+]> 8 <tibble> <tibble> <fit[+]> <tibble> 0.703 0.185
#> 8 lda <spec[+]> 10 <tibble> <tibble> <fit[+]> <tibble> 0.703 0.195
#> 9 lda <spec[+]> 12 <tibble> <tibble> <fit[+]> <tibble> 0.686 0.210
#> 10 lda <spec[+]> 15 <tibble> <tibble> <fit[+]> <tibble> 0.738 0.226
#> # ℹ 20 more rows
#> # ℹ 1 more variable: confusion_matrix <list>
shelf_make_tt_stats(example_seg_shelf, n_var = 5:10, models = c("rf", "lda"))
#> # A tibble: 12 × 10
#> name spec n_var train test model pred accuracy brier
#> <chr> <list> <int> <list> <list> <list> <list> <dbl> <dbl>
#> 1 lda <spec[+]> 5 <tibble> <tibble> <fit[+]> <tibble> 0.707 0.173
#> 2 lda <spec[+]> 6 <tibble> <tibble> <fit[+]> <tibble> 0.778 0.139
#> 3 lda <spec[+]> 7 <tibble> <tibble> <fit[+]> <tibble> 0.820 0.142
#> 4 lda <spec[+]> 8 <tibble> <tibble> <fit[+]> <tibble> 0.820 0.143
#> 5 lda <spec[+]> 9 <tibble> <tibble> <fit[+]> <tibble> 0.820 0.145
#> 6 lda <spec[+]> 10 <tibble> <tibble> <fit[+]> <tibble> 0.820 0.144
#> 7 rf <spec[+]> 5 <tibble> <tibble> <fit[+]> <tibble> 0.806 0.173
#> 8 rf <spec[+]> 6 <tibble> <tibble> <fit[+]> <tibble> 0.758 0.163
#> 9 rf <spec[+]> 7 <tibble> <tibble> <fit[+]> <tibble> 0.927 0.149
#> 10 rf <spec[+]> 8 <tibble> <tibble> <fit[+]> <tibble> 0.927 0.145
#> 11 rf <spec[+]> 9 <tibble> <tibble> <fit[+]> <tibble> 0.892 0.146
#> 12 rf <spec[+]> 10 <tibble> <tibble> <fit[+]> <tibble> 0.892 0.145
#> # ℹ 1 more variable: confusion_matrix <list>
# complete TT stats (using all available features)
shelf_make_complete_tt_stats(example_seg_shelf)
#> # A tibble: 6 × 10
#> name spec n_var train test model pred accuracy brier
#> <chr> <list> <int> <list> <list> <list> <list> <dbl> <dbl>
#> 1 glmnet <spec[+]> 54 <tibble> <tibble> <fit[+]> <tibble> 0.922 0.0989
#> 2 svm_rbf <spec[+]> 54 <tibble> <tibble> <fit[+]> <tibble> 0.799 0.123
#> 3 rf <spec[+]> 54 <tibble> <tibble> <fit[+]> <tibble> 0.778 0.189
#> 4 xgboost <spec[+]> 54 <tibble> <tibble> <fit[+]> <tibble> 0.690 0.229
#> 5 lightgbm <spec[+]> 54 <tibble> <tibble> <fit[+]> <tibble> 0.637 0.232
#> 6 lda <spec[+]> 54 <tibble> <tibble> <fit[+]> <tibble> 0.509 0.463
#> # ℹ 1 more variable: confusion_matrix <list>