-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Shapley Value option #52
Comments
' rfModel.shap <- function(estimator,
Estimate modelmod_df <- rf_df[, unique(c(list(...)$ind_var, 'trans_period', 'price'))] regr.task = makeRegrTask(id = "aa", data = mod_df, target = "price") shap_df <- mod_df %>% shapvalue_df <- shapleyR::getShapleyValues( rf_model$coefficients <- data.frame(time = 1:max(rf_df$trans_period)) %>% a <- as.data.frame(cbind(X$trans_period[kk], x$trans_period))# Add 'coefficients'log_dep <- ifelse(grepl('log', rf_spec[2]), TRUE, FALSE)if(log_dep){coefs <- pdp_df$yhat - pdp_df$yhat[1]} else {coefs <- pdp_df$yhat / pdp_df$yhat[1]}rf_model$coefficients <- data.frame(time = 1:max(rf_df$trans_period),coefficient = coefs)Structure and returnstructure(rf_model, class = c('rfmodel', class(rf_model))) } #' rfModel.sim <- function(estimator, set.seed(seed) Estimate modelrf_model <- ranger::ranger(rf_spec, Add classclass(rf_model) <- c('rfmodel', class(rf_model)) log_dep <- ifelse(grepl('log', rf_spec[2]), TRUE, FALSE) rfSimulate(rf_obj = rf_model, #' rfSimulate <- function(rf_obj, if no count of simulation is givenif (is.null(sim_count)) sim_count <- floor(sim_per * nrow(rf_df)) Get simulation observationsset.seed(seed) Calculate individual price movementssim_coefs <- purrr::map(.x = sim_df %>% split(., sim_df$trans_id), rf_obj$coefficients <- data.frame(time = 1:max(rf_df$trans_period), rf_obj } #' rfSim <- function(rf_obj, new_data <- sim_df[rep(1,length(periods)), ] %>% pred <- stats::predict(rf_obj, new_data)$prediction } |
Re-add the shapley value option. See
forest
branch prior to 84fc71dThe text was updated successfully, but these errors were encountered: