簡體   English   中英

在R中使用SVM對pincode類型進行分類

[英]Classifying pincode type using SVM in r

這是我的數據集----> 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

任何幫助將不勝感激..謝謝

最終,只需將其更改為data.frame()

pred=predict(svm_mod,newdata=data.frame(x=df_test$Address))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM