Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'list' object not callable
#1
hi
i am new to python. iam working on lstm model. i want to plot graph of loss and accuracy. i know that model history is saved. i have used below code.
var1=history. history['loss'] plt.plot(var1)

but I got an error.

plt.plot(var1)
Traceback (most recent call last):
File "<ipython-input-124-f96da71a5192>", line 1, in <module>
plt.plot(var1)
TypeError: 'list' object is not callable

please help me in removing this error. thank you.
Reply
#2
It looks like you expect plt to be an object that has a plot() method. But instead it's just a list. Possibly you are create plt incorrectly. Without seeing the code, we cannot guess.
Reply
#3
(Nov-28-2020, 06:43 PM)bowlofred Wrote: It looks like you expect plt to be an object that has a plot() method. But instead it's just a list. Possibly you are create plt incorrectly. Without seeing the code, we cannot guess.

model = Sequential() model.add(LSTM(lstm_units, input_shape=(num_timestamps,1))) model.add(Dense(dense_units, activation='relu')) model.add(Dense(dense_units, activation='relu')) model.add(Dense(dense_units, activation='relu')) model.add(Dense(num_classes, activation='softmax')) model.compile(loss=tf.keras.losses.categorical_crossentropy, optimizer='adam', metrics=['accuracy']) print('Model compiled successfully') # --- Fit model history=model.fit(train_X, train_Y ,epochs=epochs, batch_size=batch_size, verbose=1, validation_split=0.2) print('Model fit successfully') .... accuracy = model.evaluate(test_X, test_Y, batch_size=batch_size, verbose=1) print('Evaluation of the model completed') print(accuracy[1]*100, 'percent') plt.plot(history.history['loss']) plt.plot(history.history['val_loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'test'], loc='upper left') plt.show() plt.plot(history.history['accuracy']) plt.plot(history.history['val_accuracy']) plt.title('model accuracy') plt.ylabel('accuracy') plt.xlabel('epoch') plt.legend(['train', 'test'], loc='upper left') plt.show()
Reply
#4
Still not enough. Nowhere in that code is plt assigned. It's used on line 18, but it must be assigned somewhere before that. You would get a different error if that were all your code.
Reply
#5
(Nov-28-2020, 09:46 PM)bowlofred Wrote: Still not enough. Nowhere in that code is plt assigned. It's used on line 18, but it must be assigned somewhere before that. You would get a different error if that were all your code.

import csv import numpy as np from pandas import read_csv import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense from tensorflow.keras.layers import LSTM from tensorflow.keras.callbacks import TensorBoard import matplotlib.pyplot as plt model = Sequential() model.add(LSTM(lstm_units, input_shape=(num_timestamps,1))) model.add(Dense(dense_units, activation='relu')) model.add(Dense(dense_units, activation='relu')) model.add(Dense(dense_units, activation='relu')) model.add(Dense(num_classes, activation='softmax')) model.compile(loss=tf.keras.losses.categorical_crossentropy, optimizer='adam', metrics=['accuracy']) print('Model compiled successfully') # --- Fit model history=model.fit(train_X, train_Y ,epochs=epochs, batch_size=batch_size, verbose=1, validation_split=0.2) print('Model fit successfully') .... accuracy = model.evaluate(test_X, test_Y, batch_size=batch_size, verbose=1) print('Evaluation of the model completed') print(accuracy[1]*100, 'percent') plt.plot(history.history['loss']) plt.plot(history.history['val_loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'test'], loc='upper left') plt.show()
Reply
#6
Are these two separate pieces of code? Your first post (with the error) has lines in it that aren't found elsewhere. I asked to understand more of what was happening in the first code, but the other listings seem to be something else.

What's the relationship between the lines with the error and the rest of the code you've posted?

In your initial error, the problem is that instead of just being the import of matplotlib.pyplot, plt was probably reassigned to a list. Don't do that and the error shouldn't happen. The actual place it's happening isn't in any of the code that's been posted.
ndc85430 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 4,817 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
  how to capitalize letter in list object Python iwonkawa 4 2,032 May-29-2024, 04:29 PM
Last Post: DeaD_EyE
  error in class: TypeError: 'str' object is not callable akbarza 2 2,854 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  TypeError: 'NoneType' object is not callable akbarza 4 19,709 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 8,420 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 3,260 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 2,528 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  'SSHClient' object is not callable 3lnyn0 1 2,439 Dec-15-2022, 03:40 AM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 4,737 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  add object and name in list 3lnyn0 4 2,960 Nov-24-2022, 07:33 PM
Last Post: buran

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.