【发布时间】:2018-07-29 22:12:11
【问题描述】:
我正在使用R 的RMOA 包来实现具有留出评估的霍夫丁树流分类器。
一切都在正确训练,除了当我尝试从保留的测试流中评估我的模型时,我收到以下错误消息:
UseMethod("predict") 中的错误: 没有适用于“c('HoeffdingTree', 'MOA_classifier', 'MOA_model')”类对象的“预测”方法
检查了this question 的答案后,问题可能源于predict() 方法存在于stats 和RMOA 包中。我尝试使用:: 表示法来指定哪个包,但我似乎无法指向RMOA predict()。我还尝试完全卸载stats,但没有帮助。
有人知道如何直接指向RMOA 的predict(),还是我的问题完全是由其他原因引起的?
我的 R 代码如下。我现在只是在流式传输 iris 数据集,并提取前 30 个流项以用于保持评估。
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)
}
【问题讨论】:
标签: r machine-learning classification