【发布时间】:2016-12-05 16:20:31
【问题描述】:
我在这里阅读了一些关于此的答案,但恐怕我无法找到答案。
我的 R 代码是:
colors <- bmw[bmw$Channel=="Colors" & bmw$Hour=20,]
colors_test <- tail(colors, 89)
colors_train <- head(colors, 810)
colors_train_agg <- aggregate(colors_train$Impressions, list(colors_train$`Position of Ad in Break`), FUN=mean, na.rm=TRUE)
colnames(colors_train_agg) <- c("ad_position", "avg_impressions")
lm_colors <- lm(colors_train_agg$avg_impressions ~ poly(colors_train_agg$ad_position, 12))
summary(lm_colors)
colors_test_agg <- aggregate(colors_test$Impressions, list(colors_test$`Position of Ad in Break`), FUN=mean, na.rm=TRUE)
colnames(colors_test_agg) <- c("ad_position", "avg_impressions")
new.df <- data.frame(colors_test_agg$ad_position)
colnames(new.df) <- c("ad_position")
colors_test_test <- predict(lm_colors, newdata=new.df)
因此,我的训练数据和测试数据的列名完全相同。我仍然收到警告:
Warning message:
'newdata' had 15 rows but variables found have 22 rows
有人可以提出什么问题吗?另外,我想知道我的做法是否正确。
此外,我们将不胜感激有关如何计算模型准确性的一些指示。谢谢!
【问题讨论】:
-
首选
lm(avg_impressions ~ poly(ad_position, 12), data = colors_train_agg) -
问题是关于行不一致,如果您提供几个维度会有所帮助。
lapply(list(colors_test, colors_train, colors_train_agg, colors_test_agg), dim) -
你能提供数据吗?
-
使用
lm_colors <- lm(avg_impressions ~ poly(ad_position, 13), data=colors_train_agg)有效。谢谢@joel.wilson。谢谢大家的时间。 -
虽然我们解决了您的问题,但一直有发布一个comp[lete问题(包括示例小数据)供我们处理的习惯
标签: r prediction non-linear-regression