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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…