Skip to content
Prev 205471 / 398503 Next

svm

Hi,
On Tue, Jan 5, 2010 at 7:01 PM, Amy Hessen <amy_4_5_84 at hotmail.com> wrote:
This isn't exactly correct ... look at the examples in the ?svm
documentation a bit closer.
Using the first example in ?svm

attach(iris)
model <- svm(Species ~ ., data = iris)

The first argument in the function call is the formula. The "Species"
column is the class label.

`iris` is a data.frame ... you can see that it has the label *in it*,
look at the output of "head(iris)
Just follow the example in ?svm some more, you'll see training a model
and then testing it on data. The example happens to be the same data
the model trained on. To use new data, you'll just need a data
matrix/data.frame with as many columns as your original data, and as
many rows as you have observations.

The first step separates the labels from the data (you can do the same
in  your data -- you don't have to have separate test and train files
that are different -- just remove the labels from it in R):

attach(iris)
x <- subset(iris, select = -Species)
y <- Species
model <- svm(x, y)

# test with train data
pred <- predict(model, x)

Hope that helps,
-steve