"Learning by moving with new Python! Machine learning textbook" by Makoto Ito! Use the second edition When I updated numpy to the latest version 1.18.2, an error occurred. 1.18.x is NG (It also occurred in 1.18.4 when trying to run on Google Colaboratory). There is also keras
Usage environment (version):
Mac Book 2016 3.3GHz Intel Corei7 Catalina 10.15.4
Anaconda 1.9.12 JupyterLab 1.2.6 JupyterNotebook 6.0.3 Colaboratory Python 3.7.3, 3.6.9(colab) Numpy 1.18.1,2,4 (colab) Matplotlab 3.1.3, 3.2.1(colab) Tensorflow 2.0.0, 2.2.0rs4(colab) Keras 2.3.1
No problem with version 1.17.2. (1.17.x is OK)
Where you need to change
Before change: np.reshape (xx1, xn * xn, ** 1 **) After change: np.reshape (xx1, xn * xn, ** order = "F" **): Previously recommended
References [numpy.reshape version1.18.x: ValueError: Non-string object detected for the array ordering. Please pass in'C','F','A', or'K' instead error](https: // qiita .com / hiroshim021 / items / ed25fe98a6c1463a4c96)
#Listing 4-5-(3)
#Contour line display--------------------------------
def show_contour_gauss(mu, sig):
Omitted
xx0, xx1 = np.meshgrid(x0, x1)
x = np.c_[np.reshape(xx0, xn * xn, order="F"), np.reshape(xx1, xn * xn, order="F")] #After change
#3D display----------------------------------
def show3d_gauss(ax, mu, sig):
On the way
xx0, xx1 = np.meshgrid(x0, x1)
x = np.c_[np.reshape(xx0, xn * xn, order="F"), np.reshape(xx1, xn * xn, order="F")] #After change
Fixing the KeyError: 'acc' and KeyError: 'val_acc' Errors in Keras 2.3.x
After the 2.3.x release of Keras, when "accuracy" is used in melitexs, "accuracy" is used as the key. The same is true for ** val_accuracy **.
According to the 2.3.0 Release Notes: "Metrics and losses are now reported under the exact name specified by the user (e.g. if you pass metrics=['acc'], your metric will be reported under the string "acc", not "accuracy", and inversely metrics=['accuracy'] will be reported under the string "accuracy"." You can read the official release notes here: https://github.com/keras-team/keras/releases/tag/2.3.0
What this means is that if you specify metrics=["accuracy"] in the model.compile(), then the history object will have the keys as 'accuracy' and 'val_accuracy'. While if you specify it as metrics=["acc"] then they will be reported with the keys 'acc' and 'val_acc'.
#Listing 7-2-(4)
"""Accuracy display"""
plt.subplot(1,3,2)
plt.plot(history.history['accuracy'],"k",label="training")
plt.plot(history.history["val_accuracy"],"cornflowerblue",label="test")
plt.legend()
Recommended Posts