R error in glmnet: NA/NaN/Inf in foreign function call

后端 未结 3 1284
遥遥无期
遥遥无期 2021-01-08 01:23

I am trying to create a model using glmnet, (currently using cv to find the lambda value) and I am getting an error NA/NaN/Inf in foreign function call (arg 5).

相关标签:
3条回答
  • 2021-01-08 01:45

    Chars datatypes that are converted to factors cannot be supported for cv.glmnet, as stated above, can't handle NA's. Either use as.numeric or as.double.

    0 讨论(0)
  • 2021-01-08 01:50

    Addition: In case that you get this error without having NA's in your dataframe, you probably haven't defined your input matrix with the model.matrix function.

    x <- model.matrix( ~ ., Data)
    

    I know it is not the answer to your question but i had the same error as you and found this solution. So it might be helpful for others.

    0 讨论(0)
  • 2021-01-08 02:09

    It appears that glmnet cannot handle NA values!

    0 讨论(0)
提交回复
热议问题