Skip to content
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

Help: Error in yhats[[which.min(yhats_diff)]] #29

Open
Margarida-F opened this issue Dec 6, 2019 · 6 comments
Open

Help: Error in yhats[[which.min(yhats_diff)]] #29

Margarida-F opened this issue Dec 6, 2019 · 6 comments

Comments

@Margarida-F
Copy link

Hi !

Can I have help to fix the error below?

Error in yhats[[which.min(yhats_diff)]] :
attempt to select less than one element in get1index

I only code this:

contribution <- broken(model = model, new_observation = df[1,features], data = train[,features])

and my model is a randomForest.

It seems that is trying to access to the zero position, and it doesn't exist.

Thanks, Margarida

@pbiecek
Copy link
Owner

pbiecek commented Dec 6, 2019

Do you have a reproducible example that produces this error?
And please try the iBreakDown package (https://github.com/ModelOriented/iBreakDown) with break_down) function, it's a newer version so maybe this problem is already solved there

@Margarida-F
Copy link
Author

First of all, thanks for you answer.

I suppose I can't show the data but I guarantee the variables are all right.
However, maybe the problem is the model...

I try this:

contribution <- break_down(model, new_observation = df[1,features], data = train[,features])
Error in colMeans(yhatpred) : 'x' must be numeric

And then, tried construct explainer first:

explainer <- explain(model,data=train[,features],y=train$Y)
Error in UseMethod("explain") :
no applicable method for 'explain' applied to an object of class "c('randomForest.formula', 'randomForest')"

My model is like:
model

Can you help me, please?

Thank you, very much ,
Margarida

@pbiecek
Copy link
Owner

pbiecek commented Dec 7, 2019

Can you share devtools::session_info()?
It is hard to suggest anything without knowing on which versions of DALEX/breakDown you are working.
Try latest versions DALEX & iBreakDown from CRAN.

If this is not enough then try to change thy y variable from factor to numeric
(as Y == "1")

@Margarida-F
Copy link
Author

Hi, again. Thank you very much you're trying to help me.

My Session Information is:

  • Session info -----------------------------------------------------------------------------------------------------------------
    setting value
    version R version 3.5.2 (2018-12-20)
    os Windows >= 8 x64
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate Portuguese_Portugal.1252
    ctype Portuguese_Portugal.1252
    tz Europe/London
    date 2019-12-09

  • Packages ---------------------------------------------------------------------------------------------------------------------
    package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.3)
    backports 1.1.5 2019-10-02 [1] CRAN (R 3.5.3)
    callr 3.3.2 2019-09-22 [1] CRAN (R 3.5.3)
    caret * 6.0-84 2019-04-27 [1] CRAN (R 3.5.3)
    class 7.3-14 2015-08-30 [2] CRAN (R 3.5.2)
    cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.3)
    codetools 0.2-15 2016-10-05 [2] CRAN (R 3.5.2)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.5.3)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.3)
    DALEX 0.4.9 2019-10-24 [1] CRAN (R 3.5.3)
    data.table * 1.12.2 2019-04-07 [1] CRAN (R 3.5.3)
    DBI 1.0.0 2018-05-02 [1] CRAN (R 3.5.3)
    dbplyr * 1.4.2 2019-06-17 [1] CRAN (R 3.5.3)
    desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.3)
    devtools 2.2.1 2019-09-24 [1] CRAN (R 3.5.2)
    digest 0.6.23 2019-11-23 [1] CRAN (R 3.5.3)
    dplyr * 0.8.3 2019-07-04 [1] CRAN (R 3.5.3)
    ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.5.3)
    foreach 1.4.7 2019-07-27 [1] CRAN (R 3.5.3)
    fs 1.3.1 2019-05-06 [1] CRAN (R 3.5.3)
    generics 0.0.2 2018-11-29 [1] CRAN (R 3.5.3)
    ggplot2 * 3.2.1 2019-08-10 [1] CRAN (R 3.5.3)
    glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.3)
    gower 0.2.1 2019-05-14 [1] CRAN (R 3.5.3)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 3.5.3)
    iBreakDown 0.9.9 2019-08-26 [1] CRAN (R 3.5.3)
    ipred 0.9-9 2019-04-28 [1] CRAN (R 3.5.3)
    iterators 1.0.12 2019-07-26 [1] CRAN (R 3.5.3)
    lattice * 0.20-38 2018-11-04 [2] CRAN (R 3.5.2)
    lava 1.6.6 2019-08-01 [1] CRAN (R 3.5.3)
    lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.5.3)
    lubridate * 1.7.4 2018-04-11 [1] CRAN (R 3.5.3)
    magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.3)
    MASS 7.3-51.1 2018-11-01 [2] CRAN (R 3.5.2)
    Matrix 1.2-15 2018-11-01 [2] CRAN (R 3.5.2)
    memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.3)
    ModelMetrics 1.2.2 2018-11-03 [1] CRAN (R 3.5.3)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.3)
    nlme 3.1-137 2018-04-07 [2] CRAN (R 3.5.2)
    nnet 7.3-12 2016-02-02 [2] CRAN (R 3.5.2)
    pillar 1.4.2 2019-06-29 [1] CRAN (R 3.5.3)
    pkgbuild 1.0.5 2019-08-26 [1] CRAN (R 3.5.3)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.5.3)
    pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.3)
    plyr 1.8.4 2016-06-08 [1] CRAN (R 3.5.3)
    prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.3)
    processx 3.4.1 2019-07-18 [1] CRAN (R 3.5.3)
    prodlim 2018.04.18 2018-04-18 [1] CRAN (R 3.5.3)
    ps 1.3.0 2018-12-21 [1] CRAN (R 3.5.3)
    purrr 0.3.2 2019-03-15 [1] CRAN (R 3.5.3)
    R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.3)
    randomForest * 4.6-14 2018-03-25 [1] CRAN (R 3.5.3)
    Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.5.3)
    recipes 0.1.7 2019-09-15 [1] CRAN (R 3.5.2)
    remotes 2.1.0 2019-06-24 [1] CRAN (R 3.5.3)
    reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.5.3)
    rlang 0.4.1 2019-10-24 [1] CRAN (R 3.5.3)
    rpart 4.1-13 2018-02-23 [2] CRAN (R 3.5.2)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.3)
    rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.5.2)
    scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.3)
    sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.3)
    stringi 1.4.3 2019-03-12 [1] CRAN (R 3.5.3)
    stringr 1.4.0 2019-02-10 [1] CRAN (R 3.5.3)
    survival 2.43-3 2018-11-26 [2] CRAN (R 3.5.2)
    testthat 2.2.1 2019-07-25 [1] CRAN (R 3.5.3)
    tibble 2.1.3 2019-06-06 [1] CRAN (R 3.5.3)
    tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.5.3)
    timeDate 3043.102 2018-02-21 [1] CRAN (R 3.5.3)
    usethis 1.5.1 2019-07-04 [1] CRAN (R 3.5.3)
    withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.3)
    yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.3)

[1] C:/Users/Margarida Ferreira/Documents/R/win-library/3.5
[2] C:/Program Files/R/R-3.5.2/library

Change Y to numeric doesn't works because Y isn't an argument of break_down().

Should I download the code and run each code block to debug?

Thanks for everything,
Margarida

@Margarida-F
Copy link
Author

Hi, again.

Just to close this issue:

I'm now using some code of iBreakDown. It's normal that it take too long (around 8 minutes) to calculate contributions of 13 variables and 1 row?

Thanks very much. I promise I close this issue before your answer.

Margarida

@pbiecek
Copy link
Owner

pbiecek commented Dec 19, 2019

Hi,
busy time ar university, sorry for late response.

iBreakDown is much faster than breakDown.
For FIFA data (200k cases, ~100 variables) calculation of break down is below a minute, do for 13 variables it shall be seconds at most.

Here you will find how to use the most recent version of iBreakDown
https://pbiecek.github.io/PM_VEE/breakDown.html#BDR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants