R Warning: newdata' had 15 rows but variables found have 22 rows [duplicate]

喜欢而已 提交于 2019-12-02 03:42:58

solution :

lm_colors <- lm(avg_impressions ~ poly(ad_position, 13), data=colors_train_agg)

Reason : you can compare yourselves how model.matrix() generates the matrix to score the data inside predict(). So when we pass model(df$var1~df$var2), model.matrix() looks for df$var1 and df$var2 to generate the matrix- but this has dimensions of training data (df). Problem of having different names in the model and in newdata

go through below steps( if you are interested in knowing the cause) :

model1 <- lm(var1~var2, data = df)
model2 <- lm(df$var1~df$var2)
debug(predict)
predict(model1, newdata = df1)
predict(model2, newdata = df1) 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!