---
title: "Discussion on \"Time Series Forecasting Lab (Part 2) - Feature Engineering with Recipes\" | Hashnode"
description: "Discussion on \"Time Series Forecasting Lab (Part 2) - Feature Engineering with Recipes\". Cover photo by Kristine Tumanyan on Unsplash\nGo to R-bloggers for R news and tutorials contributed by hundreds of R bloggers.\nThis is the second of a series of 6 articles about time series forecasting with panel data and ensemble stacking with R. Cli..."
url: "https://hashnode.com/posts/time-series-forecasting-lab-part-2-feature-engineering-with-recipes/61d5c777e2f29f0805e13d7a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Time Series Forecasting Lab (Part 2) - Feature Engineering with Recipes](https://blog.bguarisma.com/time-series-forecasting-lab-part-2-feature-engineering-with-recipes?utm_source=hashnode&utm_medium=feed)

Cover photo by Kristine Tumanyan on Unsplash Go to R-bloggers for R news and tutorials contributed by hundreds of R bloggers. This is the second of a series of 6 articles about time series forecasting with panel data and ensemble stacking with R. Cli...

Jan 5, 2022 · 20 min read · blog.bguarisma.com  
Updated Apr 20, 2022  
Read the article

-   [#r](https://hashnode.com/tag/r)
-   [#machine-learning](https://hashnode.com/tag/machine-learning)

## Written by

[Boris Guarisma](https://hashnode.com/@bguarisma)

@bguarisma · Paris, France

  
[View profile](https://hashnode.com/@bguarisma)

Data Science, AI & Quantum Computing

Avec curiosité et humilité, je partage ici mes explorations en IA, data science et au-delà. Un carnet de bord pour apprendre, douter, comprendre — loin du buzz, proche du vrai.

## Responses 3

Markdown supported · ⌘↵ to post

[Bebo E](https://hashnode.com/@naivebayes1)

[Nov 16, 2022](https://hashnode.com/posts/time-series-forecasting-lab-part-2-feature-engineering-with-recipes/61d5c777e2f29f0805e13d7a/comment/6374c8c2e1d53a5fd290def3)

Hi , great work! I wanted to quickly ask. When augmenting lags and rolling features and then you split test and train, isn't there significant leakage in the test set due to the rolling features seeing the actual values for turnover?

[JG](https://hashnode.com/@TheGoat)

[Feb 18, 2025](https://hashnode.com/posts/time-series-forecasting-lab-part-2-feature-engineering-with-recipes/61d5c777e2f29f0805e13d7a/comment/6374c8c2e1d53a5fd290def3#reply-67b4fb0963d5fa72ea83ced1)

Did you get an answer to this?

[Ajay Mehta](https://hashnode.com/@AjayKMehta)

[Jan 25, 2022](https://hashnode.com/posts/time-series-forecasting-lab-part-2-feature-engineering-with-recipes/61d5c777e2f29f0805e13d7a/comment/61f0239f87fd2728e7cd3913)

An alternative approach to get standardization parameters would be to calculate them (again):

```
tmp <- monthly_retail_tbl %>%
  group_by(Industry) %>% 
  arrange(Month) %>%
  mutate(Turnover = log1p(x = Turnover)) %>% 
  group_map(~ c(mean = mean(.x$Turnover, na.rm = TRUE),
                sd = sd(.x$Turnover, na.rm = TRUE))) %>% 
  bind_rows()

std_mean <- tmp$mean
std_sd <- tmp$sd
rm('tmp')
```

[Simona Jokubauskaite](https://hashnode.com/@S1mona)

[Jan 24, 2022](https://hashnode.com/posts/time-series-forecasting-lab-part-2-feature-engineering-with-recipes/61d5c777e2f29f0805e13d7a/comment/61eec6d9c99aed184e7275c7)

**Hi, one could capture.output from standardize\_vec like this:**

```
stdout <- capture.output(groups <- lapply(X = 1:length(Industries), FUN = function(x){

  monthly_retail_tbl %>%
    filter(Industry == Industries[x]) %>%
    arrange(Month) %>%
    mutate(Turnover =  log1p(x = Turnover)) %>%
    mutate(Turnover =  standardize_vec(Turnover)) %>%
    future_frame(Month, .length_out = "12 months", .bind_data = TRUE) %>%
    mutate(Industry = Industries[x]) %>%
    tk_augment_fourier(.date_var = Month, .periods = 12, .K = 1) %>%
    tk_augment_lags(.value = Turnover, .lags = 12) %>%
    tk_augment_slidify(.value   = Turnover_lag12,
                       .f       = ~ mean(.x, na.rm = TRUE), 
                       .period  = c(3, 6, 9, 12),
                       .partial = TRUE,
                       .align   = "center")
}), type = "message")
```

**And save mean and sd values automatically:**

```
collect_vals <- function(stdout, string = "mean: "){
  stdout %>% grep(string, ., value = TRUE) %>% gsub(string,"", .) %>% as.numeric()
}
std_mean <- stdout %>% collect_vals("mean: ")
std_sd <- stdout %>% collect_vals("standard deviation: ")
```

[Boris Guarisma](https://hashnode.com/@bguarisma)

[Jan 24, 2022](https://hashnode.com/posts/time-series-forecasting-lab-part-2-feature-engineering-with-recipes/61d5c777e2f29f0805e13d7a/comment/61eec6d9c99aed184e7275c7#reply-61eedeb7c99aed184e727948)

Thank you [Simona Jokubauskaite](https://hashnode.com/@S1mona) ! I will update by referring the reader to your comment
