Home>

As shown below, an error occurs when a model is created and trained.
Even if I read the error message, I still don't understand. .
Thanks for your guidance.

#Create model for use in neutral network
model = Sequential ()
model.add (Dense (1000, activation = 'relu'))
model.add (Dense (800, activation = 'relu'))
model.add (Dense (100, activation = 'relu'))
model.add (Dense (1))
# Compile the model
from keras.optimizers import Adam
model.compile (Adam (lr = 1e-3), loss = "mean_squared_error")
#Learning with training data and evaluating with test data (using mean square error)
history = model.fit (x_train_std, y_train, batch_size = 128, epochs = 100, verbose = 1, validation_data = (x_test_std, y_test))

The following is an error message.

-------------------------------------------- -------------------------------
ValueError Traceback (most recent call last)
<ipython-input-32-5a6b2d63d428>in<module>
      1 # Learn with training data and evaluate with test data (using mean square error)
      2
---->3 history = model.fit (x_train_std, y_train, batch_size = 128, epochs = 100, verbose = 1, validation_data = (x_test_std, y_test))
C: \ python \ anaconda \ pgm \ lib \ site-packages \ keras \ engine \ training.py in fit (self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch , steps_per_epoch, validation_steps, ** kwargs)
    950 sample_weight = sample_weight,
    951 class_weight = class_weight,
->952 batch_size = batch_size)
    953 # Prepare validation data.
    954 do_validation = False
C: \ python \ anaconda \ pgm \ lib \ site-packages \ keras \ engine \ training.py in _standardize_user_data (self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
    700 'either a single'
    701 'array or a list of arrays.'
->702 'You passed: y =' + str (y))
    703 # Typecheck that all inputs are * either * value * or * symbolic.
    704 if y is not None:
ValueError: Please provide as model targets either a single array or a list of arrays.You passed: y = MEDV
80 28.0
426 10.2
316 17.8
63 25.0
25 13.9
68 1
  • Answer # 1

    Is it in pandas DF?

    Please change it to a one-dimensional array.