Why am I getting "Error: Problem with `mutate()` column `regression1`"?

Why am I getting "Error: Problem with `mutate()` column `regression1`"?

我正在做一项作业,我必须使用测试数据评估基于 RMSE(均方根误差)的预测模型。我已经建立了一个线性回归模型来预测葡萄酒质量(数字),使用基于火车数据的所有可用预测变量。以下是我当前的代码。完整的错误是 “错误:mutate()regression1 有问题。 我regression1 = predict(regression1, newdata = my_type_test)。 x 没有适用于 'predict' 的方法应用于 class 的对象“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)

您采取的许多步骤可能都是不必要的。
应该实现相同目的的最小示例:

# Set seed for reproducibility
set.seed(42)
# Take the internal 'mtcars' dataset
data <- mtcars
# Get a random 80/20 split for the number of rows in data
split <- sample(
   ​size = nrow(data), 
   ​x = c(TRUE, FALSE), 
   ​replace = TRUE,
   ​prob = c(0.2, 0.8)
)
# Split the data into train and test sets
train <- data[split, ]
test <- data[!split, ]

# Train a linear model
fit <- lm(mpg ~ disp + hp + wt + qsec + am + gear, data = train)

# Predict mpg in test set
prediction <- predict(fit, test)

结果:

> caret::RMSE(prediction, test$mpg)
[1] 4.116142