rasbt / python-machine-learning-book-3rd-edition

The "Python Machine Learning (3rd edition)" book code repository
https://www.amazon.com/Python-Machine-Learning-scikit-learn-TensorFlow/dp/1789955750/
MIT License
4.6k stars 1.98k forks source link

axis labels of ch07/images/07_11.png #159

Closed niwak01 closed 2 years ago

niwak01 commented 2 years ago

It seems that the positions of the x-label ('Alcohol') and y-label ('OD280/OD315 of diluted wines') are reversed. https://github.com/rasbt/python-machine-learning-book-3rd-edition/blob/master/ch07/images/07_11.png

I am sorry if I am wrong.

niwak01 commented 2 years ago

I would like to write code I think should be corrected.

import numpy as np
import matplotlib.pyplot as plt

x_min = X_train[:, 0].min() - 1
x_max = X_train[:, 0].max() + 1
y_min = X_train[:, 1].min() - 1
y_max = X_train[:, 1].max() + 1

xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.1),
                     np.arange(y_min, y_max, 0.1))

f, axarr = plt.subplots(nrows=1, ncols=2, 
                        sharex='col', 
                        sharey='row', 
                        figsize=(8, 3))

for idx, clf, tt in zip([0, 1],
                        [tree, bag],
                        ['Decision tree', 'Bagging']):
    clf.fit(X_train, y_train)
    Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
    Z = Z.reshape(xx.shape)
    axarr[idx].contourf(xx, yy, Z, alpha=0.3)
    axarr[idx].scatter(X_train[y_train == 0, 0],
                       X_train[y_train == 0, 1],
                       c='blue', marker='^')
    axarr[idx].scatter(X_train[y_train == 1, 0],
                       X_train[y_train == 1, 1],
                       c='green', marker='o')
    axarr[idx].set_title(tt)

**_#axarr[0].set_ylabel('Alcohol', fontsize=12)
axarr[0].set_ylabel('OD280/OD315 of diluted wines', fontsize = 12)_**
plt.tight_layout()
plt.text(0, -0.2,
         **_#s='OD280/OD315 of diluted wines',
         s = 'Alcohol',_**
         ha='center',
         va='center',
         fontsize=12,
         transform=axarr[1].transAxes)

#plt.savefig('images/07_08.png', dpi=300, bbox_inches='tight')
plt.show()
rasbt commented 2 years ago

Ah yes, good catch, you are right! Just updated it! Thanks!