【发布时间】:2021-12-25 06:28:12
【问题描述】:
我正在执行一项任务,我必须使用测试数据评估基于 RMSE(均方根误差)的预测模型。我已经建立了一个线性回归模型,使用基于训练数据的所有可用预测变量来预测葡萄酒质量(数字)。以下是我当前的代码。完整的错误是 “错误:mutate() 列 regression1 有问题。
我regression1 = predict(regression1, newdata = my_type_test)。
x 没有适用于“c('double', 'numeric')”类对象的“预测”方法
install.packages("rsample")
library(rsample)
my_type_split <- initial_split(my_type, prop = 0.7)
my_type_train <- training(my_type_split)
my_type_test <- testing(my_type_split)
my_type_train
regression1 <- lm(formula = quality ~ fixed.acidity + volatile.acidity + citric.acid + chlorides + free.sulfur.dioxide + total.sulfur.dioxide +
density + pH + sulphates + alcohol, data = my_type_train)
summary(regression1)
regression1
install.packages("caret")
library(caret)
install.packages("yardstick")
library(yardstick)
library(tidyverse)
my_type_test <- my_type_test %>%
mutate(regression1 = predict(regression1, newdata = my_type_test)) %>%
rmse(my_type_test, price, regression1)
【问题讨论】:
-
你能提供数据或至少几行吗?没有数据很难复制这个问题。你可以使用
dput()函数。 -
你确定你的代码吗?结果变量名先是
quality,然后好像是price?
标签: r linear-regression training-data predict