Error in scale.default: length of 'center' must equal the number of columns of 'x'

本小妞迷上赌 提交于 2019-12-05 15:07:45

Actually, the problems with glmboost and glm are related. There are problems with your teacher_prefix variable.

As the glm example points out, there are levels that are in test that are not in training (kind of). While both factors have the same levels(), the training set has no observations where teacher_prefix=="" but test does. Compare

table(test$teacher_prefix)
table(training$teacher_prefix)

So glm is actually giving the more accurate, helpful error message. The problem is the same with glmboost although it isn't as direct about saying it.

Doing this seemed to "fix" it

test2 <- subset(test, teacher_prefix %in% c("Dr.","Mr.","Mrs.","Ms."))
test2$teacher_prefix <- droplevels(test2$teacher_prefix)
pred <- predict(model, newdata=test2, type="response")

We just get rid of the unused levels and then do the standard prediction.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!