Skip to content

Commit

Permalink
upd ch02 & ch03
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt committed Jul 8, 2019
1 parent 1691604 commit ff97614
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 134 deletions.
44 changes: 22 additions & 22 deletions ch02/ch02.ipynb

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions ch02/ch02.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def fit(self, X, y):
Parameters
----------
X : {array-like}, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and
X : {array-like}, shape = [n_examples, n_features]
Training vectors, where n_examples is the number of examples and
n_features is the number of features.
y : array-like, shape = [n_samples]
y : array-like, shape = [n_examples]
Target values.
Returns
Expand Down Expand Up @@ -255,7 +255,7 @@ def plot_decision_regions(X, y, classifier, resolution=0.02):
plt.xlim(xx1.min(), xx1.max())
plt.ylim(xx2.min(), xx2.max())

# plot class samples
# plot class examples
for idx, cl in enumerate(np.unique(y)):
plt.scatter(x=X[y == cl, 0],
y=X[y == cl, 1],
Expand Down Expand Up @@ -330,10 +330,10 @@ def fit(self, X, y):
Parameters
----------
X : {array-like}, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and
X : {array-like}, shape = [n_examples, n_features]
Training vectors, where n_examples is the number of examples and
n_features is the number of features.
y : array-like, shape = [n_samples]
y : array-like, shape = [n_examples]
Target values.
Returns
Expand Down Expand Up @@ -417,10 +417,10 @@ def predict(self, X):



ada = AdalineGD(n_iter=15, eta=0.01)
ada.fit(X_std, y)
ada_gd = AdalineGD(n_iter=15, eta=0.01)
ada_gd.fit(X_std, y)

plot_decision_regions(X_std, y, classifier=ada)
plot_decision_regions(X_std, y, classifier=ada_gd)
plt.title('Adaline - Gradient Descent')
plt.xlabel('sepal length [standardized]')
plt.ylabel('petal length [standardized]')
Expand All @@ -429,7 +429,7 @@ def predict(self, X):
# plt.savefig('images/02_14_1.png', dpi=300)
plt.show()

plt.plot(range(1, len(ada.cost_) + 1), ada.cost_, marker='o')
plt.plot(range(1, len(ada_gd.cost_) + 1), ada_gd.cost_, marker='o')
plt.xlabel('Epochs')
plt.ylabel('Sum-squared-error')

Expand Down Expand Up @@ -465,7 +465,7 @@ class AdalineSGD(object):
Weights after fitting.
cost_ : list
Sum-of-squares cost function value averaged over all
training samples in each epoch.
training examples in each epoch.
"""
Expand All @@ -481,10 +481,10 @@ def fit(self, X, y):
Parameters
----------
X : {array-like}, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and
X : {array-like}, shape = [n_examples, n_features]
Training vectors, where n_examples is the number of examples and
n_features is the number of features.
y : array-like, shape = [n_samples]
y : array-like, shape = [n_examples]
Target values.
Returns
Expand Down Expand Up @@ -550,10 +550,10 @@ def predict(self, X):



ada = AdalineSGD(n_iter=15, eta=0.01, random_state=1)
ada.fit(X_std, y)
ada_sgd = AdalineSGD(n_iter=15, eta=0.01, random_state=1)
ada_sgd.fit(X_std, y)

plot_decision_regions(X_std, y, classifier=ada)
plot_decision_regions(X_std, y, classifier=ada_sgd)
plt.title('Adaline - Stochastic Gradient Descent')
plt.xlabel('sepal length [standardized]')
plt.ylabel('petal length [standardized]')
Expand All @@ -563,7 +563,7 @@ def predict(self, X):
# plt.savefig('images/02_15_1.png', dpi=300)
plt.show()

plt.plot(range(1, len(ada.cost_) + 1), ada.cost_, marker='o')
plt.plot(range(1, len(ada_sgd.cost_) + 1), ada_sgd.cost_, marker='o')
plt.xlabel('Epochs')
plt.ylabel('Average Cost')

Expand All @@ -574,7 +574,7 @@ def predict(self, X):



ada.partial_fit(X_std[0, :], y[0])
ada_sgd.partial_fit(X_std[0, :], y[0])



Expand Down
Loading

0 comments on commit ff97614

Please sign in to comment.