If I use the example code from the e1071 documentation on page 52, I obtain a pred
variable of class "factor".
> str(pred)
Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
- attr(*, "names")= chr [1:150] "1" "2" "3" "4" ...
This is fine; but when I use the same commands on my data, I obtain a pred variable of class "numeric":
> str(pred)
Named num [1:1000] 0.95 0.0502 0.05 0.9902 -0.0448 ...
- attr(*, "names")= chr [1:1000] "1" "2" "3" "4" ...
and this seems wrong; the prediction does not seem to work at all.
My code is:
# create variables to store the path to the files you downloaded:
data.dir <- "c:/kaggle/scikit/"
train.file <- paste0(data.dir, 'train.csv')
trainLabels.file <- paste0(data.dir, 'trainLabels.csv')
# READ DATA - CAREFUL IF THERE IS A HEADER OR NOT
train <- read.csv(train.file, stringsAsFactors=F, header=FALSE)
trainLabels <- read.csv(trainLabels.file, stringsAsFactors=F, header=FALSE)
# LOADING LIBRARY e1071
install.packages('e1071')
library('e1071')
## classification mode
model <- svm(train, trainLabels)
summary(model)
# test with train data
pred <- predict(model, train)
Where do I go wrong?