Skip to content

wrong structure for logistic regression confidence intervals #156

@topepo

Description

@topepo
library(tidymodels)
#> ── Attaching packages ───────────────────────────────────────────────────────────────── tidymodels 0.0.2 ──
#> ✔ broom     0.5.1          ✔ purrr     0.3.0     
#> ✔ dials     0.0.2          ✔ recipes   0.1.4     
#> ✔ dplyr     0.8.0.1        ✔ rsample   0.0.4     
#> ✔ ggplot2   3.1.0          ✔ tibble    2.0.1     
#> ✔ infer     0.4.0          ✔ yardstick 0.0.2     
#> ✔ parsnip   0.0.1.9000
#> ── Conflicts ──────────────────────────────────────────────────────────────────── tidymodels_conflicts() ──
#> ✖ purrr::discard() masks scales::discard()
#> ✖ dplyr::filter()  masks stats::filter()
#> ✖ dplyr::lag()     masks stats::lag()
#> ✖ recipes::step()  masks stats::step()

data("lending_club")

lending_club <-
  lending_club %>%
  slice(1:200) 

log_reg <-
  logistic_reg() %>%
  set_engine("glm") %>%
  fit(Class ~ log(funded_amnt) + int_rate, data = lending_club)

predict(log_reg, lending_club %>% slice(1:7) %>% dplyr::select(-Class), type = "prob")
#> # A tibble: 7 x 2
#>   .pred_bad .pred_good
#>       <dbl>      <dbl>
#> 1   0.0511       0.949
#> 2   0.0706       0.929
#> 3   0.0500       0.950
#> 4   0.0499       0.950
#> 5   0.00185      0.998
#> 6   0.0166       0.983
#> 7   0.00441      0.996

predict(log_reg, lending_club %>% slice(1:7) %>% dplyr::select(-Class), type = "conf_int")
#> # A tibble: 7 x 2
#>   .pred_lower .pred_upper
#>         <dbl>       <dbl>
#> 1       0.896       0.976
#> 2       0.813       0.975
#> 3       0.883       0.980
#> 4       0.897       0.976
#> 5       0.975       1.000
#> 6       0.944       0.995
#> 7       0.971       0.999

Created on 2019-02-25 by the reprex package (v0.2.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions