【发布时间】:2016-06-28 14:58:37
【问题描述】:
构建 SVM 模型
model<- svm(SeriousDlqin2yrs~., IAStrain)
predictedY <- predict(model, IAStest)
Error in names(ret2) <- rowns:
'names' attribute [2000] must be the same length as the vector [1605]
我的两个数据集(训练和测试)的数据类型:
> str(IAStest)
'data.frame': 2000 obs. of 10 variables:
$ RevolvingUtilizationOfUnsecuredLines: num 0.106 0.503 0.111 1 1 ...
$ age : int 45 46 78 78 63 33 44 65 31 41 ...
$ NumberOfTime30.59DaysPastDueNotWorse: int 0 0 0 0 0 0 0 0 0 0 ...
$ DebtRatio : num 0.2877 0.311 0.0651 0.1255 45 ...
$ MonthlyIncome: int 10000 4912 11583 12465 NA 2500 NA 18915 8200 30018 ...
$ NumberOfOpenCreditLinesAndLoans: int 5 6 8 2 4 8 4 6 9 14 ...
$ NumberOfTimes90DaysLate: int 0 0 0 0 0 0 0 0 0 0 ...
$ NumberRealEstateLoansOrLines : int 2 1 0 2 0 1 0 2 1 3 ...
$ NumberOfTime60.89DaysPastDueNotWorse: int 0 0 0 0 0 0 0 0 0 0 ...
$ NumberOfDependents : int 5 3 0 0 0 1 0 2 0 2 ...
> str(IAStrain)
'data.frame': 28000 obs. of 11 variables:
$ SeriousDlqin2yrs: Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ RevolvingUtilizationOfUnsecuredLines: num 0.957 0.658 0.907 0.213 0.306
$ age : int 40 38 49 74 57 39 27 57 30 51 ...
$ NumberOfTime30.59DaysPastDueNotWorse: int 0 1 1 0 0 0 0 0 0 0 ...
$ DebtRatio : num 1.22e-01 8.51e-02 2.49e-02 3.76e-01 5.71e+03 ...
$ MonthlyIncome : int 2600 3042 63588 3500 NA 3500 NA 23684 2500 6501 ...
$ NumberOfOpenCreditLinesAndLoans: int 4 2 7 3 8 8 2 9 5 7 ...
$ NumberOfTimes90DaysLate: int 0 1 0 0 0 0 0 0 0 0 ...
$ NumberRealEstateLoansOrLines: int 0 0 1 1 3 0 0 4 0 2 ...
$ NumberOfTime60.89DaysPastDueNotWorse: int 0 0 0 0 0 0 0 0 0 0 ...
$ NumberOfDependents: int 1 0 0 1 0 0 NA 2 0 2 ...
我已经阅读了很多关于同一问题的帖子。问题主要在于 变量的数据类型。但就我而言,这不是问题。
【问题讨论】:
-
这个问题似乎与您的测试集有关。你可以尝试减少你的测试集,这样错误仍然存在吗?例如。通过将测试集拆分为停止并在发生错误的一半继续。之后通过
dput(..)的输出,以便可以重现。另外:您使用了哪个库e1071? -
感谢您的回答。我确实将日期拆分为多个小数据框,但仍然出现相同的错误。 IAStest1
-
但是你能在你的问题出现错误的地方添加大约 5 到 10 行吗?这样我们就可以重现您的问题。
标签: r machine-learning svm