0

Here's my code to plot my model accuracies/losses.

    import matplotlib.pyplot as plt
    train_acc, = np.array(hist.history.get('acc'))
    val_acc, = np.array(hist.history.get('val_acc'))
    plt.figure()
    epochs=np.arange(len(train_acc))
    plt_train_acc = plt.plot(epochs,train_acc,'r',label='Train_Acc')
    plt_val_acc = plt.plot(epochs,val_acc,'b',label='Val_Acc')
    plt.title('Acc Trends')
    plt.ylabel('Acc')
    plt.xlabel('Epochs')
    plt.legend( [plt_train_acc,plt_val_acc],
                [train_acc,val_acc], )
    plt.savefig("trendsPlot.jpg")
    plt.show()

But I get "TypeError: 'bool' object is not callable" error for the line plt.legend

3

3 Answers 3

1

I don't know why but I also had to face the same problem sometimes when using 'Jupiter notebook' I had to restart the kernel to use again. You can use axes object of subplots , the sample code is below.

import matplotlib.pyplot as plt1


fig, ax = plt1.subplots(figsize=(5, 3))
ax.plot([1,2,3,4,5,6,7],[44,55,66,77,88,99,11],color='orange',label='real value')
ax.plot([1,2,3,4,5,6,7],[144,155,166,177,188,199,111],color='blue',label='prediction')
ax.legend(bbox_to_anchor=(1, 1), loc='upper left', borderaxespad=0.)
fig.tight_layout()
Sign up to request clarification or add additional context in comments.

Comments

0

I solved this problem by reinstalling 'SciPy'. It not only solved the problem above, but also solved the problem that I can't import 'seaborn' and 'missingno'.

By the way, I was confused that they only happened in 'jupyter notebook', but not in 'spyder' and 'pycharm'.

Comments

0

The reason this happened is that you had erroneously used plt.legend= instead of plt.legend() in the past, this would cause the function to be assigned the value you first inputted and change the function to a variable, that's why it said the function is a bool variable and is not callable, the only way to fix it as far as I'm aware is to restart the kernel to reset the module.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.