From 3be0ba2b8adb80a310a574456939c953fa02e5eb Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Tue, 28 Sep 2021 11:28:47 -0500 Subject: [PATCH 1/3] Forces test predictions to vector. It surfaces multiple test failures --- R/test-predictions.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/test-predictions.R b/R/test-predictions.R index 3fb21d6..8d198d5 100644 --- a/R/test-predictions.R +++ b/R/test-predictions.R @@ -68,12 +68,12 @@ tidypredict_test_default <- function(model, df = model$model, threshold = 0.0000 if (is.numeric(max_rows)) df <- head(df, max_rows) - base <- predict(model, df, interval = interval, type = "response") + preds <- predict(model, df, interval = interval, type = "response") if (!include_intervals) { - base <- data.frame(fit = base, row.names = NULL) + base <- data.frame(fit = as.vector(preds), row.names = NULL) } else { - base <- as.data.frame(base) + base <- as.data.frame(preds) } te <- tidypredict_to_column( From 86bd2a76d9029041dba77fd4e050c2c259ea90d0 Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Tue, 28 Sep 2021 13:32:21 -0500 Subject: [PATCH 2/3] Switches between GLM and non-GLM coefs for earth models --- R/model-earth.R | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/R/model-earth.R b/R/model-earth.R index 930f13a..b8ec292 100644 --- a/R/model-earth.R +++ b/R/model-earth.R @@ -14,10 +14,7 @@ parse_model.earth <- function(model) { } is_glm <- !is.null(model$glm.list) - - all_coefs <- model$coefficients - if (is_glm) all_coefs <- model$glm.coefficients - + pm <- list() pm$general$model <- "earth" pm$general$type <- "tree" @@ -29,12 +26,12 @@ parse_model.earth <- function(model) { pm$general$family <- fam$family pm$general$link <- fam$link } - pm$terms <- mars_terms(model) + pm$terms <- mars_terms(model, is_glm) as_parsed_model(pm) } -mars_terms <- function(mod) { +mars_terms <- function(mod, is_glm) { feature_types <- tibble::as_tibble(mod$dirs, rownames = "feature") %>% dplyr::mutate(feature_num = dplyr::row_number()) %>% @@ -48,9 +45,16 @@ mars_terms <- function(mod) { tidyr::pivot_longer(cols = c(-feature, -feature_num), values_to = "value", names_to = "term") + + if (is_glm) { + all_coefs <- mod$glm.coefficients + } else { + all_coefs <- mod$coefficients + } + feature_coefs <- # Note coef(mod) formats data differently for logistic regression - tibble::as_tibble(mod$coefficients, rownames = "feature") %>% + tibble::as_tibble(all_coefs, rownames = "feature") %>% setNames(c("feature", "coefficient")) term_to_column <- From eeeddd6292e907478ef05ef2dfec76ade6665675 Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Tue, 28 Sep 2021 13:36:30 -0500 Subject: [PATCH 3/3] Updates NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index e856fb2..45b5532 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # tidypredict (development version) +- Fixes issue handling GLM Binomial earth models (#97) + - Adds capability to handle single simple Cubist models (#57) - Fixed parenthesis issue in the creation of the interval formula (#76)