我正在尝试使用此数据框构建分类模型:
str(aa)
'data.frame': 49 obs. of 967 variables:
$ Lunes : num 0.1 0.14 0.19 0.15 0.14 0.12 0.19 0.15 0.15 0.15 ...
$ Martes : num 0.15 0.16 0.21 0.17 0.15 0.14 0.2 0.13 0.16 0.15 ...
$ Miercoles : num 0.15 0.16 0.17 0.17 0.16 0.16 0.17 0.13 0.16 0.14 ...
$ Jueves : num 0.15 0.13 0.12 0.13 0.12 0.13 0.14 0.09 0.13 0.13 ...
$ Viernes : num 0.2 0.13 0.16 0.13 0.13 0.13 0.14 0.13 0.16 0.12 ...
$ Sabado : num 0.13 0.15 0.1 0.13 0.16 0.17 0.1 0.16 0.13 0.18 ...
$ Domingo : num 0.12 0.12 0.05 0.12 0.14 0.15 0.05 NA 0.11 0.13 ...
$ CODNUEVZON : int 7001 35801 24402 NA 17203 37102 24403 38402 60201 10404 ...
$ POBLA : int 363 4282 2090 NA 1477 32797 1694 17440 0 11045 ...
$ BANCO.BOLIVARIANO : int 1 1 1 NA 1 1 2 0 1 1 ...
$ BANCO.DE.LOJA : int 0 0 0 NA 1 0 0 0 0 0 ...
$ BANCO.DELBANK : int 0 0 0 NA 0 0 0 0 0 0 ...
$ BANCO.DESARROLLO : int 0 0 0 NA 0 0 0 0 0 0 ...
$ BANCO.GUAYAQUIL : int 0 3 0 NA 3 1 1 4 2 1 ...
$ BANCO.INTERNACIONAL : int 0 4 1 NA 1 1 8 0 0 1 ...
$ BANCO.PICHINCHA : int 0 8 5 NA 14 1 4 13 7 0 ...
$ BANCO.PROCREDIT : int 0 0 0 NA 3 0 0 0 0 0 ...
$ BANCO.PRODUBANCO : int 0 6 0 NA 6 1 1 2 0 0 ...
$ BANCO.SOLIDARIO : int 0 1 0 NA 2 0 0 0 0 0 ...
$ BANRED : int 0 0 0 NA 0 0 0 0 0 0 ...
$ COOP..29.DE.OCTUBRE : int 0 1 0 NA 1 0 0 0 0 0 ...
$ COOP..ALIANZA.DEL.VALLE : int 0 0 1 NA 0 0 0 0 0 0 ...
$ COOP..AMBATO : int 0 0 0 NA 0 0 0 0 0 0 ...
$ COOP..J.E.P : int 0 0 0 NA 0 0 0 0 0 0 ...
$ COOP..OSCUS : int 0 0 0 NA 1 0 0 0 0 0 ...
$ COOP..POLICIA.NACIONAL : int 0 0 0 NA 1 0 1 0 0 0 ...
$ MUTUALISTA.PICHINCHA : int 0 1 0 NA 2 0 1 0 1 0 ...
$ RED.TRANSACCIONAL.COONECTA : int 1 1 0 NA 0 0 1 1 0 0 ...
$ TotalATM : int 2 26 8 NA 36 5 19 20 11 3 ...
$ Tiendas : int 18 14 17 NA 9 88 18 58 41 48 ...
$ advertising : int 0 0 0 NA 0 0 0 0 1 0 ...
$ animal_boarding : int 0 0 0 NA 0 0 0 0 0 0 ...
$ arts_centre : int 0 0 0 NA 0 0 0 0 0 0 ...
$ atm : int 0 0 2 NA 0 3 6 3 0 0 ...
$ bank : int 0 11 2 NA 1 0 8 7 4 0 ...
$ bar : int 2 0 1 NA 0 1 1 0 0 5 ...
$ bbq : int 0 0 0 NA 0 0 0 0 0 0 ...
$ bench : int 0 0 0 NA 1 0 1 0 0 0 ...
$ bicycle_parking : int 0 0 0 NA 0 0 3 0 0 0 ...
$ bicycle_rental : int 0 0 0 NA 0 0 1 0 0 0 ...
$ bicycle_repair_station : int 0 0 0 NA 0 0 0 0 0 0 ...
$ biergarten : int 0 0 0 NA 0 0 0 0 0 0 ...
$ bureau_de_change : int 0 0 0 NA 0 0 0 0 0 0 ...
$ bus_station : int 0 0 0 NA 0 0 2 0 0 0 ...
$ cafe : int 2 7 2 NA 0 4 11 0 8 1 ...
$ cafe.ice_cream : int 0 0 0 NA 0 0 0 0 0 0 ...
$ car_rental : int 0 0 0 NA 0 0 0 0 0 0 ...
$ car_wash : int 0 1 0 NA 0 0 1 0 1 0 ...
$ charging_station : int 0 0 0 NA 0 0 0 0 0 0 ...
$ childcare : int 0 0 0 NA 0 0 0 0 0 0 ...
$ cinema : int 0 1 0 NA 1 0 0 0 3 0 ...
$ clinic : int 2 0 0 NA 0 0 1 0 2 3 ...
$ college : int 0 0 1 NA 0 0 4 0 0 0 ...
$ community_centre : int 1 0 0 NA 0 0 0 0 0 0 ...
$ computer : int 0 0 0 NA 0 0 0 0 0 0 ...
$ courthouse : int 0 0 0 NA 0 0 0 0 0 0 ...
$ coworking_space : int 0 0 1 NA 0 0 0 0 0 0 ...
$ dancing_school : int 0 0 1 NA 0 0 0 0 0 0 ...
$ dentist : int 1 2 2 NA 0 7 0 4 2 5 ...
$ doctors : int 2 1 1 NA 1 1 0 1 0 0 ...
$ dojo : int 0 0 0 NA 0 0 0 0 1 1 ...
$ drinking_water : int 1 0 0 NA 0 0 0 0 0 0 ...
$ driving_school : int 0 0 0 NA 0 0 0 0 0 0 ...
$ embassy : int 0 0 1 NA 0 0 0 0 0 0 ...
$ fast_food : int 4 0 3 NA 1 1 1 0 4 8 ...
$ fire_station : int 0 0 0 NA 0 0 0 0 0 0 ...
$ food_court : int 0 0 0 NA 0 0 0 0 0 0 ...
$ fountain : int 0 0 0 NA 0 0 0 0 0 0 ...
$ fuel : int 0 0 0 NA 0 0 0 0 2 0 ...
$ grave_yard : int 0 0 0 NA 0 0 0 0 1 0 ...
$ hospital : int 0 0 0 NA 2 1 0 2 0 0 ...
$ hunting_stand : int 0 0 0 NA 0 0 0 0 0 0 ...
$ ice_cream : int 0 0 0 NA 0 0 0 0 1 0 ...
$ internet : int 0 0 0 NA 0 0 0 0 0 0 ...
$ internet_cafe : int 1 0 0 NA 0 3 1 1 0 0 ...
$ kindergarten : int 0 0 0 NA 0 0 0 0 0 0 ...
$ language_school : int 0 0 0 NA 0 0 0 0 0 0 ...
$ library : int 0 0 0 NA 0 0 1 0 1 0 ...
$ marketplace : int 0 0 0 NA 0 0 0 1 0 0 ...
$ money_transfer : int 0 0 0 NA 0 0 0 0 0 0 ...
$ music_school : int 0 0 0 NA 0 0 0 0 0 0 ...
$ nightclub : int 0 0 1 NA 0 0 0 0 0 0 ...
$ parking : int 0 0 1 NA 0 0 2 0 7 2 ...
$ parking_entrance : int 0 4 0 NA 0 0 0 0 0 0 ...
$ parking_space : int 0 0 0 NA 0 0 0 0 0 0 ...
$ pharmacy : int 3 3 1 NA 1 4 5 5 4 5 ...
$ place_of_worship : int 1 0 0 NA 0 1 0 3 1 0 ...
$ police : int 0 0 0 NA 0 0 1 0 0 0 ...
$ post_box : int 0 0 0 NA 0 0 0 0 1 0 ...
$ post_office : int 0 1 0 NA 0 0 0 1 0 1 ...
$ pub : int 0 0 0 NA 0 0 2 0 0 0 ...
$ public_building : int 0 0 0 NA 0 0 0 0 0 0 ...
$ recycling : int 0 0 0 NA 1 0 0 0 0 0 ...
$ residence : int 0 0 0 NA 0 0 0 0 0 0 ...
$ restaurant : int 2 9 5 NA 3 21 10 15 7 13 ...
$ school : int 0 1 3 NA 0 0 1 4 1 6 ...
$ shelter : int 1 0 0 NA 1 0 0 0 0 0 ...
$ shower : int 0 0 0 NA 0 0 0 0 0 0 ...
$ showers : int 0 0 0 NA 0 0 0 0 0 0 ...
[list output truncated]
我正在运行带有调整功能的交叉验证SVM模型:
svm_tune <- tune(svm, catrent ~., data = aa, list(gamma = 2^(-1:1), cost = 2^(2:4)))
我收到此错误:
if(any(co)){:缺少值需要TRUE / FALSE
时出错
答案 0 :(得分:0)
在这里发表评论我的建议。
您的错误是由于您的数据中存在NA。您可以使用不同的approch来处理这些问题,但由于您只有49个观察结果,我不会忽略这些...我会把每一列的意思都搞定:
for(i in 1:ncol(aa)){
aa[is.na(aa[,i]), i] <- mean(aa[,i], na.rm = TRUE)
}
因为您正在使用调谐功能。在应用函数之前,数据不需要按比例缩放,因为它在运行函数时完成。
但是,由于你只有49个观察点,你需要调整调整函数中的交叉参数(看一下e1071包的详细信息e10171)。
tc <- tune.control(cross = 5)
model_1 <- tune.svm(catrent~., data =aa , list(gamma=2^(-1:1), cost = 2^(2:4)), tunecontrol = tc)
应该工作!