object '.fitted' not found

How can we optain fitted values from tidymodels.

fitting normal lm() works...

df <- df %>% dplyr::select(any_of(colVect)) %>% group_by(groupId) %>%
tidyr::nest(-groupId) %>%
dplyr::mutate(split = purrr::map(data, ~rsample::initial_split(., prop = 0.8)),
train = purrr::map(split, ~training(.)),
test = purrr::map(split, ~testing(.)),
myFormula = purrr::map(groupId, ~getFormula(.)),
fit = purrr::map(train, ~lm(as.character(myFormula),data=.)),
tidied = purrr::map(fit, tidy),
glanced = purrr::map(fit, glance),
augmented = purrr::map(fit, augment),
pred = purrr::map2(.x = fit, .y = test, ~predict(object = .x, newdata = .y)))

#------------------------------------------
model_perf <- df %>% unnest(glanced)
best_fit <- model_perf %>%
top_n(n = modelAnz, wt = r.squared)

    perfPlot     <- model_perf %>% 
        ggplot(aes(x = r.squared)) + 
        geom_histogram()
    #------------------------------------------
    best_augmented <- best_fit %>% unnest(augmented)
    
    actual_fitted_plot <- best_augmented %>% 
        ggplot(aes(x = id)) +
        geom_point(aes_(y = as.name(targetTxt))) + 
        geom_line(aes(y = .fitted), color = "red") +
        facet_wrap(~groupId, scales = "free_y")

    #View(best_augmented)
    print(actual_fitted_plot)

while...

df <- df %>% dplyr::select(any_of(colVect)) %>% group_by(groupId) %>%
tidyr::nest(-groupId) %>%
dplyr::mutate(split = purrr::map(data, ~rsample::initial_split(., prop = 0.8)),
train = purrr::map(split, ~training(.)),
test = purrr::map(split, ~testing(.)),
myFormula = purrr::map(groupId, ~getFormula(.)),
fit = purrr::map2(.x = train, .y = as.character(myFormula), ~fitTidy(df = .x, myFormula = .y)),
tidied = purrr::map(fit, tidy),
glanced = purrr::map(fit, glance),
augmented = purrr::map2(.x = fit, .y = train, ~broom::augment(x = .x, new_data = .y)),
pred = purrr::map2(.x = fit, .y = test, ~predict(object = .x, new_data = .y)))

... has no '.fitted'- column from broom::augment and ggplot says: Error in FUN(X[[i]], ...) : object '.fitted' not found

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.