简体   繁体   English

R cv.glmnet 错误:“需要至少两个非 NA 值进行插值”

[英]R cv.glmnet error: "need at least two non-NA values to interpolate"

I am getting an error in R when running the cv.glmnet function that I can't trace.运行无法追踪的cv.glmnet function 时,我在 R 中遇到错误。 Research only hinted me to the approx() function that throws the error when searching for lambda but I am not familiar enough with glmnet to figure out how it connects.研究只提示我approx() function 在搜索 lambda 时引发错误,但我对glmnet不够熟悉,无法弄清楚它是如何连接的。

The error is: "need at least two non-NA values to interpolate"错误是: “需要至少两个非 NA 值进行插值”

While the solution seems obvious, I am working with simulated data, so definitely no NAs in there.虽然解决方案似乎很明显,但我正在使用模拟数据,所以那里绝对没有 NA。 I double-checked multiple times.我反复检查了很多次。 I also dropped columns with constant variables in one attempt but didn't help either.我还一次尝试删除了带有常量变量的列,但也没有帮助。

Reproducible example is a bit messy due to the complexity of the data (and also not minimal since the error doesn't occur in small example data) but please see below:由于数据的复杂性,可重现的示例有点混乱(而且也不是最小的,因为错误不会发生在小示例数据中),但请参见下文:

pacman::p_load(glmnet,RCurl)

url <- getURL('https://raw.githubusercontent.com/oliverkostorz/MC-Simulation-Ensemble-Methods-Heterogeneous-Treatment-Effects/master/example.csv')
data <- read.csv(text = url)

x <- data[,3:ncol(data)]
y <- data[,2]

EN_fit <- cv.glmnet(x, y, type.measure = 'mse', alpha = .5)

Hope someone can help!希望有人能帮忙!

Best, Oliver最好的,奥利弗

9.352584e+229 is causing issues. 9.352584e+229 导致问题。 It's quite a big number.这是一个相当大的数字。

big_index <- y > 1e120
EN_fit <- cv.glmnet(as.matrix(x[!big_index, ]), y[!big_index], 
    type.measure = 'mse', alpha = .5)
EN_fit
# 
# Call:  cv.glmnet(x = as.matrix(x[!big_index, ]), y = y[!big_index],
#     type.measure = "mse", alpha = 0.5) 
# 
# Measure: Mean-Squared Error 
# 
#         Lambda Index    Measure  SE Nonzero
# min 3.864e+113    84 8.533e+229 Inf      10
# 1se 1.836e+115     1 8.644e+229 Inf       0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM