警告消息:损坏的数据帧

Warning message: corrupt data frame

我正在尝试创建数据框,但下面的代码给出了一条警告消息。有人知道问题出在哪里吗?

library(tibble); library(magrittr); library(tidymodels); library(dplyr)

c(28L, 13L, 3L, 2L, 0L, 3L) -> points
c(100L, 91L, 8L, 5L, 13L, 12L) -> hours

tibble(points, hours) -> monthly

linear_reg() %>%
  set_engine("lm") %>%
  fit(points ~ hours, data = monthly) ->
  lm_fit

expand.grid(hours = seq(5, 30, 5)) %>%
  mutate(predicted = predict(lm_fit, .))

#  hours                                    predicted
# 1     5      3[38;5;246m# A tibble: 6 x 13[39m
# 2    10                                        .pred
# 3    15   3[3m3[38;5;246m<dbl>3[39m3[23m
# 4    20                3[38;5;250m13[39m 0.885
# 5    25                3[38;5;250m23[39m 1.98 
# 6    30                3[38;5;250m33[39m 3.08 

predict() 方法调用了 lm_fit returns tibble/data 帧。我认为您只需要该数据框的预测列,.pred。您可以通过标准子集化获得:

expand.grid(hours = seq(5, 30, 5)) %>%
    mutate(predicted = predict(lm_fit, .)$.pred)

  hours predicted
1     5  0.885311
2    10  1.983003
3    15  3.080695
4    20  4.178386
5    25  5.276078
6    30  6.373770