Skip to content

Commit

Permalink
matplotlib 3.4 compat
Browse files Browse the repository at this point in the history
rasbt committed May 26, 2021
1 parent 0460d56 commit 0bbd87a
Showing 3 changed files with 167 additions and 58 deletions.
178 changes: 133 additions & 45 deletions ch03/ch03.ipynb

Large diffs are not rendered by default.

47 changes: 34 additions & 13 deletions ch03/ch03.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
from sklearn.metrics import accuracy_score
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
import matplotlib
from distutils.version import LooseVersion
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.linear_model import SGDClassifier
@@ -103,9 +105,9 @@



print('Label counts in y:', np.bincount(y))
print('Label counts in y_train:', np.bincount(y_train))
print('Label counts in y_test:', np.bincount(y_test))
print('Labels count in y:', np.bincount(y))
print('Labels count in y_train:', np.bincount(y_train))
print('Labels count in y_test:', np.bincount(y_test))


# Standardizing the features:
@@ -153,6 +155,8 @@



# To check recent matplotlib compatibility


def plot_decision_regions(X, y, classifier, test_idx=None, resolution=0.02):

@@ -176,7 +180,7 @@ def plot_decision_regions(X, y, classifier, test_idx=None, resolution=0.02):
plt.scatter(x=X[y == cl, 0],
y=X[y == cl, 1],
alpha=0.8,
c=colors[idx],
color=colors[idx],
marker=markers[idx],
label=cl,
edgecolor='black')
@@ -186,15 +190,27 @@ def plot_decision_regions(X, y, classifier, test_idx=None, resolution=0.02):
# plot all examples
X_test, y_test = X[test_idx, :], y[test_idx]

plt.scatter(X_test[:, 0],
X_test[:, 1],
c='',
edgecolor='black',
alpha=1.0,
linewidth=1,
marker='o',
s=100,
label='test set')

if LooseVersion(matplotlib.__version__) < LooseVersion('0.3.4'):
plt.scatter(X_test[:, 0],
X_test[:, 1],
c='',
edgecolor='black',
alpha=1.0,
linewidth=1,
marker='o',
s=100,
label='test set')
else:
plt.scatter(X_test[:, 0],
X_test[:, 1],
c='none',
edgecolor='black',
alpha=1.0,
linewidth=1,
marker='o',
s=100,
label='test set')


# Training a perceptron model using the standardized training data:
@@ -754,3 +770,8 @@ def error(p):








Binary file modified ch03/tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0bbd87a

Please sign in to comment.