0

I'm using the RMOA package for R to implement a Hoeffding Tree stream classifier with holdout evaluation.

Everything is training correctly, except when I try to evaluate my model from my held-out test stream I'm getting hit with the following error message:

Error in UseMethod("predict") : no applicable method for 'predict' applied to an object of class "c('HoeffdingTree', 'MOA_classifier', 'MOA_model')"

Having checked the answer to this question, the problem may stem from the fact that the predict() method exists in both the stats and RMOA packages. I have tried to use the :: notation in order to specify which package, but I can't seem to point to RMOA predict(). I also tried uninstalling stats altogether but it hasn't helped.

Does anyone know how to point directly to RMOA's predict(), or is my issue caused by something else entirely?

My R code is below. I'm simply streaming the iris data set for just now, and extracting the first 30 stream items to use for holdout evaluation.

holdout<-function(){
    require("RMOA")

    #Initialise streams
    stream<-datastream_dataframe(iris)
    test<-stream$get_points(n=30)
    test<-datastream_dataframe(test)

    #Specify model
    mymodel<-HoeffdingTree(numericEstimator = "GaussianNumericAttributeClassObserver")

    #Record execution time for training
    start_time<-Sys.time()
    while(!stream$finished)
    {
        mymodel <<- trainMOA(model=mymodel, formula = Species ~ Sepal.Length+Sepal.Width+Petal.Length+Petal.Width, data=stream)
    }
    end_time<-Sys.time()
    time_taken <- end_time - start_time
    cat("Finished training. Elapsed time: ", time_taken)
    #Empty vector to store individual accuracy results of holdout stream elements
    accuracies<-c()

    #Record the execution time of holdout evaluation
    start_time<-Sys.time()
    while(!test$finished)
    {
        samp<-test$get_points(n=1)
        pred <- predict(mymodel, samp, type="response")
    }
    end_time<-Sys.time()
    time_taken <- end_time - start_time
    cat("Finished training. Elapsed time: ", time_taken)
}
Scott
  • 1,863
  • 2
  • 24
  • 43

1 Answers1

1

the predict method in package RMOA is an internal variable you can call it like this:

RMOA:::predict.MOA_trainedmodel

full example:

library(RMOA)
data(iris)
stream <- datastream_dataframe(iris)
test <- stream$get_points(n = 30)
test <- datastream_dataframe(test)

mymodel <- HoeffdingTree(numericEstimator = "GaussianNumericAttributeClassObserver")
mymodel <- trainMOA(model = mymodel, formula = Species ~ Sepal.Length+Sepal.Width+Petal.Length+Petal.Width, data = stream)

in my case the predict function is not masked (which is odd if it is not exported):

pred1 <- predict(mymodel, iris, type = "response")

but if it was I could use:

pred2 <- RMOA:::predict.MOA_trainedmodel(mymodel, iris, type = "response")

and the result would be the same:

all.equal(pred1, pred2)
#output
TRUE

I checked the NAMESPACE of RMOA and predict function is exported but for some reason

RMOA::predict.MOA_trainedmodel

results in

Error: 'predict.MOA_trainedmodel' is not an exported object from 'namespace:RMOA'

while

RMOA:::predict.MOA_trainedmodel

does not

missuse
  • 19,056
  • 3
  • 25
  • 47
  • Thanks very much. I did try `RMOA::predict.MOA_trainedmodel` but I ended up with the same error as you. Cheers! – Scott Feb 19 '18 at 17:27