Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R RKEA - Not enough training instances with class labels (required: 1, provided: 0)!

I'm trying to get RKEA to work in R Studio. Here's my current code:

#Imports packages
library(RKEA)
library(tm)

#Creates a corpus of training sentences
data <- c("This is a sentence",
          "I am in an office",
          "I'm working on a laptop",
          "I have a glass of water",
          "There is a wooden desk",
          "I have an apple for lunch")
data <- as.data.frame(data)
data <- Corpus(VectorSource(data$data))

#Creates a corpus of training keywords
keywords <- c("sentence",
              "office",
              "working",
              "glass",
              "wooden",
              "apple")
keywords <- as.data.frame(keywords)
keywords <- Corpus(VectorSource(keywords$keywords))

#Creates output file for created model
tmpdir <- tempfile()
dir.create(tmpdir)
model <- file.path(tmpdir, "MyModel")

#Creates RKEA model
createModel(data, keywords, model)

This is mostly modelled after the example given in the RKEA documentation. However, when I run this I get the following error message:

Error in .jcall(km, "V", "saveModel") : 
  weka.core.WekaException: weka.classifiers.bayes.NaiveBayesSimple: Not enough training instances with class labels (required: 1, provided: 0)!
like image 979
peter337 Avatar asked Oct 17 '17 14:10

peter337


1 Answers

I think your example sentences are too short as documents. The following modification (primarily to the first sample document) works without error:

data <- c("This is a longer and longer sentence.",
      "I am in an office.",
      "I'm working on a laptop.",
      "I have a glass of water.",
      "There is a wooden desk.",
      "I have an apple for lunch.")

My guess is that with really short sentences, there aren't enough words that aren't keywords to use in building the model.

like image 161
cmaimone Avatar answered Sep 19 '22 05:09

cmaimone