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)
}