Learn by running with new Python! Machine learning textbook Makoto Ito numpy / keras Attention!

background

"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

[1] numpy np.shape (xx0, xn * xn, 1) ⇒ order = "F" Must be changed

Occurs in numpy version 1.18.2 or later

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)

1. List 4-5- (3) Page 142 (per)
#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
2. List 7-1- (10) Page 274 (per)
3. List 7-1- (14) Page 294 (per)
4. List 7-2- (4) Page 304 (per)
5. List 9-2- (6) Page 364 (per)

[2] KeyError:'acc' and KeyError:'val_acc' Errors in Keras 2.3.x ⇒ Go to accuracy

References

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'.

6. List 7-2- (4) -page 303

#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

Learn by running with new Python! Machine learning textbook Makoto Ito numpy / keras Attention!
Chapter 6 Supervised Learning: Classification pg212 ~ [Learn by moving with Python! New machine learning textbook]
Chapter 7 [Neural Network Deep Learning] P252 ~ 275 (first half) [Learn by moving with Python! New machine learning textbook]
Chapter 7 [Error back propagation method] P275 ~ (Middle) [Learn by moving with Python! New machine learning textbook]
Machine learning with Python! Preparation
Beginning with Python machine learning
Python learning memo for machine learning by Chainer Chapter 8 Introduction to Numpy
[Machine learning] Try running Spark MLlib with Python and make recommendations
Machine learning with python (1) Overall classification
Machine learning summary by Python beginners
"Gaussian process and machine learning" Gaussian process regression implemented only with Python numpy
"Scraping & machine learning with Python" Learning memo
"Introduction to Machine Learning by Bayesian Inference" Approximate inference of Poisson mixed model implemented only with Python numpy
Machine learning with python (2) Simple regression analysis
[Shakyo] Encounter with Python for machine learning
Python & Machine Learning Study Memo ④: Machine Learning by Backpropagation
Build AI / machine learning environment with Python
Machine Learning with docker (40) with anaconda (40) "Hands-On Data Science and Python Machine Learning" By Frank Kane
[Python] Easy introduction to machine learning with python (SVM)
Machine learning starting with Python Personal memorandum Part2
Machine learning starting with Python Personal memorandum Part1
[Python] Collect images with Icrawler for machine learning [1000 images]
I started machine learning with Python Data preprocessing
Build a Python machine learning environment with a container
Learn collaborative filtering along with Coursera Machine Learning materials
Classify mnist numbers by unsupervised learning with keras [Autoencoder]
Python learning memo for machine learning by Chainer from Chapter 2
Python learning memo for machine learning by Chainer Chapters 1 and 2
Build a machine learning application development environment with Python
Site summary to learn machine learning with English video
Classify anime faces by sequel / deep learning with Keras
Summary of the basic flow of machine learning with Python
Record of the first machine learning challenge with Keras
Learn Python asynchronous processing / coroutines by comparing with Node.js