From eba7ded252884148cbba1add1d373368ce0c6e10 Mon Sep 17 00:00:00 2001 From: Kelly Sovacool Date: Mon, 29 May 2023 11:23:04 -0400 Subject: [PATCH 1/8] Preserve factor levels when given To ensure the user's preferred positive class is preserved. We should probably add an argument for this? --- R/performance.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/R/performance.R b/R/performance.R index 15b47236..afeaa99f 100644 --- a/R/performance.R +++ b/R/performance.R @@ -121,7 +121,14 @@ calc_perf_metrics <- function(test_data, trained_model, outcome_colname, perf_me if (class_probs) pred_type <- "prob" preds <- stats::predict(trained_model, test_data, type = pred_type) if (class_probs) { - uniq_obs <- unique(c(test_data %>% dplyr::pull(outcome_colname), as.character(trained_model$pred$obs))) + if (is.factor(test_data %>% dplyr::pull(outcome_colname))) { + uniq_obs <- test_data %>% dplyr::pull(outcome_colname) %>% levels() + } else { + uniq_obs <- unique(c(test_data %>% dplyr::pull(outcome_colname), + as.character(trained_model$pred$obs) + ) + ) + } obs <- factor(test_data %>% dplyr::pull(outcome_colname), levels = uniq_obs) pred_class <- factor(names(preds)[apply(preds, 1, which.max)], levels = uniq_obs) perf_met <- perf_metric_function(data.frame(obs = obs, pred = pred_class, preds), lev = uniq_obs) From fd5beb0b6de15cf77cb8ccfda0426bfcc92d2c5f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 16:07:17 +0000 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=8E=A8=20Style=20R=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/performance.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/performance.R b/R/performance.R index afeaa99f..afe6c5d4 100644 --- a/R/performance.R +++ b/R/performance.R @@ -122,12 +122,14 @@ calc_perf_metrics <- function(test_data, trained_model, outcome_colname, perf_me preds <- stats::predict(trained_model, test_data, type = pred_type) if (class_probs) { if (is.factor(test_data %>% dplyr::pull(outcome_colname))) { - uniq_obs <- test_data %>% dplyr::pull(outcome_colname) %>% levels() + uniq_obs <- test_data %>% + dplyr::pull(outcome_colname) %>% + levels() } else { - uniq_obs <- unique(c(test_data %>% dplyr::pull(outcome_colname), - as.character(trained_model$pred$obs) - ) - ) + uniq_obs <- unique(c( + test_data %>% dplyr::pull(outcome_colname), + as.character(trained_model$pred$obs) + )) } obs <- factor(test_data %>% dplyr::pull(outcome_colname), levels = uniq_obs) pred_class <- factor(names(preds)[apply(preds, 1, which.max)], levels = uniq_obs) From a06db85588f2ec8aa48ec4ae9e43a46530cbed88 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 16:33:49 +0000 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=93=91=20Build=20docs=20site?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/dev/CODE_OF_CONDUCT.html | 2 +- docs/dev/CONTRIBUTING.html | 2 +- docs/dev/LICENSE-text.html | 2 +- docs/dev/LICENSE.html | 2 +- docs/dev/SUPPORT.html | 2 +- docs/dev/articles/index.html | 2 +- docs/dev/articles/introduction.html | 2 +- docs/dev/articles/paper.html | 2 +- docs/dev/articles/parallel.html | 36 +++++++++---------- docs/dev/articles/preprocess.html | 2 +- docs/dev/articles/tuning.html | 2 +- docs/dev/authors.html | 9 +++-- docs/dev/index.html | 15 ++++---- docs/dev/news/index.html | 16 ++++++++- docs/dev/pkgdown.yml | 2 +- docs/dev/pull_request_template.html | 2 +- .../abort_packages_not_installed.html | 2 +- docs/dev/reference/bootstrap_performance.html | 30 ++++++++-------- docs/dev/reference/bounds.html | 2 +- .../reference/calc_balanced_precision.html | 2 +- .../reference/calc_baseline_precision.html | 2 +- docs/dev/reference/calc_mean_perf.html | 2 +- .../reference/calc_perf_bootstrap_split.html | 2 +- docs/dev/reference/calc_perf_metrics.html | 2 +- docs/dev/reference/calc_pvalue.html | 2 +- docs/dev/reference/change_to_num.html | 2 +- docs/dev/reference/check_all.html | 2 +- docs/dev/reference/check_cat_feats.html | 2 +- docs/dev/reference/check_corr_thresh.html | 2 +- docs/dev/reference/check_dataset.html | 2 +- docs/dev/reference/check_features.html | 2 +- .../dev/reference/check_group_partitions.html | 2 +- docs/dev/reference/check_groups.html | 2 +- docs/dev/reference/check_kfold.html | 2 +- docs/dev/reference/check_method.html | 2 +- docs/dev/reference/check_ntree.html | 2 +- docs/dev/reference/check_outcome_column.html | 2 +- docs/dev/reference/check_outcome_value.html | 2 +- .../reference/check_packages_installed.html | 2 +- .../reference/check_perf_metric_function.html | 2 +- .../dev/reference/check_perf_metric_name.html | 2 +- docs/dev/reference/check_permute.html | 2 +- docs/dev/reference/check_remove_var.html | 2 +- docs/dev/reference/check_seed.html | 2 +- docs/dev/reference/check_training_frac.html | 2 +- .../dev/reference/check_training_indices.html | 2 +- docs/dev/reference/cluster_corr_mat.html | 2 +- .../collapse_correlated_features.html | 2 +- .../dev/reference/combine_hp_performance.html | 2 +- docs/dev/reference/compare_models.html | 2 +- .../create_grouped_data_partition.html | 2 +- .../create_grouped_k_multifolds.html | 2 +- docs/dev/reference/define_cv.html | 2 +- .../reference/find_permuted_perf_metric.html | 2 +- docs/dev/reference/flatten_corr_mat.html | 2 +- docs/dev/reference/get_binary_corr_mat.html | 2 +- .../dev/reference/get_caret_dummyvars_df.html | 2 +- .../dev/reference/get_caret_processed_df.html | 2 +- docs/dev/reference/get_corr_feats.html | 2 +- docs/dev/reference/get_difference.html | 2 +- .../dev/reference/get_feature_importance.html | 2 +- .../reference/get_groups_from_clusters.html | 2 +- docs/dev/reference/get_hp_performance.html | 2 +- .../reference/get_hyperparams_from_df.html | 2 +- docs/dev/reference/get_hyperparams_list.html | 2 +- docs/dev/reference/get_outcome_type.html | 2 +- docs/dev/reference/get_partition_indices.html | 2 +- docs/dev/reference/get_perf_metric_fn.html | 8 ++--- docs/dev/reference/get_perf_metric_name.html | 2 +- docs/dev/reference/get_performance_tbl.html | 2 +- .../dev/reference/get_seeds_trainControl.html | 2 +- docs/dev/reference/get_tuning_grid.html | 2 +- .../reference/group_correlated_features.html | 2 +- docs/dev/reference/index.html | 2 +- docs/dev/reference/is_whole_number.html | 2 +- .../keep_groups_in_cv_partitions.html | 2 +- docs/dev/reference/mikropml.html | 2 +- docs/dev/reference/mutate_all_types.html | 2 +- docs/dev/reference/otu_data_preproc.html | 2 +- docs/dev/reference/otu_mini_bin.html | 2 +- .../otu_mini_bin_results_glmnet.html | 2 +- .../reference/otu_mini_bin_results_rf.html | 2 +- .../otu_mini_bin_results_rpart2.html | 2 +- .../otu_mini_bin_results_svmRadial.html | 2 +- .../otu_mini_bin_results_xgbTree.html | 2 +- .../otu_mini_cont_results_glmnet.html | 2 +- .../reference/otu_mini_cont_results_nocv.html | 2 +- docs/dev/reference/otu_mini_cv.html | 2 +- docs/dev/reference/otu_mini_multi.html | 2 +- docs/dev/reference/otu_mini_multi_group.html | 2 +- .../otu_mini_multi_results_glmnet.html | 2 +- docs/dev/reference/otu_small.html | 2 +- docs/dev/reference/pbtick.html | 2 +- docs/dev/reference/permute_p_value.html | 2 +- docs/dev/reference/plot_curves.html | 2 +- docs/dev/reference/plot_hp_performance.html | 2 +- .../dev/reference/plot_model_performance.html | 2 +- docs/dev/reference/preprocess_data.html | 2 +- docs/dev/reference/process_cat_feats.html | 2 +- docs/dev/reference/process_cont_feats.html | 2 +- docs/dev/reference/process_novar_feats.html | 2 +- docs/dev/reference/radix_sort.html | 2 +- .../reference/randomize_feature_order.html | 2 +- docs/dev/reference/reexports.html | 2 +- .../reference/remove_singleton_columns.html | 2 +- docs/dev/reference/replace_spaces.html | 2 +- docs/dev/reference/rm_missing_outcome.html | 2 +- docs/dev/reference/run_ml.html | 2 +- docs/dev/reference/select_apply.html | 2 +- docs/dev/reference/sensspec.html | 2 +- docs/dev/reference/set_hparams_glmnet.html | 2 +- docs/dev/reference/set_hparams_rf.html | 2 +- docs/dev/reference/set_hparams_rpart2.html | 2 +- docs/dev/reference/set_hparams_svmRadial.html | 2 +- docs/dev/reference/set_hparams_xgbTree.html | 2 +- docs/dev/reference/shared_ggprotos.html | 2 +- docs/dev/reference/shuffle_group.html | 2 +- .../dev/reference/split_outcome_features.html | 2 +- docs/dev/reference/tidy_perf_data.html | 2 +- docs/dev/reference/train_model.html | 2 +- docs/dev/search.json | 2 +- 121 files changed, 180 insertions(+), 164 deletions(-) diff --git a/docs/dev/CODE_OF_CONDUCT.html b/docs/dev/CODE_OF_CONDUCT.html index 4fc94a4d..1929bf63 100644 --- a/docs/dev/CODE_OF_CONDUCT.html +++ b/docs/dev/CODE_OF_CONDUCT.html @@ -10,7 +10,7 @@ mikropml - 1.5.0.9000 + 1.6.0.9000