library(tree)
set.seed(1)
train=1:80
sum(is.na(sobija1))
hist(sobija1$CCSI)
sss=ifelse(sobija1$CCSI<=100, "negative","positive" )
sss=as.factor(sss)
sobija1=data.frame(sobija1,sss)
Tree_Class=tree(sss~sobija1$unemployment_rate+sobija1$house_pirce_index,sobija1,subset=train)
print(summary(Tree_Class))
plot(Tree_Class)
text(Tree_Class, pretty=0, cex=0.75)
cat("\n Confusion table for classification trees \n")
print(table(predict(Tree_Class,newdata = sobija1[-train,],type = "class"), sss[-train]))
> print(table(predict(Tree_Class,newdata = sobija1[-train,],type = "class"), sss[-train]))
Error in table(predict(Tree_Class, newdata = sobija1[-train, ], type = "class"), :
all arguments must have the same length
In addition: Warning message:
'newdata' had 41 rows but variables found have 121 rows
I tried to make a decision tree model, and was trying to make a matrix to check the error rate, but this error came up and now I have no idea how fix it.