Skip to content

Commit

Permalink
Merge pull request #310 from SchlossLab/feat-imp
Browse files Browse the repository at this point in the history
Show example feature importance plot
  • Loading branch information
kelly-sovacool committed Nov 4, 2022
2 parents 42d4298 + cee4cd7 commit 5b2cc3a
Show file tree
Hide file tree
Showing 26 changed files with 1,062 additions and 301 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# mikropml development version

- Created an example showing how to plot feature importances in the `parallel` vignette (#310, @kelly-sovacool).
- You can now use `parRF`, a parallel implementation of the `rf` method, with
the same default hyperparameters as `rf` set automatically.
the same default hyperparameters as `rf` set automatically (#306, @kelly-sovacool).

# mikropml 1.4.0

Expand Down
5 changes: 2 additions & 3 deletions R/feature_importance.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#' Calculates feature importance using a trained model and test data. Requires
#' the `future.apply` package.
#'
#' @param train_data Training data: dataframe of outcome and features.
#' @inheritParams run_ml
#' @inheritParams calc_perf_metrics
#' @inheritParams group_correlated_features
Expand Down Expand Up @@ -121,15 +120,15 @@
#' @author Begüm Topçuoğlu, \email{topcuoglu.begum@@gmail.com}
#' @author Zena Lapp, \email{zenalapp@@umich.edu}
#' @author Kelly Sovacool, \email{sovacool@@umich.edu}
get_feature_importance <- function(trained_model, train_data, test_data,
get_feature_importance <- function(trained_model, test_data,
outcome_colname, perf_metric_function,
perf_metric_name, class_probs, method,
seed = NA, corr_thresh = 1, groups = NULL,
nperms = 100, corr_method = "spearman") {
abort_packages_not_installed("future.apply")

# get outcome and features
split_dat <- split_outcome_features(train_data, outcome_colname)
split_dat <- split_outcome_features(test_data, outcome_colname)
outcome <- split_dat$outcome
features <- split_dat$features

Expand Down
1 change: 0 additions & 1 deletion R/run_ml.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ run_ml <-
message("Finding feature importance...")
feature_importance_tbl <- get_feature_importance(
trained_model_caret,
train_data,
test_data,
outcome_colname,
perf_metric_function,
Expand Down
3 changes: 2 additions & 1 deletion R/train_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ train_model <- function(train_data,
...
)
} else {
features_train <- train_data %>% dplyr::select(-outcome_colname)
features_train <- train_data %>%
dplyr::select(-dplyr::all_of(outcome_colname))
outcomes_train <-
train_data %>% dplyr::pull(outcome_colname)
if (is.character(outcomes_train)) {
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ mamba install -c conda-forge r-mikropml

### Dependencies

- Imports: caret, dplyr, e1071, glmnet, kernlab, MLmetrics,
randomForest, rlang, rpart, stats, utils, xgboost
- Suggests: doFuture, foreach, future, future.apply, ggplot2, knitr,
progress, progressr, purrr, rmarkdown, testthat, tidyr
- Imports: caret, dplyr, e1071, glmnet, kernlab, MLmetrics,
randomForest, rlang, rpart, stats, utils, xgboost
- Suggests: doFuture, foreach, future, future.apply, ggplot2, knitr,
progress, progressr, purrr, rmarkdown, testthat, tidyr

## Usage

Expand Down
9 changes: 5 additions & 4 deletions docs/dev/CODE_OF_CONDUCT.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/dev/CONTRIBUTING.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/dev/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/dev/SUPPORT.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b2cc3a

Please sign in to comment.