gpt4 book ai didi

r - 名称错误(ret2) <- rowns : 'names' attribute [2000] must be the same length as the vector [1605]

转载 作者:行者123 更新时间:2023-11-30 08:52:24 24 4
gpt4 key购买 nike

构建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 ...

我读过很多关于同一类问题的帖子。问题主要在于变量的数据类型。但就我而言,这不是问题。

最佳答案

除了我的评论之外,您的数据中的NA很可能是问题所在

predictedY <- predict(model, IAStest[!rowSums(is.na(IAStest)),])

应该为不包含NA值的行生成结果

关于r - 名称错误(ret2) <- rowns : 'names' attribute [2000] must be the same length as the vector [1605],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35972845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com