Errata

Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow

Errata for Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date Submitted
O'Reilly learning platform Page Chapter 6: Decision Trees, section Regression
Figure 6-5

Figure 6-5 was changed in the 3rd edition of the book, now the figure does not fit the text above and Figure 6-4 any more (the x-values do not match).

Antje Muntzinger  Apr 05, 2024 
O'Reilly learning platform Page Polynomial Regression
Warning box

The formula for the number of polynomial features should be (n+d)!/(d!n!)-1 instead of (n+d)!/(d!n!). For example, for a polynomial of degree d=2 with n=1 feature x, we get 2 features (x and x^2), not 3. The reason is that we subtract the bias term 1, so the original formula is changed here.

Antje Muntzinger  Apr 05, 2024 
Printed Page 314
2nd paragraph

The code `housing = fetch_california_housing()`, and subsequent code `fashion_mnist = tf.keras.datasets.fashion_mnist.load_data()` (on p.318, ~3rd paragraph), will not work in all circumstances. It fails on macos 13.6.4 running Python 3.11.8, with the following error:

URL fetch failure ...certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1006)

This can be fixed by running the following code prior to `housing = fetch_california_housing()`:

import os, ssl
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and
getattr(ssl, '_create_unverified_context', None)):
ssl._create_default_https_context = ssl._create_unverified_context

Paul Maurizio  Mar 11, 2024 
O'Reilly learning platform Page Select a Performance Measure
Equation 2-1

I agree with Valerio's Jan 09, 2024 submission, there is a missing open parenthesis in this equation, and I'm assuming (as Valerio did) that it should've been before the h.

Dave Smith  Jan 10, 2024 
O'Reilly learning platform Page Select a Performance Measure
Equation 2-1

missing parenthesis before h

Valerio  Jan 09, 2024 
PDF Page 205
Figure 6-5

The boundaries showed in the Figure 6-5 are different from what you can find in DT nodes of Figure 6-4. I ran the Python notebook to see if the two images have the same boundaries and in that case everything is correct!

Lorenzo  Jan 02, 2024 
Printed Page 47
Figure 2-4: Your notebook in Google Colab

Figure contents out of sync with Github version

Morten Hoffmann  Nov 15, 2023 
Other Digital Version 587
First paragraph


In the spanish translation:

(25.000 para el entrenamiento y 25.000 para las pruebas)

should be:

(25.000 de sentimiento positivo y 25.000 de sentimiento negativo),

Mario Brito Morales  Oct 29, 2023 
ePub Page Chapter 10, footnote 25
End of the sentence.

The footnote refers to homl.info/extra-anns . However, this notebook (or directory) does not exist on the book github. Is it still "work in progress"? Roland Leners reported a similar issue May 08, 2023.

Anonymous  Sep 13, 2023 
PDF, Other Digital Version Page 389
First paragraph, right under "Power scheduling"

In the digital version, the formula for power scheduling is badly formatted. It appears as:
"η(t) = η0 / (1 + t/s)c."

When it should display:
"η(t) = η0 / (1 + t/s)^c."

Marcos Rodrigo  Sep 01, 2023 
Printed, PDF, Other Digital Version Page 421
Note with a blue bird in the middle of the page

In the note, it says:

"Keras automatically infers the output shape, except when the layer is dynamic (as you will see shortly). In this (rare) case, you need to implement the compute_output_shape() method, which must return a TensorShape object."

However, the "compute_output_shape()" method is not addressed anywhere else on the third edition of this book. In the second edition of the book, most code examples of this chapter (chapter 12) actually included said method, but in the third edition none of the code examples use it (and it is not addressed in the text anywhere else either).

All the code provided in the GitHub repository, as well as in the Google collaboratory, continue to provide an outdated version of the examples displayed in this chapter of the book.

Marcos Rodrigo  Aug 08, 2023 
Printed Page Training Supervision : Unsupervised learning
1st paragraph Page 12, 1st paragraph Page 13

Hello Aurélien.

Thank you for this incredible book.

From page 11 of the printed version of the book, you are presenting unsupervised learning. In this section, there is a mix in the usage of tasks and algorithms that makes me confused.
From my understanding, there are 3 types of tasks in unsupervised learning: Clustering, Dimensionality reduction and Association rules.
Visualization algorithm is part of dimensionality reduction and anomaly detection is part of clustering.
I can be wrong but please can you clarify?

