我正在尝试使用 Titanic Kaggle 数据集在 R 中完成对 SVM 模型的调整。
当我运行以下代码时:
tune.out = tune(svm, Survived ~ Pclass + Sex + Age + Fare + Embarked + family,
data = boat, kernel = "linear",
ranges = list(cost = c(0.001, 0.01, 0.1, 1, 5, 10, 100)))
我得到错误:
Error in names(ret2) <- rowns :
'names' attribute [90] must be the same length as the vector [71]
使用回溯:
3: predict.svm(model, if (!is.null(validation.x)) validation.x else if (useFormula) data[-train.ind[[sample]],
, drop = FALSE] else if (inherits(train.x, "matrix.csr")) train.x[-train.ind[[sample]],
] else train.x[-train.ind[[sample]], , drop = FALSE])
2: predict.func(model, if (!is.null(validation.x)) validation.x else if (useFormula) data[-train.ind[[sample]],
, drop = FALSE] else if (inherits(train.x, "matrix.csr")) train.x[-train.ind[[sample]],
] else train.x[-train.ind[[sample]], , drop = FALSE])
1: tune(svm, Survived ~ Pclass + Sex + Age + Fare + Embarked + family,
data = boat, kernel = "linear", ranges = list(cost = c(0.001,
0.01, 0.1, 1, 5, 10, 100)))
我知道我的变量可能有问题 - 有没有想过这可能是什么?
如果有帮助,我没有修改任何变量,但删除了一堆(在调整公式中没有看到并通过以下方式创建了一个新变量family
:
boat$family = boat$SibSp + boat$Parch
boat$family[boat$family > 0] = 1
船是一个data.table
。