我尝试使用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
。