Thank you.

Best Regards.

Franklin Wilfried NDJATHE NDJATHE  Jul 27, 2023 
Printed Page 93
Second paragraph

In the second paragraph on page 93, right below the code it states that the best model is obtained by setting max_features to 8, but the output of the code states it should be set to 6.

Sam  Jul 03, 2023 
Printed Page 104
Last paragraph

The typo appears in Chapter 3: Classification, specifically on page 104. The error is as follows: In the last paragraph of page 104, there is an issue with the wording. The paragraph currently reads as follows: "One pixel's intensity is from 0 to 255 that's right, but 0 indicates white and 255 indicates black in grayscale map." However, the correct phrasing should be: "The pixel intensity ranges from 0 to 255, where 0 indicates black and 255 indicates white in a grayscale map." This correction clarifies the intended meaning and ensures accurate understanding for readers.

Deep  Jun 27, 2023 
Printed Page 420
Code snippet

In the build function, the parent's build method is not called (contrary to what the text says). On Github it is called:
super().build(batch_input_shape) # must be at the end

Roland Leners  Jun 21, 2023 
Printed Page 483
Figure 14-3

In addition to the error reported earlier (stride = 1 and not 2), the accolade representing fw=3 is one unit too large.

Roland Leners  Jun 15, 2023 
Printed Page 390
First line of code

The code does not work because "decay is deprecated in the new Keras optimizer, pleasecheck the docstring for valid arguments, or use the legacy optimizer, e.g., tf.keras.optimizers.legacy.SGD.".

I understand that Power scheduling is replaced by the PolynomialDecay scheduler, though both are only equivalent as long as t/s << 1.

Probably the rest of the chapter on schedulers needs to be adapted as well to the Learning rate schedules API.

Finally it might be useful to specify that a "(training) step" consists of one iteration on one batch. The terms "step" and "iteration" could benefit from a definition somewhere in the book.

Roland Leners  May 10, 2023 
Printed Page 377
3rd paragraph

The homl.info link to extra-anns is broken.

Roland Leners  May 08, 2023 
Other Digital Version chapter 2 - end to end ML project
equations such as RMSE

This may be a Kindle Scribe issue rather than a book format issue but on Kindle Scribe equations such as RMSE dont display correctly. They display correctly on Kindle app for IPad

Ronan Stokes  Apr 27, 2023 
Printed Page 346
Code middle of the page

When running the code (locally):
top3_models = random_search_tuner.get_best_models(num_models=3)
and
best_model = top3_models[0]

I get long lists of warnings, with the following header:

WARNING:tensorflow:Detecting that an object or model or tf.train.Checkpoint is being deleted with unrestored values. See the following logs for the specific values in question. To silence these warnings, use `status.expect_partial()`.

The topic of checkpoints is not addressed in the book and the TF documentation is IMHO too advanced at this stage (introduction to Keras)

Roland Leners  Apr 27, 2023 
Printed Page 410
Second code section

The following two lines produce an „NotFoundError“:

v[0, 1].assign(42)
v[:, 2].assign([0., 1.])

Michael Bühlmann  Apr 20, 2023 
Printed Page 322
First set of code

The example lead me in thinking that the sequence of layer indices (used in model.layers[index]) followed the sequence of layer instantiations. It is true for a Sequential model, but not in general. It got me confused when I analyzed the layers of the example on page 332. Might deserve a footnote.

Roland Leners  Apr 18, 2023 
Printed Page 288
Just above the code snippet

The code looks for a 2% threshold, but the paragraph above (twice) says 4.

The text in the Jupyter notebook on GitHub consistently uses 2.

Peter Drake  Apr 06, 2023 
Printed Page Michael Bühlmann
343

On the line:
tf.summary.histogram("my_hist", data, buckets=50, step=step)
I get an "InvalidArgumentError".

What's wrong?

Michael Bühlmann  Apr 05, 2023 
Printed Page 276
Section on representative images

I am wondering about the benefit of making a detour via representative images instead of using directly the cluster centroids:

