mardi 21 avril 2015

Svm missing value where TRUE/FALSE needed in R

Vote count: 0

I'm trying to implement binary svm. I've got the following error message:

Error in if (any(co)) { : missing value where TRUE/FALSE needed

For the following code:

library(e1071)
dataset <- read.csv("C:/Users/Backup/Desktop/pos.csv")
# Subset the dataset dataset to only 2 labels and 2 features
dataset.part = subset(dataset, label != 1)
dataset.part$label = factor(dataset.part$label)


# Fit svm model
fit = svm(label ~ ., data=dataset.part, type='C-classification',   kernel='linear')

# Make a plot of the model
dev.new(width=5, height=5)
plot(fit, dataset.part)

# Tabulate actual labels vs. fitted labels
pred = predict(fit, dataset.part)
table(Actual=dataset.part$label, Fitted=pred)

# Obtain feature weights
w = t(fit$coefs) %*% fit$SV

# Calculate decision values manually
dataset.scaled = scale(dataset.part[,-3], fit$x.scale[[1]],  fit$x.scale[[2]]) 
t(w %*% t(as.matrix(dataset.scaled))) - fit$rho

# Should equal...
fit$decision.values

I'm a beginner in R and i don't know how to solve this. Could any one help me?

asked 1 min ago



Svm missing value where TRUE/FALSE needed in R

Aucun commentaire:

Enregistrer un commentaire