title: Normalizing features with tensorflow in R
body: <p>I am currently starting to work with Keras/Tensorflow in R and am therefore working through the <a href="https://tensorflow.rstudio.com/tutorials/beginners/basic-ml/tutorial_basic_regression/" rel="nofollow noreferrer">tensorflow tutorial.</a></p>
  <p>However, when I try to normalize the feature space in the same way as described in the tutorial, I receive an error message/exception.</p>
  <p>I found a kaggle notebook online that tried to reproduce the tensorflow tutorial as well, and it als got stuck at the exact same error message. See <a href="https://www.kaggle.com/code/kewagbln/boston-housing-regression-with-tensorflow/notebook" rel="nofollow noreferrer">https://www.kaggle.com/code/kewagbln/boston-housing-regression-with-tensorflow/notebook</a>.</p>
  <p>Does anyone understand why I am getting the error message? Ultimately, I am not even coding on my own but just copying out of the tutorial and it still does not work.</p>
  <p>To provide some more information: I am running the following code:</p>
  <pre><code>rm(list = ls())
  
  library(keras)
  library(tensorflow)
  library(tfdatasets)
  tensorflow::set_random_seed(42)
  
  boston_housing &lt;- dataset_boston_housing()
  
  c(train_data, train_labels) %&lt;-% boston_housing$train
  c(test_data, test_labels) %&lt;-% boston_housing$test
  
  paste0(&quot;Training entries: &quot;, length(train_data), &quot;, labels: &quot;, length(train_labels))
  
  library(dplyr)
  
  column_names &lt;- c('CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 
                    'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT')
  
  train_df &lt;- train_data %&gt;% 
    as_tibble(.name_repair = &quot;minimal&quot;) %&gt;% 
    setNames(column_names) %&gt;% 
    mutate(label = train_labels)
  
  test_df &lt;- test_data %&gt;% 
    as_tibble(.name_repair = &quot;minimal&quot;) %&gt;% 
    setNames(column_names) %&gt;% 
    mutate(label = test_labels)
  
  spec &lt;- feature_spec(train_df, label ~ . ) %&gt;%
    step_numeric_column(all_numeric(), normalizer_fn = scaler_standard()) %&gt;%
    fit()
  
  spec
  
  layer &lt;- layer_dense_features(
    feature_columns = dense_features(spec),
    dtype = tf$float32
  )
  layer(train_df)
  input &lt;- layer_input_from_dataset(train_df %&gt;% select(-label))
  
  output &lt;- input %&gt;% 
    layer_dense_features(dense_features(spec)) %&gt;% 
    layer_dense(units = 64, activation = &quot;relu&quot;) %&gt;%
    layer_dense(units = 64, activation = &quot;relu&quot;) %&gt;%
    layer_dense(units = 1) 
  
  model &lt;- keras_model(input, output)
  
  summary(model)
  </code></pre>
  <p>Overall, the code runs just fine and I can train a simple neural network. The exception is being raised when calling <code>layer(train_df)</code>. This, however, seems to have no impact on the overall model construction.</p>