【问题标题】:"Error in xy.coords(x, y, xlabel, ylabel, log) : x' and 'y' lengths differ" for SVM支持向量机的“xy.coords(x, y, xlabel, ylabel, log) 中的错误:x' 和 'y' 长度不同”
【发布时间】:2015-03-23 15:35:14
【问题描述】:

得到以下错误:

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。

谢谢

【问题讨论】:

  • testset( &lt;-mydata[testindex,]testset后面有个括号
  • 大声笑我把它放进去的错误,但这与原来的问题无关。错误仍然存​​在。

标签: r plot svm


【解决方案1】:

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")

【讨论】:

    猜你喜欢
    • 2021-07-05
    • 1970-01-01
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 2021-08-18
    相关资源
    最近更新 更多