svm - r support vector machine e1071 training not working -


i playing around support vector machines in r-language. using e1071 package.

as long follow manual pages or tutorial @ wikibooks everythings works. if try use own datasets examples things aren't anymore.

it seems model creation fails reason. @ least not getting levels on target column. below find example clarification.

maybe can me figure out doing wrong here. here code , data.

test dataset

target,col1,col2 0,1,2 0,2,3 0,3,4 0,4,5 0,5,6 0,1,2 0,2,3 0,3,4 0,4,5 0,5,6 0,1,2 0,2,3 0,3,4 0,4,5 1,6,7 1,7,8 1,8,9 1,9,0 1,0,10 1,6,7 1,7,8 1,8,9 1,9,0 1,0,10 1,6,7 1,7,8 1,8,9 1,9,0 1,0,10 

r-script

library(e1071)  dataset <- read.csv("test.csv", header=true, sep=',')  tuned <- tune.svm(target~., data = dataset, gamma = 10^(-6:-1), cost = 10^(-1:1))  summary(tuned)  model  <- svm(target~., data = dataset, kernel="radial", gamma=0.001, cost=10)  summary(model) 

output of summary(model) statement

+ summary(model)  call: svm(formula = target ~ ., data = dataset, kernel = "radial", gamma = 0.001,      cost = 10)  parameters:    svm-type:  eps-regression   svm-kernel:  radial         cost:  10        gamma:  0.001      epsilon:  0.1   number of support vectors:  28 > 

wikibooks examaple

if compare output output of wikibooks example, it's missing information. please notice "levels"-section in output:

library(mass) library(e1071) data(cats) model  <- svm(sex~., data = cats) summary(model) 

output

> summary(model)  call: svm(formula = sex ~ ., data = cats)  parameters:    svm-type:  c-classification   svm-kernel:  radial         cost:  1        gamma:  0.5   number of support vectors:  84   ( 39 45 )  number of classes:  2   levels:   f m 

putting roland's answer in proper "answer" format:

target numeric

sex factor

let me give few more suggestions:

  • it seems if target should factor. (it has 2 levels, 0 & 1, , suspect you're trying classify either 0 or 1.) stick in dataset$target <- factor(dataset$target) somewhere.
  • right now, because target numeric, regression model being run instead of classification.
  • it's worthwhile similar check of variables before running model (especially model). in case gave, instance, it's not obvious col1 , col2 are. if either of them grouping or classification, should make them factors, too.
    • in r, many functions have multiple ways in run, depending upon data types fed them. if feed factors model, run classification. if feed numerics, regression. common in many programming languages, , called function overloading.

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -