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

TOI 700 e
  • 197
  • 1
  • 3
  • 18
  • Please include the full error message in your question. – DYZ Jul 01 '20 at 05:34
  • Restart Kerner and Clear All Output, run your code, and see if it still does the same thing. Also, change `plt.legend( [plt_train_acc,plt_val_acc], [train_acc,val_acc], )` to just `plt.legend()`. – Trenton McKinney Jul 01 '20 at 05:49
  • If that doesn't resolve the issue, then you'll need to [create a reproducible copy of the DataFrame with `df.head(10).to_clipboard(sep=',')`](https://stackoverflow.com/questions/52413246/how-to-provide-a-copy-of-your-dataframe-with-to-clipboard), [edit] the question, and paste the clipboard into a code block or include synthetic data: [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Trenton McKinney Jul 01 '20 at 05:52

2 Answers2

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()
Mehedee Hassan
  • 133
  • 1
  • 9
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'.