【发布时间】:2019-09-22 03:41:49
【问题描述】:
我正在尝试使用支持向量机来预测一系列值,例如:
输入 0、1、2、3 将预测 4
出于这个原因,我将此问题视为 R 中的回归 ML 问题,这是我的代码:
library("e1071")
x0 <- c(0)
x1 <- c(0, 1)
x2 <- c(0, 1, 2)
x3 <- c(0, 1, 2, 3)
x4 <- c(0, 1, 2, 3, 4)
x5 <- c(0, 1, 2, 3, 4, 5)
x6 <- c(0, 1, 2, 3, 4, 5, 6)
x7 <- c(0, 1, 2, 3, 4, 5, 6, 7)
x = c(x0, x1, x2, x3, x4, x5, x6, x7)
y = c(1, 2, 3, 4, 5, 6, 7, 8)
df = data.frame(x, y)
df
svmfit = svm(y ~ ., data = df)
print(svmfit)
目前我陷入了如何正确创建输入序列的问题,并且一直收到此错误:
data.frame(x, y) 中的错误:参数暗示不同的行数: 36、8回溯:
- data.frame(x, y)
- stop(gettextf("参数暗示不同的行数:%s", .paste(unique(nrows), collapse = ", ")), domain = NA)
谁能帮帮我?
提前非常感谢!
【问题讨论】:
-
请检查你的
df <- data.frame(x, y)length(x)是8,'y'是36,不是回收。可能你需要明确使用rep即df <- data.frame(x, y = rep(y, length.out = length(x)))
标签: r dataframe machine-learning plot svm