Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

r - type="C-classification" SVM long vectors (argument 29) are not supported in .C

Hi I am having difficulties implementing svm model.

The setup for the SVM model would be

    d <- diamonds[sample(nrow(diamonds),"4000"), ]
d$price_cat <- cut(d$price,10,labels = LETTERS[1:10])

spec = c(train = .5, test = .3, validate = .2)

g = sample(cut(
  seq(nrow(d)), 
  nrow(d)*cumsum(c(0,spec)),
  labels = names(spec)
))

res = split(d, g)

X_trn <- model.matrix(price_cat~.-1, data=res$train)
X_val <- model.matrix(price_cat~.-1, data=res$validate)
X_tst <- model.matrix(price_cat~.-1, data=res$test)


#scaling
means <- apply(X_trn, 2, mean)
sds <- apply(X_trn, 2, sd)

X_trn.s <- X_trn %>% sweep(MARGIN = 2, STATS = means, FUN = `-`) %>% 
  sweep(MARGIN = 2, STATS = sds, FUN = `/`)

X_val.s <- X_trn %>% sweep(MARGIN = 2, STATS = means, FUN = `-`) %>% 
  sweep(MARGIN = 2, STATS = sds, FUN = `/`)

X_tst.s <- X_trn %>% sweep(MARGIN = 2, STATS = means, FUN = `-`) %>% 
  sweep(MARGIN = 2, STATS = sds, FUN = `/`)

Then I try to implement svm model

svm.1 <- svm(price_cut~., data = res$train, kernel="radial",type="C-classification")

It seems that without specifying a type, the function works perfectly fine. once i try to add this type I get the error

the error

What am I missing?

Thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...