收到以下错误:
Error in xy.coords(x, y, xlabel, ylabel, log) : x' and 'y' lengths differ
当我尝试运行以下代码时。我知道它与我的x和y的长度有关。:
install.packages("e1071")
library("e1071")
mydata <- read.table("http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv", sep=";", header=TRUE);
#Go on split the data into a training and test set.
index <- 1:nrow(mydata)
testindex <- sample(index, trunc(length(index)/3))
testset( <-mydata[testindex,]
trainset <- mydata[-testindex,]
svm.model <- svm(formula = as.factor(quality) ~ residual.sugar, data = trainset, kernel = linear, method = "class")
svm.pred <- predict(svm.model, trainset, type = "class")
table(pred = svm.pred, true = trainset[,10)
plot(svm.pred, testset)
我检查了长度,我不明白为什么我的测试装置会出现12。
由于
答案 0 :(得分:0)
svm.pred
关于训练集的预测是可变的:
svm.pred <- predict(svm.model, trainset, type = "class")
然后你想绘制实际与预测的关系,但你错误地采用了测试集的实际值和预测的训练集(svm.pred
):
plot(svm.pred, testset)
这就是x,y长度不同的原因。
如果要在测试集上进行验证,则应对测试集进行预测,因此svm.pred
应为:
svm.pred <- predict(svm.model, testset, type = "class")