3

I'm new in using Rweka and R. When I'm using KNN to train the data like writing the following codes.

library(RWeka)
trainfile='/poker-hand-training-true.arff'
rtrain <- as.data.frame(read.arff(file=trainfile))
classifier <- IBk(class ~., data = rtrain)

Here is the error log:

> classifier <- IBk(class ~., data = rtrain)
Error in model.frame.default(formula = class ~ ., data = rtrain) : 
  object is not a matrix

And I've also test the class of the train data. Here it is:

> rtrain
      V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 L
1      1 10  1 11  1 13  1 12  1   1 9
2      2 11  2 13  2 10  2 12  2   1 9
3      3 12  3 11  3 13  3 10  3   1 9
4      4 10  4 11  4  1  4 13  4  12 9
5      4  1  4 13  4 12  4 11  4  10 9
6      1  2  1  4  1  5  1  3  1   6 8
7      1  9  1 12  1 10  1 11  1  13 8
8      2  1  2  2  2  3  2  4  2   5 8
9      3  5  3  6  3  9  3  7  3   8 8
10     4  1  4  4  4  2  4  3  4   5 8
11     1  1  2  1  3  9  1  5  2   3 1
> class(rtrain)
[1] "data.frame"
Keniajin
  • 1,649
  • 2
  • 20
  • 43
Claire Liu
  • 31
  • 1
  • 2
  • 1
    The message is saying that you should use matrix instead of data.frame. You can use `as.matrix(rtrain)` to transform your data – Mamoun Benghezal Apr 02 '15 at 14:11
  • After I tried as.matrix, it turned out to be the following errors > rtrain <- as.matrix(read.arff(file=trainfile)) > classifier <- IBk(class ~., data = rtrain) Error in model.frame.default(formula = class ~ ., data = rtrain) : 'data' must be a data.frame, not a matrix or an array – Claire Liu Apr 02 '15 at 19:11
  • 1
    Why are you using `class~ .` while there is no such variable in `rtrain`? – Mamoun Benghezal Apr 02 '15 at 19:35
  • 1
    did you ever get an answer to this? – Faller Nov 18 '16 at 18:15
  • Dependent variable name has passed incorrectly therefore facing the error. It has been rectified by @MamounBenghezal – Prafulla Dec 05 '16 at 06:59

0 Answers0