Unable to draw svm plot. Error in terms.default(x) : no terms component nor attribute

StackOverflow https://stackoverflow.com/questions/22729866

  •  23-06-2023
  •  | 
  •  

Pergunta

I could run svm using R package "e1071" on my dataset but I am not able to plot the graph using any two predictor variables. I am not able to find out its solution even after googling a lot. Experts please help me out in this problem:

I have a dataset with following attributes:

> dim(fulldata)
[1]  153 2915

> str(fulldata)
'data.frame':   153 obs. of  2915 variables:
$ label : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
$ V12   : num  1.372 -1.541 0.201 1.06 1.815 ...
$ V14   : num  0.052 -1.442 1.022 -0.35 0.192 ...
$ V17   : num  0.885 -2.569 0.326 1.574 1.394 ...
$ V37   : num  0.356 2.884 -0.452 0.067 0.282 ...
$ V51   : num  -0.018 -1.71 1.084 -0.21 0.091 ...
$ V66   : num  0.178 0.264 -3.189 0.451 0.831 ...
$ V67   : num  0.693 -0.698 -0.335 0.076 1.016 ...
$ V69   : num  -0.383 -0.316 1.332 -0.643 0.195 ...
$ V70   : num  0.203 0.196 -0.83 0.024 0.257 -0.33 -0.731 0.668 0.39 -0.12 ...

I could able to run svm using e1071 package, but unable to plot using any two predictor variable

svm(y=fulldata[,1], x=fulldata[,-1], probability=T,na.rm=T, kernel="linear")

Call:
svm.default(x = fulldata[, -1], y = fulldata[, 1], kernel = "linear", 
probability = T, na.rm = T)


Parameters:
SVM-Type:  C-classification 
SVM-Kernel:  linear 
      cost:  1 
     gamma:  0.0003431709 

Number of Support Vectors:  60

BUT

> plot(svm(y=fulldata[,1], x=fulldata[,-1], probability=T,na.rm=T, 
kernel="linear"),fulldata,fulldata[,2]~fulldata[,3])

Error in terms.default(x) : no terms component nor attribute

Here is information about my session

sessionInfo() R version 3.0.1 (2013-05-16) Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_IN       LC_NUMERIC=C         LC_TIME=en_IN       
 [4] LC_COLLATE=en_IN     LC_MONETARY=en_IN    LC_MESSAGES=en_IN   
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C        
 [10] LC_TELEPHONE=C       LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] MASS_7.3-26 e1071_1.6-3

loaded via a namespace (and not attached):
[1] class_7.3-7 tcltk_3.0.1 tools_3.0.1
Foi útil?

Solução

from ?formula

The models fit by, e.g., the lm and glm functions are specified in a compact symbolic form. The ~ operator is basic in the formation of such models. An expression of the form y ~ model is interpreted as a specification that the response y is modelled by a linear predictor specified symbolically by model. Such a model consists of a series of terms separated by + operators. The terms themselves consist of variable and factor names.

Using formula with variable names fixs it...a fake example follows

library(e1071)
fulldata <- data.frame("label" = gl(2,150),
                       "V1" = rnorm(300),
                       "V2" = rnorm(300),
                       "V3" = rnorm(300),
                       "V4" = rnorm(300),
                       "V5" = rnorm(300),
                       "V6" = rnorm(300),
                       "V7" = rnorm(300),
                       "V8" = rnorm(300),
                       "V9" = rnorm(300),
               "V10" = rnorm(300))

str(fulldata)

my.svm <- svm(label ~ .,
              probability=TRUE,
              na.rm=TRUE,
              kernel="linear",
              data = fulldata)
my.svm
plot(my.svm,
     data = fulldata,
     formula = V1 ~ V2)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top