log_reg.fit(kmeans.cluster_centers_, y_representative_digits)
log_reg.score(X_test, y_test) #gives 0.869 accuracy

Roland Leners  Apr 03, 2023 
Printed Page 245
Last paragraph

I think that understanding of the reasoning would be improved if the text stated that the singular values of s (as returned by np.linalg.svd() ) are sorted in descending order. I understand that this is the reason why one can select the first principal components for reducing dimensionality.

Roland Leners  Mar 15, 2023 
Printed Page 233
First line

The page break between pages 232 and 233 garbles up the text.

It currently reads:
", and use these (page break) can be used as the input features..."
instead of:
", and use these (page break) as the input features ..."

Roland Leners  Mar 13, 2023 
Printed Page 563
`to_seq2seq_dataset` function code block

To my understanding, the lambda function S should actually be defined as:
>>> lambda S: (S[:, 0], S[:, 1:, target_col])
instead of
>>> lambda S: (S[:, 0], S[:, 1:, 1])
Otherwise, the `to_seq2seq_dataset` function parameter `target_col` is not even used.

Riccardo Trevisan  Mar 09, 2023 
Printed Page 224
Eq. 7-1

There appears to be a mistake in Equation 7-1 as it is missing a denominator.
Thanks!

Haesun Park  Mar 07, 2023 
Printed Page 204
Figure 6-4

I believe that Figure 6-4 is from the 2nd edition, and it is different from the one in the 3rd edition notebook.
Additionally, the explanation below Figure 6-2 needs to be updated to reflect this change.
Thanks!

Haesun Park  Mar 07, 2023 
Printed Page 64
2nd paragraph

Because combination attributes is not added yet, there are 9 numerical attributes.
So, "there are now 11 numerical attributes, you would get 11^2 = 121 plots" should be "there are now 9 numerical attributes, you would get 9^2 = 81 plots".
Thanks

Haesun Park  Mar 07, 2023 
Printed Page 67
below the correlation matrix

Under the correlation matrix, the paragraph says "...The new bedrooms_ratio is much more correlated with median house value than the total number of rooms or bedrooms..."

This is clearly a slight mistake as the bedroom_ratio is the least correlated to the median house value. What was probably meant instead is the rooms_per_house attribute.

Dominik Dekleva  Mar 01, 2023 
Printed Page 220
Last paragraph of "Random Forest" chapter

The text "The random forest algorithm introduces extra randomness when growing trees; etc." is not clear for me. When reading through the sklearn documentation it seems to me that DecisionTreeClassifier() and RandomForestClassifier() behave identically wrt max_features. And, according to the documentation, the default value for max_features of the RandomForestClassifier() is 1.0 and not 'sqrt' like the text seems to imply.

Roland Leners  Feb 27, 2023 
Printed, ePub Page Chapter 3, page 119
the code near the top

>>> y_train_pred_forest = y_probas_forest[:, 1] >= 0.5 # positive proba ≥ 50%
>>> f1_score(y_train_5, y_pred_forest)

Instead of:

>>> y_train_pred_forest = y_probas_forest[:, 1] >= 0.5 # positive proba ≥ 50%
>>> f1_score(y_train_5, y_train_pred_forest)

Kostas Katis  Feb 24, 2023 
Printed Page 215
Last code snippe of "Voting Classifier" section

>>>voting_clf.score(X_test, y_test)
fails because the probability of the SVC estimator reverts to False after execution of the fit() method on the VotingClassifier. To make the code work, I had to instantiate the VotingClassifier (code of page 214) with ('svc', SVC(probability=True, random_state=42)).

I tested this several times and indeed voting_clf.named_estimators_["svc"].probability is reset to False after execution of voting_clf.fit(X_train, y_train).

Roland Leners  Feb 23, 2023 
Printed Page 126,127
last paragraph

Hi,

In the last paragraph on p126 and the first paragraph on p127, `ChainClassifier` should be `ClassifierChain`.

Thank you!

Haesun Park  Feb 23, 2023 
Printed Page 120
Middle of page

Hi,

As you may know, "the number of won duels plus or minus a small tweak(max +- 0.33) to break ties" is true if `break_ties=True`.
But `break_ties` parameter's default value is `False`.
So please add some explanation.

