title: Passing a data frame to R Keras model fit
body: <p>I'm trying to fit a model in R using Keras.  The model seems to be created and compiled without any problems.  However, my fit function is giving me the following error:</p>
  <blockquote>
  <p>Error: Data passed to Keras must be a vector, matrix, or array (you passed a data frame)</p>
  </blockquote>
  <p>I've looked at various tutorials and they seem to show the preprocessing very similar to what I'm doing</p>
  <pre><code>library(tensorflow)
  library(caret)
  library(keras)
  library(tidyverse)
  
  data &lt;- read.table(&quot;wdbc.data&quot;, header = FALSE, sep=&quot;,&quot;, stringsAsFactors = FALSE)
  data[data == &quot;?&quot;] &lt;- 0
  data[data == &quot;M&quot;] &lt;- 0
  data[data == &quot;B&quot;] &lt;- 1
  x &lt;- floor(0.6*nrow(data))
  set.seed(0)
  train_ind &lt;- sample(seq_len(nrow(data)), size = x)
  
  train &lt;- data[train_ind,]
  test &lt;- data[-train_ind,]
  
  x_train &lt;- subset(train, select=-c(ID, Class))
  y_train &lt;- train[-c(1, 3:32)]
  x_test &lt;- subset(test, select=-c(ID, Class))
  y_test &lt;- test[-c(1, 3:32)]
  
  max_len &lt;- 3
  batch_size &lt;- 64
  total_epochs &lt;- 5
  
  set.seed(0)
  model &lt;- keras_model_sequential()
  model %&gt;%
      layer_embedding(5000, 64, name = &quot;embedding1&quot;) %&gt;%
      layer_simple_rnn(64, return_sequences = TRUE, name = &quot;simpleRNN1&quot;) %&gt;%
      layer_simple_rnn(64, name = &quot;simpleRNN2&quot;) %&gt;%
      layer_dense(1, activation = &quot;sigmoid&quot;, name = &quot;dense1&quot;)
  
  model %&gt;% compile(loss = 'binary_crossentropy', 
                    optimizer = 'adam', 
                    metrics = c('accuracy'))
  
  x_train &lt;- array_reshape(x_train, c(nrow(x_train), 30))
  x_test &lt;- array_reshape(x_test, c(nrow(x_test), 30))
  
  trainModel &lt;- model %&gt;% fit(
      x = x_train,
      y = y_train,
      batch_size = batch_size,
      epochs = total_epochs,
      validation_split = 0.1)
  </code></pre>
  <p>I'm running this in a Jupyter notebook, so trainModel is in it's own cell.  When I run that cell, I get the error from above.  Here is a more detailed version of the error:</p>
  <pre><code>Error: Data passed to Keras must be a vector, matrix, or array (you passed a data frame)
  Traceback:
  
  1. model %&gt;% fit(x = x_train, y = y_train, batch_size = batch_size, 
   .     epochs = total_epochs, validation_split = 0.1)
  2. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
  3. eval(quote(`_fseq`(`_lhs`)), env, env)
  4. eval(quote(`_fseq`(`_lhs`)), env, env)
  5. `_fseq`(`_lhs`)
  6. freduce(value, `_function_list`)
  7. withVisible(function_list[[k]](value))
  8. function_list[[k]](value)
  9. fit(., x = x_train, y = y_train, batch_size = batch_size, epochs = total_epochs, 
   .     validation_split = 0.1)
  10. fit.keras.engine.training.Model(., x = x_train, y = y_train, 
    .     batch_size = batch_size, epochs = total_epochs, validation_split = 0.1)
  11. keras_array(x)
  12. stop(&quot;Data passed to Keras must be a vector, matrix, or array (you passed a &quot;, 
    .     &quot;data frame)&quot;, call. = FALSE)
  </code></pre>
  <p>Data can be found at <a href="https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/" rel="nofollow noreferrer">https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/</a>
  The first and second columns were named 'ID' and 'Class'</p>