这是我的数据集----> df_train
Address Pincode_type
flat no 3,cruz villa, sa - 200021 5521
plot 21,high street, nz - 500034 5524
room no12,pink seepz, bl -300001 1132
qbiz,almount park, ls - 500034 5524
papton_green,b-3,street1, sp-200021 5521
rose villa,plot no3, ai- 200021 5521
class(df_train$Address) = factor
class(df_train$Pincode_type) = factor
我使用SVM根据地址使用df_train数据集对pincode_type进行分类
这是我的df_test
数据
Address
blueton,shinville, ca-500034
treboss,plot-2, hs -200021
jacq apt,room no3, sp -300001
class(df_test$Address) = "factor"
这就是我试过的
attach(df_train)
svm_mod=svm(as.factor(Address)~Pincode_type,data=df_train,type='C',kernal='linear') #executes properly
summary(svm_mod)
SVM_Type:C-classification
SVM Kernal:radial
cost:1
gamma :0.0002187705
Number of support vectors:4636
Number of Classes :91
pred=predict(svm_mod,df_test$Address)
Error in 1:nrow(newdata) : argument of length 0
我也试过
pred=predict(svm_mod,as.character(df_test$Address))
Error in colnames <- '(' *tmp* value =c(Address..link.blueton
length of dimnames [2] not equal to array extent
任何帮助都会非常感谢。谢谢
答案 0 :(得分:1)
最后通过将其更改为data.frame()
来完成此操作pred=predict(svm_mod,newdata=data.frame(x=df_test$Address))