Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • Thanks for your fast response, I really appreciate that! I am really new to Python and Neural Networks, I don't get exactly what I have to change.. I don't know if that's too much to ask, but would you be so kind and show me what I have to change in the code? Commented May 7, 2020 at 18:30
  • I added a bit more explanation. In order to test or score a model, you must first train it. You already seem to know how to use *.fit, you just need to use that code to train your model during every call of test_and_score. Does it make sense now? Commented May 7, 2020 at 18:43
  • Yes indeed it helped, It is running now. I just don't unterstand, why I should change the return statement of train_and_score to something like return hist.history['val_loss'][-1] ? Could you explain that further? Thanks a lot! Commented May 7, 2020 at 19:51
  • What you had originally test['val_loss'][-1] is attempting to do a dictionary-like hash lookup in the object 'test' of the string 'val_loss'. test is an object of type tf.keras.Model and does not have data stored in a way that can be accessed like that. The error you received said it like this: TypeError: 'Model' object is not subscriptable. On the other hand, the output of model.fit() is a record of training loss values and metrics. Commented May 7, 2020 at 20:50
  • look at returns here tensorflow.org/api_docs/python/tf/keras/Model#fit Commented May 7, 2020 at 20:50