glmnet中的R错误:外部函数调用中的NA/NaN/Inf [英] R error in glmnet: NA/NaN/Inf in foreign function call

查看:2031
本文介绍了glmnet中的R错误:外部函数调用中的NA/NaN/Inf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用glmnet创建一个模型(当前正在使用cv查找lambda值),并且出现错误NA/NaN/Inf in foreign function call (arg 5).我相信这与我的数据集中的NA值有关,因为当我删除所有带有NA的数据点时,命令将成功运行.

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). I believe this has something to do with the NA values in my data set, because when I remove all data points with NAs the command runs successfully.

我的印象是glmnet 可以处理NA值.我不确定错误是从哪里来的:

I was under the impression that glmnet can handle NA values. I'm not sure where the error is coming from:

> res <- cv.glmnet(features.mat, as.factor(tmp[,"outcome"]), family="binomial")
Error in lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs,  : 
  NA/NaN/Inf in foreign function call (arg 5)

数据集看起来像这样:

> head(features.mat)
6 x 8 sparse Matrix of class "dgCMatrix"
   a b   c  e  f  g  h i
1  1 1 138 NA NA 15 NA .
4  1 3 171 NA NA 17 NA .
7  1 1 156 NA NA  5 NA .
8  1 4  97 NA NA  7 NA .
9  1 1 219 NA NA 11 NA .
10 1 . 263 NA NA 20 NA .
> head(as.factor(tmp[,"outcome"]))
[1] 0 0 0 0 0 0
Levels: 0 1

推荐答案

看来glmnet无法处理NA值!

It appears that glmnet cannot handle NA values!

这篇关于glmnet中的R错误:外部函数调用中的NA/NaN/Inf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