Fairy
Fairy

Reputation: 389

plot does not show up for an svm object and no error is returned as well

I am trying to use svm() to classify my data. A sample of my data is as follows:

    ID  call_YearWeek   week    WeekCount   oc
    x   2011W01 1   0   0
    x   2011W02 2   1   1
    x   2011W03 3   0   0
    x   2011W04 4   0   0
    x   2011W05 5   1   1
    x   2011W06 6   0   0
    x   2011W07 7   0   0
    x   2011W08 8   1   1
    x   2011W09 9   0   0
    x   2011W10 10  0   0
    x   2011W11 11  0   0
    x   2011W12 12  1   1
    x   2011W13 13  1   1
    x   2011W14 14  1   1
    x   2011W15 15  0   0
    x   2011W16 16  2   1
    x   2011W17 17  0   0
    x   2011W18 18  0   0
    x   2011W19 19  1   1

The third column shows week of the year. The 4th column shows number of calls in that week and the last column is a binary factor (if a call was received in that week or not). I used the following lines of code:

 train <- data[1:105,]
 test <- data[106:157,]
 model <- svm(oc~week,data=train)
 plot(model,train,week)
 plot(model,train)

none of the last two lines work. they dont show any plots and they return no error. I wonder why this is happening.

Thanks

Upvotes: 3

Views: 2486

Answers (1)

MrFlick
MrFlick

Reputation: 206382

Seems like there are two problems here, first is that not all svm types are supported by plot.svm -- only the classification methods are, and not the regression methods. Because your response is numeric, svm() assumes you want to do regression so it chooses "eps-regression" by default. If you want to do classification, change your response to a factor

model <- svm(factor(oc)~week,data=train)

which will then use "C-classification" by default.

The second problem is that there does not seem to be a univariate predictor plot implemented. It seems to want two variables (one for x and one for y).

It may be better to take a step back and describe exactly what you want your plot to look like.

Upvotes: 4

Related Questions