if (FALSE) {
+# If you called `run_ml()` with `feature_importance = FALSE` (the default),
+# you can use `get_feature_importance()` later as long as you have the
+# trained model and test data.
results <- run_ml(otu_small, "glmnet", kfold = 2, cv_times = 2)
names(results$trained_model$trainingData)[1] <- "dx"
-get_feature_importance(results$trained_model,
- results$trained_model$trainingData, results$test_data,
+feat_imp <- get_feature_importance(results$trained_model,
+ results$trained_model$trainingData,
+ results$test_data,
"dx",
- multiClassSummary, "AUC",
- class_probs = TRUE, method = "glmnet"
+ multiClassSummary,
+ "AUC",
+ class_probs = TRUE,
+ method = "glmnet"
)
-# optionally, you can group features together with a custom grouping
-get_feature_importance(results$trained_model,
- results$trained_model$trainingData, results$test_data,
+# We strongly recommend providing multiple cores to speed up computation time.
+# Do this before calling `get_feature_importance()`.
+doFuture::registerDoFuture()
+future::plan(future::multicore, workers = 2)
+
+# Optionally, you can group features together with a custom grouping
+feat_imp <- get_feature_importance(results$trained_model,
+ results$trained_model$trainingData,
+ results$test_data,
"dx",
- multiClassSummary, "AUC",
- class_probs = TRUE, method = "glmnet",
+ multiClassSummary,
+ "AUC",
+ class_probs = TRUE,
+ method = "glmnet",
groups = c(
"Otu00007", "Otu00008", "Otu00009", "Otu00011", "Otu00012",
"Otu00015", "Otu00016", "Otu00018", "Otu00019", "Otu00020", "Otu00022",
@@ -212,9 +229,8 @@ Examples
)
)
-# the function can show a progress bar if you have the progressr package installed
-## optionally, specify the progress bar format
-
+# the function can show a progress bar if you have the `progressr` package installed.
+## optionally, specify the progress bar format:
progressr::handlers(progressr::handler_progress(
format = ":message :bar :percent | elapsed: :elapsed | eta: :eta",
clear = FALSE,
@@ -224,18 +240,24 @@ Examples
progressr::handlers(global = TRUE)
## run the function and watch the live progress udpates
feat_imp <- get_feature_importance(results$trained_model,
- results$trained_model$trainingData, results$test_data,
+ results$trained_model$trainingData,
+ results$test_data,
"dx",
- multiClassSummary, "AUC",
- class_probs = TRUE, method = "glmnet"
+ multiClassSummary,
+ "AUC",
+ class_probs = TRUE,
+ method = "glmnet"
)
-# you can specify any correlation method supported by `stats::cor`:
+# You can specify any correlation method supported by `stats::cor`:
feat_imp <- get_feature_importance(results$trained_model,
- results$trained_model$trainingData, results$test_data,
+ results$trained_model$trainingData,
+ results$test_data,
"dx",
- multiClassSummary, "AUC",
- class_probs = TRUE, method = "glmnet",
+ multiClassSummary,
+ "AUC",
+ class_probs = TRUE,
+ method = "glmnet",
corr_method = "pearson"
)
}
diff --git a/docs/reference/get_perf_metric_fn.html b/docs/reference/get_perf_metric_fn.html
index fbda5846..1216b07c 100644
--- a/docs/reference/get_perf_metric_fn.html
+++ b/docs/reference/get_perf_metric_fn.html
@@ -105,7 +105,7 @@ Examples
#> data$obs <- factor(data$obs, levels = lev)
#> postResample(data[, "pred"], data[, "obs"])
#> }
-#> <bytecode: 0x7fa6d7021a18>
+#> <bytecode: 0x7f80bb595430>
#> <environment: namespace:caret>
get_perf_metric_fn("binary")
#> function (data, lev = NULL, model = NULL)
@@ -163,7 +163,7 @@ Examples
#> stats <- stats[c(stat_list)]
#> return(stats)
#> }
-#> <bytecode: 0x7fa6f3348cf8>
+#> <bytecode: 0x7f80d7840cc0>
#> <environment: namespace:caret>
get_perf_metric_fn("multiclass")
#> function (data, lev = NULL, model = NULL)
@@ -221,7 +221,7 @@ Examples
#> stats <- stats[c(stat_list)]
#> return(stats)
#> }
-#> <bytecode: 0x7fa6f3348cf8>
+#> <bytecode: 0x7f80d7840cc0>
#> <environment: namespace:caret>