-3

There are two data frames: trainReady(288obs.) and testReady(112obs.). These data frames contains 55 attributes (54 continuous and 1 binary, class attribute). I have already discretized those 54 attributes to 10 divisions, levels (with equal number of observations per level assumption). The number of obs. of both classes in trainReady is nearly equal. In testReady too. Class attribute is treated as factor. Below I am posting pieces of data frames:
trainReady trainReady

testReady enter image description here

When I try to run those lines (as you can see I have set the threshold to omit "0-frequency" problem):

model_bayes <- naiveBayes(isFace ~ ., data = trainReady)
prediction <- predict(model_bayes, testReady[,-1], threshold = 0.001, eps = 0)

I receive:

Error in [.default(object$tables[[v]], , nd + islogical[attribs[v]]) : 
  subscript out of bounds

What I have already done to help myself with overcoming the problem:

  1. model_bayes <- naiveBayes(isFace ~ ., data = trainReady, drop.unused.levels = FALSE)
  2. Predicting on the data which had been used to train model:

prediction <- predict(model_bayes, trainReady[,-1], threshold = 0.001, eps = 0) 1 does not work, 2 works but I would like to predict on the test data. Could you tell me how can I overcome the problem?

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
Czarek
  • 689
  • 9
  • 20
  • Please do not provide your data in an image. We do not want to type it all in again to reproduce your problem. Instead, please use `dput(testReady)` and `dput(trainReady)` and copy the results to your question so that we can cut and paste into R. – G5W May 09 '18 at 23:58

1 Answers1

0

You must use the same discretization that you used for training also for test data.

Do not diacretize them independently.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194