Thanks!

Haesun Park  Feb 23, 2023 
Printed Page 118
Caution block

Hi,

Last sentence of the caution block, "See the extra material... this chapter's notebook for more details".
But there is no extra material in the notebook.

Thanks!

Haesun Park  Feb 23, 2023 
Printed Page 113
2nd paragraph

Hi,

"the function adds a last precision of 0 and a last recall of 1" should be "the function adds a last precision of 1 and a last recall of 0".

Thank you!

Haesun Park  Feb 23, 2023 
Printed Page 112
code block in the middle

Hi,

After `>>> y_some_digits_pred = (y_scores > threshold)`, `>>> y_some_digits_pred` should be added.

Thank you!

Haesun Park  Feb 23, 2023 
Printed Page Throughout the book
E.g. code of page 204

Since v1.17.0, numpy has a new interface for random number generation. It might be appropriate to upgrade the code in the next release of the book with this interface.

Roland Leners  Feb 20, 2023 
Printed Page 204
Figure 6-4

The decision tree in figure 6-4 is inconsistent with figure 6-5 (max_depth=2). The decision tree published on Github is consistent though.

Roland Leners  Feb 20, 2023 
Printed Page Page : 602
Section with the bird ( last second)

While the encoder uses LSTM with 512 unit, in the following section it mentions GRU with 10 units.

This is confusing, I think.

Deniz Turan  Feb 18, 2023 
Printed Page Page : 602
Section with the bird ( last second)

While the encoder uses LSTM with 512 unit, in the following section it mentions GRU with 10 units.

This is confusing, I think.

Anonymous  Feb 18, 2023 
Printed Page p92
In a TIP

Hi Aurelien,

I think `memory` of `Pipeline` class is just parameter, not hyperparameter.

Thanks!

Haesun Park  Feb 16, 2023 
Printed Page p91, p92
Middle of page

Hi Aurelien,

(p91, p92) In the middle of page,

I suggest to change `RandomForest` --> `RandomForestRegressor`

Thank you!

Haesun Park  Feb 16, 2023 
Printed Page p86
1st paragraph under the TIP

Actually, make_column_selector is a class, not a function.
So I suggest that

"make_column_selector() function" --> "make_column_selector class"
Two "selector function" --> "selector"

Thank you!

Haesun Park  Feb 16, 2023 
Printed Page p71
footnote 11

(p71) In footnote,

sklearn.set_config(pandas_in_out=True) --> sklearn.set_config(transform_output="pandas")

Thank you! :)

Haesun Park  Feb 16, 2023 
Printed Page 828
Last entry in the index on the page

Incomplete reference in index: sklearn.model_selection.RandomizedSearchCV is already introduced on pages 93/94 (in addition to p. 248)

Roland Leners  Feb 16, 2023 
Printed Page 96
Last paragraph

Student's t-distribution is used to compute the confidence interval for the generalization error i.e. the mean of the squared errors. I understand that this would require the squared errors to follow a normal distribution (see e.g. Wikipedia's page on Student's t-distribution). However they do not. The data has a cut-off at 0 and a long tail towards high values.

Do I miss something here?

Roland Leners  Jan 26, 2023 
Page Equation typesetting in various chapters
Equations: 2-1 (notation box), 4-11, 5-3, 6-4, 7-1, 11-1, 14-1, 16-1, 18-4

When viewed in portrait mode on an iPad, these long equations do not "collapse" within a scrollable box in the body text like other long equations do. Instead, they overflow outside of the body text area, causing margins to be rendered from the end of those equations rather than from the body text, leading to very large actual margins around the body text. It's possible I missed some other problematic equations, these just happened to be the longest/most obvious ones overflowing from the body text.


Notably, this is not an issue on my Android phone which forces all these equations to scroll. The issue might be related to how the equation rendering works on screens of a certain medium-to-large size (large enough to be considered tablet displays and render the full equations rather than scrolled versions, but not large enough in practice to fit the full equations). Maybe this is something that can be fixed in the text markup, or maybe it's a larger rendering issue in the iOS app.

Note from the Author or Editor:
Thanks for your feedback. I reported this formatting issue to O'Reilly, they are looking into it.

Rasmi Elasmar  Dec 26, 2022