Ad
How To Solve " NameError: Name 'model' Is Not Defined " Error?
While trying to predict the output I am facing the error NameError: name 'model' is not defined
. How to solve this.
%%time
# Lstm
model = Sequential()
model.add(LSTM(data_dim, input_shape=(95,data_dim), activation='relu'))
model.add(Dense(data_dim))
model.compile(loss='mse', optimizer='adam')
model.fit(X_train, y_train, epochs=10, batch_size=96)
model.summary()
The above model trained well. While trying model.predict(X_test1)
, I am having the issue mentioned above.
Ad
Answer
The issue lies in the magic function %%time
. In the latest version of IPython in Jupyter, running a cell with time
magic function as a header runs the cell out of the global context. This is also true for %%timeit
.
Practically it means that all the new variables defined in the %%time
cell do not exist in the main context, including your model
variable, which is why you receive the NameError exception, since the interpreter can not find a variable named model
.
Removing the %%time
line from your cell will do the trick.
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad