title: What is causing the loss function to be nan in the tidymodels specification?
body: <p>I'm tackling a problem for <a href="https://www.kaggle.com/datasets/gregorut/videogamesales" rel="nofollow noreferrer">this</a> dataset.
  I am trying to build a model to predict Japan sales from every other predictor (except Rank, Name and Global Sales which is too correlated with the outcome variable). So, I did:</p>
  <pre><code>vgames &lt;- read_csv('data/vgsales.csv', show_col_types = FALSE, col_types = list(
      Year = col_date(&quot;%Y&quot;)
  )) %&gt;%
      mutate(
          Platform = factor(Platform),
          Genre = factor(Genre),
          Publisher = factor(Publisher)
      )
  
  vgames_model &lt;- vgames %&gt;%
      select(-c(Rank, Name, Global_Sales))
  
  # Train test split
  vgames_split &lt;- vgames_model %&gt;% initial_split()
  vgames_training &lt;- vgames_split %&gt;% training()
  vgames_testing &lt;- vgames_split %&gt;% testing()
  
  # Folds for CV
  vgames_folds &lt;- vgames_training %&gt;% vfold_cv(v = 10)
  
  # Recipe
  vgames_recipe &lt;- vgames_training %&gt;%
      recipe(formula = JP_Sales ~ .) %&gt;%
      step_normalize(all_numeric_predictors()) %&gt;%
      step_date(Year, features = c(&quot;year&quot;), keep_original_cols = FALSE) %&gt;%
      step_dummy(all_nominal()) %&gt;%
      step_zv(all_numeric_predictors())
  </code></pre>
  <p>The output of this recipe is something like this:</p>
  <pre><code># A tibble: 12,448 × 570
     NA_Sales EU_Sales Other_…¹ JP_Sa…² Year_…³ Platf…⁴ Platf…⁵ Platf…⁶ Platf…⁷ Platf…⁸ Platf…⁹ Platf…˟ Platf…˟ Platf…˟
        &lt;dbl&gt;    &lt;dbl&gt;    &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;
   1   -0.272  -0.279   -0.240     0       2006       0       0       0       0       0       0       0       0       0
   2    0.145   0.258    0.0629    0       2012       0       0       0       0       0       0       0       0       0
   3   -0.198  -0.241   -0.189     0.07    2008       0       0       0       1       0       0       0       0       0
   4   -0.149  -0.260   -0.189     0       2010       0       0       0       1       0       0       0       0       0
   5   -0.149  -0.0679  -0.0380    0       2006       0       0       0       0       0       0       0       0       0
   6   -0.296  -0.183   -0.189     0       2015       0       1       0       0       0       0       0       0       0
   7    3.32    1.05     0.315     1.81    1988       0       0       0       0       0       0       0       0       0
   8   -0.308  -0.260   -0.240     0       2016       0       0       0       0       0       0       0       0       0
   9   -0.321  -0.202   -0.240     0       2015       0       0       0       0       0       0       0       0       0
  10   -0.112  -0.145   -0.139     0       2010       0       0       0       0       0       0       0       0       0
  # … with 12,438 more rows, 556 more variables: Platform_N64 &lt;dbl&gt;, Platform_NES &lt;dbl&gt;, Platform_NG &lt;dbl&gt;,
  #   Platform_PC &lt;dbl&gt;, Platform_PCFX &lt;dbl&gt;, Platform_PS &lt;dbl&gt;, Platform_PS2 &lt;dbl&gt;, Platform_PS3 &lt;dbl&gt;,
  #   Platform_PS4 &lt;dbl&gt;, Platform_PSP &lt;dbl&gt;, Platform_PSV &lt;dbl&gt;, Platform_SAT &lt;dbl&gt;, Platform_SCD &lt;dbl&gt;,
  #   Platform_SNES &lt;dbl&gt;, Platform_TG16 &lt;dbl&gt;, Platform_Wii &lt;dbl&gt;, Platform_WiiU &lt;dbl&gt;, Platform_WS &lt;dbl&gt;,
  #   Platform_X360 &lt;dbl&gt;, Platform_XB &lt;dbl&gt;, Platform_XOne &lt;dbl&gt;, Genre_Adventure &lt;dbl&gt;, Genre_Fighting &lt;dbl&gt;,
  #   Genre_Misc &lt;dbl&gt;, Genre_Platform &lt;dbl&gt;, Genre_Puzzle &lt;dbl&gt;, Genre_Racing &lt;dbl&gt;, Genre_Role.Playing &lt;dbl&gt;,
  #   Genre_Shooter &lt;dbl&gt;, Genre_Simulation &lt;dbl&gt;, Genre_Sports &lt;dbl&gt;, Genre_Strategy &lt;dbl&gt;, …
  # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names
  </code></pre>
  <p>Now, here comes the problem: when I define and fit the mlp, the epochs give all a nan back as a loss function and every other metric, that is:</p>
  <pre><code>nn &lt;- mlp(epochs = 20) %&gt;%
      set_engine('keras', verbose = 1, metrics = c(&quot;mae&quot;), optimizer = 'adam', loss = 'mean_absolute_error') %&gt;%
      set_mode('regression')
  
  nnwf &lt;- workflow() %&gt;%
      add_model(nn) %&gt;%
      add_recipe(vgames_recipe)
  
  nnwf %&gt;% fit(vgames_training)
  </code></pre>
  <p>yields</p>
  <pre><code>...
  Epoch 16/20
  389/389 [==============================] - 1s 1ms/step - loss: nan - mae: nan
  Epoch 17/20
  389/389 [==============================] - 1s 1ms/step - loss: nan - mae: nan
  Epoch 18/20
  389/389 [==============================] - 1s 2ms/step - loss: nan - mae: nan
  Epoch 19/20
  389/389 [==============================] - 1s 2ms/step - loss: nan - mae: nan
  Epoch 20/20
  389/389 [==============================] - 1s 1ms/step - loss: nan - mae: nan
  </code></pre>
  <p>I already looked around and tried to normalize in other points, to take the learning rate down (both in the mlp() function and in the set_engine specification) and to remove the date column altogether. None of that worked, and I'm having a hard time figuring out what. Did anybody run into this issue before?</p>