简体   繁体   English

R - svd()函数 - 'x'中的无限或缺失值

[英]R - svd() function - infinite or missing values in 'x'

I am constantly getting this error. 我经常遇到这个错误。 I am sure the matrix does not have any non-numeric entries. 我确信矩阵没有任何非数字条目。 I also tried imputing the matrix, did not work. 我也尝试过输入矩阵,没用。

Anyone know what the error might be? 任何人都知道错误可能是什么?

fileUrl <- "https://dl.dropboxusercontent.com/u/76668273/kdd.csv";
download.file(fileUrl,destfile="./kdd.csv",method="curl");
kddtrain <- read.csv("kdd.csv");
kddnumeric <- kddtrain[,sapply(kddtrain,is.numeric)];
kddmatrix <- as.matrix(kddnumeric);
svd1 <- svd(scale(kddmatrix));

You have columns composed of all zeroes. 您有由全零组成的列。 Using scale on a column of all zeroes returns a column composed of NaN . 在全零的列上使用scale返回由NaN组成的列。 To solve this, remove columns where you have all zeroes ( svd will not reveal anything new about them), or replace NaN columns with zero after using scale . 要解决此问题,请删除全部为零的列( svd不会显示任何有关它们的新内容),或者在使用scale后将NaN列替换为零。

Reproducible example: 可重复的例子:

mat <- matrix(c(1,2,3,0,0,0,2,4,6,5,12,13),nrow = 3)
     # [,1] [,2] [,3] [,4]
# [1,]    1    0    2    5
# [2,]    2    0    4   12
# [3,]    3    0    6   13
scale(mat)
     # [,1] [,2] [,3]       [,4]
# [1,]   -1  NaN   -1 -1.1470787
# [2,]    0  NaN    0  0.4588315
# [3,]    1  NaN    1  0.6882472
# attr(,"scaled:center")
# [1]  2  0  4 10
# attr(,"scaled:scale")
# [1] 1.000000 0.000000 2.000000 4.358899
svd(mat) #fine
svd(scale(mat)) # not fine

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

相关问题 R:采样:校准函数:svd(X)中的错误:“ x”中的值无穷或缺失 - R: Sampling: Calib function: Error in svd(X) : infinite or missing values in 'x' 计算R错误中的SVD:缺失值或无限值 - Calculate SVD in R error: missing or infinite values R 中的 PCA:svd(x,nu=0,nv=k)中的错误:“x”中的值无限或缺失 - PCA in R: Error in svd(x, nu=0, nv=k) : Infinite or missing values in 'x' R MASS软件包中的lm.ridge()说“ svd(X)中的错误:&#39;x&#39;中的值无穷或缺失” - lm.ridge() in R MASS package saying “Error in svd(X) : infinite or missing values in 'x'” R中缺少值的SVD - SVD with missing values in R R-&#39;x&#39;中的无穷或缺失值 - R - Infinite or missing values in 'x' svd(x, nu = 0, nv = k) 中的错误:“x”中的值无限或缺失。 矩阵中没有 NA 或 Inf 值 - Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'. There are no NA or Inf values in matrix svd(x,nu = 0)中的错误:&#39;x&#39;中的值无限或缺失(检查是否存在负值) - Error in svd(x, nu = 0) : infinite or missing values in 'x' (checked no negative values exist) svd(X)中的错误:&#39;x&#39;中的值无穷或缺失。 在GAS中使用BacktestVaR时 - Error in svd(X) : infinite or missing values in 'x' . when using BacktestVaR in GAS R- prcomp() 的“x”中的无限或缺失值 - R- infinite or missing values in 'x' for prcomp()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM