如果我使用第 52 页上的e1071 文档pred
中的示例代码,我将获得一个“因子”类的变量。
> 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" ...
这可以; 但是当我对我的数据使用相同的命令时,我获得了一个“数字”类的 pred 变量:
> 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" ...
这似乎是错误的;预测似乎根本不起作用。
我的代码是:
# 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)
我哪里错了?