[英]lm.ridge() in R MASS package saying “Error in svd(X) : infinite or missing values in 'x'”
I'm trying to run a ridge regression on a dataset of 8*8 pixel coordinates. 我正在尝试对8 * 8像素坐标的数据集运行岭回归。 The dataset is a map of a series of 1s and 0s written by different hands, sorted as rows of 64 numerical values corresponding to the 8*8 pixel matrix.
数据集是用不同的手书写的一系列1和0的映射,按对应于8 * 8像素矩阵的64个数值的行排序。
The lm.ridge()
function below responds to me with Error in svd(X) : infinite or missing values in 'x'
. 下面的
lm.ridge()
函数Error in svd(X) : infinite or missing values in 'x'
响应我Error in svd(X) : infinite or missing values in 'x'
。 What is the problem and what am I doing wrong? 问题出在哪里,我在做什么错?
digits = read.csv("digits.csv", header = FALSE)
library(MASS)
digits$y = rep(0,nrow(digits))
digits$y[1:554] = 1
digits$y[555:1125] = -1
lm =lm.ridge(y ~ ., digits , lambda = 1)
sample of the dataset, since I cannot figure out how to upload the csv here. 数据集的示例,因为我无法在此处弄清楚如何上传csv。
'data.frame': 1125 obs. of 65 variables:
$ V1 : int 0 0 0 0 0 0 0 0 0 0 ...
$ V2 : int 16 0 0 16 0 0 0 0 0 0 ...
$ V3 : int 96 160 240 160 32 128 112 160 32 0 ...
$ V4 : int 240 255 32 240 208 255 224 128 192 128 ...
$ V5 : int 192 96 224 128 144 128 96 176 176 192 ...
.
.
.
$ V62: int 16 48 0 0 64 80 0 0 128 144 ...
$ V63: int 0 0 0 0 0 0 0 0 0 16 ...
$ V64: int 0 0 0 0 0 0 0 0 0 0 ...
$ y : num 1 1 1 1 1 1 1 1 1 1 ...
I understand it might be related to having columns consisting of all zeroes (eg V1). 我知道这可能与包含全零的列(例如V1)有关。 I've currently removed this with summing the columns and removing the ones with zero sums, but I wonder if a) there's a cleaner way to do this and b) if this will ruin my ridge regression analysis.
我目前已通过加总列并删除总和为零的列来删除此列,但我想知道是否a)有一种更简洁的方法可以做到这一点,b)是否会破坏我的岭回归分析。
Cheers. 干杯。
From what I understood, you cannot give a column of zeros to lm.ridge()
. 据我了解,您不能为
lm.ridge()
提供零列。 the solution I implemented did not ruin the ridge regression. 我实施的解决方案并未破坏ridge回归。 I thought of a better way to implement it, by checking whether the sum of the absolute values of the columns is zero or not (
digits = digits[,which(colSums(abs(digits)) !=0)]
). 我想到了一种更好的方法,通过检查列的绝对值之和是否为零(
digits = digits[,which(colSums(abs(digits)) !=0)]
)。
Hope this helps someone. 希望这对某人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.