Skip to content

Commit

Permalink
Merge pull request #1 from rasbt/master
Browse files Browse the repository at this point in the history
Last version of the repository
  • Loading branch information
alexgcsa authored Jan 9, 2021
2 parents 653e4f5 + 0460d56 commit 48fd3e6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
14 changes: 7 additions & 7 deletions ch03/ch03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Labels counts in y: [50 50 50]\n",
"Labels counts in y_train: [35 35 35]\n",
"Labels counts in y_test: [15 15 15]\n"
"Labels count in y: [50 50 50]\n",
"Labels count in y_train: [35 35 35]\n",
"Labels count in y_test: [15 15 15]\n"
]
}
],
"source": [
"print('Labels counts in y:', np.bincount(y))\n",
"print('Labels counts in y_train:', np.bincount(y_train))\n",
"print('Labels counts in y_test:', np.bincount(y_test))"
"print('Labels count in y:', np.bincount(y))\n",
"print('Labels count in y_train:', np.bincount(y_train))\n",
"print('Labels count in y_test:', np.bincount(y_test))"
]
},
{
Expand Down Expand Up @@ -1782,7 +1782,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.8.3"
},
"toc": {
"nav_menu": {},
Expand Down
6 changes: 3 additions & 3 deletions ch03/ch03.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@



print('Labels counts in y:', np.bincount(y))
print('Labels counts in y_train:', np.bincount(y_train))
print('Labels counts in y_test:', np.bincount(y_test))
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))


# Standardizing the features:
Expand Down
23 changes: 17 additions & 6 deletions ch15/ch15_part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -697,18 +697,29 @@
}
],
"source": [
"from distutils.version import LooseVersion as Version\n",
"\n",
"\n",
"####### Binary Crossentropy\n",
"bce_probas = tf.keras.losses.BinaryCrossentropy(from_logits=False)\n",
"bce_logits = tf.keras.losses.BinaryCrossentropy(from_logits=True)\n",
"\n",
"logits = tf.constant([0.8])\n",
"probas = tf.keras.activations.sigmoid(logits)\n",
"\n",
"tf.print(\n",
" 'BCE (w Probas): {:.4f}'.format(\n",
" bce_probas(y_true=[1], y_pred=probas)),\n",
" '(w Logits): {:.4f}'.format(\n",
" bce_logits(y_true=[1], y_pred=logits)))\n",
"if Version(tf.__version__) >= '2.3.0':\n",
" tf.print(\n",
" 'CCE (w Probas): {:.4f}'.format(\n",
" cce_probas(y_true=[[0, 0, 1]], y_pred=probas)),\n",
" '(w Logits): {:.4f}'.format(\n",
" cce_logits(y_true=[[0, 0, 1]], y_pred=logits)))\n",
" \n",
"else:\n",
" tf.print(\n",
" 'CCE (w Probas): {:.4f}'.format(\n",
" cce_probas(y_true=[0, 0, 1], y_pred=probas)),\n",
" '(w Logits): {:.4f}'.format(\n",
" cce_logits(y_true=[0, 0, 1], y_pred=logits)))\n",
"\n",
"\n",
"####### Categorical Crossentropy\n",
Expand Down Expand Up @@ -1260,7 +1271,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.8.2"
}
},
"nbformat": 4,
Expand Down
19 changes: 14 additions & 5 deletions ch15/ch15_part1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pandas as pd
import matplotlib.pyplot as plt
import os
from distutils.version import LooseVersion as Version

# *Python Machine Learning 3rd Edition* by [Sebastian Raschka](https://sebastianraschka.com) & [Vahid Mirjalili](http://vahidmirjalili.com), Packt Publishing Ltd. 2019
#
Expand Down Expand Up @@ -271,11 +272,19 @@ def conv2d(X, W, p=(0, 0), s=(1, 1)):
logits = tf.constant([[1.5, 0.8, 2.1]])
probas = tf.keras.activations.softmax(logits)

tf.print(
'CCE (w Probas): {:.4f}'.format(
cce_probas(y_true=[0, 0, 1], y_pred=probas)),
'(w Logits): {:.4f}'.format(
cce_logits(y_true=[0, 0, 1], y_pred=logits)))
if Version(tf.__version__) >= '2.3.0':
tf.print(
'CCE (w Probas): {:.4f}'.format(
cce_probas(y_true=[[0, 0, 1]], y_pred=probas)),
'(w Logits): {:.4f}'.format(
cce_logits(y_true=[[0, 0, 1]], y_pred=logits)))

else:
tf.print(
'CCE (w Probas): {:.4f}'.format(
cce_probas(y_true=[0, 0, 1], y_pred=probas)),
'(w Logits): {:.4f}'.format(
cce_logits(y_true=[0, 0, 1], y_pred=logits)))

####### Sparse Categorical Crossentropy
sp_cce_probas = tf.keras.losses.SparseCategoricalCrossentropy(
Expand Down
2 changes: 2 additions & 0 deletions errata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

## Chapter 3

- pg. 55 & 56: Says `print('Labels counts ...` in code, but "labels counts" is grammatically wrong and should be "label counts."

- pg. 56: The comment about the `n_iter` method can be ignored as it does not apply to recent scikit-learn versions (0.21 and newer)

- pg. 84: It says "XOR gate using the `logical_or` function from NumPy, " near the bottom, but it should be `logical_xor` instead of `logical_or`
Expand Down

0 comments on commit 48fd3e6

Please sign in to comment.