I have an error:
Error in scores[j, ] <- object$moamodel$getVotesForInstance(oneinstance) : number of items to replace is not a multiple of replacement length
It is after 35 loops for chunk with 1000 sizeand after 17 loops for chunk 2000.
This is my code:
library(foreign)
library(RMOA)
library(stream)
library(mlbench)
library(MASS)
library(plyr)
## stream ##
stream <- read.csv("Poker.csv", sep= ",")
stream$Class <- as.factor(stream$Class)
size <- nrow(stream)
datastream <- datastream_dataframe(data=stream)
## loop parameters ##
chunk <<- 1000
turns <<- (size/chunk)-1
turns <<- floor(turns)
position <<- chunk
## vectors for results ##
result_hdt <- vector('numeric')
## first sample (train) ##
sample <- datastream$get_points(datastream, n = chunk, outofpoints = c("stop", "warn", "ignore"))
sample <- datastream_dataframe(data=sample)
## first model ##
hdt <- HoeffdingTree(numericEstimator = "GaussianNumericAttributeClassObserver")
model_hdt <- trainMOA(model = hdt,
Class ~ .,
data = sample)
## loop ##
list <- 1:turns
progress.bar <- create_progress_bar("text")
progress.bar$init(turns)
for (i in 2:turns){
## second sample (test) ##
sample <- datastream$get_points(datastream, n = chunk, outofpoints = c("stop", "warn", "ignore"))
## prediction ##
scores <- predict(model_hdt,
newdata=sample[, colnames(sample[1:11])],
type="response")
table(scores, sample$Class)
## accuracy ##
chunk_acc_hdt <- mean((scores == sample$Class)*100)
result_hdt <- append(result_hdt, chunk_acc_hdt)
## sample to datastream_dataframe ##
sample <- datastream_dataframe(sample)
## updating model ##
mymodel_hdt <- trainMOA(model = model_hdt$model,
formula = Class ~.,
data = sample,
reset=FALSE,
trace=FALSE)
progress.bar$step()
}
## results ##
result_hdt
X11()
plot(result_hdt, type='l', col='red', main='Hoeffding Tree',
xlab="chunk number", ylab="accuracy [%]", ylim=c(0,100),
xlim=c(0,1024))
My dataset is avaliable here: https://www.dropbox.com/s/0wtpg2lstad43zo/Poker.csv?dl=0
Thak you in advance for any help.