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

Error in py_call_impl: not enough values to unpack #37

Closed
frmunoz opened this issue May 8, 2020 · 7 comments
Closed

Error in py_call_impl: not enough values to unpack #37

frmunoz opened this issue May 8, 2020 · 7 comments

Comments

@frmunoz
Copy link

frmunoz commented May 8, 2020

I have the following error with sjSDM function,

Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: not enough values to unpack (expected 2, got 1)

Any idea on what could be the cause?

@MaximilianPi
Copy link
Member

Hi François,
I cannot pinpoint the cause of this error, could please provide more information? Can you create a minimal example when this is happening, or at least the code of your analysis?

@frmunoz
Copy link
Author

frmunoz commented May 8, 2020

Here we go:

model = sjSDM(train_X.samp, train_Y.samp, learning_rate = 0.01, iter = 50L, 
                biotic = bioticStruct(df = 10),
                step_size = 20, #as.integer(nrow(train_X)*0.1),
                device = "gpu") #cpu

for debug.zip

@MaximilianPi
Copy link
Member

Thanks, I found two issues:

  1. data formats: train_Y.samp was a table -> as.matrix , train_X.samp had also a weird format, class says it is a data.frame but only with data.frame(train_X.samp) it worked
  2. There are NA's in train_X.samp, model.frame removes them but the corresponding rows in Y are not removed

This works (I also switched X and Y because I assume that Y is your occurrence matrix:

library(sjSDM)
model = sjSDM(as.matrix(train_Y.samp), train_X.samp, learning_rate = 0.01, iter = 50L, 
              biotic = bioticStruct(df = 10),
              step_size = 20, #as.integer(nrow(train_X)*0.1),
              device = "cpu") #cpu

#This works:

no_na = complete.cases(data.frame(train_X.samp))
model = sjSDM(as.matrix(train_Y.samp)[no_na, ], data.frame(train_X.samp)[no_na, ], learning_rate = 0.01, iter = 50L, 
              biotic = bioticStruct(df = 10),
              step_size = 2, #as.integer(nrow(train_X)*0.1),
              device = "cpu") #cpu

reminder for me:

  • record NAs in linear and remove the rows in Y
  • check data types

@frmunoz
Copy link
Author

frmunoz commented May 8, 2020

Thank you !
Does it mean that the function cannot manage predictors with different types (e.g., numeric and categorical)?

@MaximilianPi
Copy link
Member

No, it can handle all types. The difference to lm/glm is that they manage the data in one dataset (formula = y~temp + treatment, data = forest_data) and therefore rows with nas are removed in the predictors (tmp, treatment) and the response (y).
However, the model.frame does not support multiple responses (Y1+Y2), that is why sjSDM users have to provide an env object (env = matrix or linear(data=env, formula = ~temp + treatment) and the response (occ=matrix with Y1, Y2) separately. If there are now nas in temp or treatment, those rows are removed only in the predictors but not in the response (occ/Y).

By the way if you want to see how the model.frame parses your formula/predictors:

no_na = complete.cases(data.frame(train_X.samp))

env = linear(data = data.frame(train_X.samp)[no_na, ], formula = ~.) # which is equivalent to env = data.frame(train_X.samp)[no_na, ]
print(env$x)

model = sjSDM(as.matrix(train_Y.samp)[no_na, ], env = env, learning_rate = 0.01, iter = 50L, 
              biotic = bioticStruct(df = 10),
              step_size = 2, #as.integer(nrow(train_X)*0.1),
              device = "cpu") #cpu

@frmunoz
Copy link
Author

frmunoz commented May 8, 2020

Ok, noted, thank you for your help Max. :-)

@MaximilianPi
Copy link
Member

No problem, quite the opposite. I have to thank you, you reveal a lot of weaknesses/bugs in the pkg ^^

Close for now, but the na and data format checker have to be implemented #35

@MaximilianPi MaximilianPi mentioned this issue May 8, 2020
11 tasks
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