Errata

Machine Learning with Python Cookbook

Errata for Machine Learning with Python Cookbook, Second Edition

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
Chapter 23, Section 6
Last Paragraph

there is minor typo here: "while the Python library takes car ("takes care") of all the server ".

Mehran  Jul 02, 2023 
Printed Page p.256
in the middle

'We will discuss handling imbalanced classes during preprocessing in Recipe 17.5.'

This paragraph should refer Recipe 5.5 instead of 17.5.

HIDEMOTO NAKADA  Apr 22, 2024 
Printed Page p.274
comment in the code

"# Search the index for the two nearest neighbors"

"two" should be "ten".

HIDEMOTO NAKADA  Apr 22, 2024 
Printed Page p.278, p.281
comment in the code

"# Create decision tree regression object"

The comment seems to be wrong, since we are not using decision tree regression here.

HIDEMOTO NAKADA  Apr 22, 2024 
Printed Page p.301
in the end

array([[0.31859969, 0.63663466, 0.04476565]])

the above line repeats twice
the first occurence should be

lassifer_sigmoid.predict_proba(new_observation)

HIDEMOTO NAKADA  Apr 22, 2024 
Printed Page p.375
comment in the code

"# Save the model to a directory called `save_model`"

`save_model` should be `saved_model`

HIDEMOTO NAKADA  Apr 22, 2024 
PDF Page p.328
the code

The code creates standard scalar but does not use.
we need to have something like

features = scaler.fit_transform(features)

HIDEMOTO NAKADA  Apr 25, 2024 
PDF Page p.5
in the middle of the code

# Generate a matrix of shape (3,3) containing all ones
matrix = np.full(shape=(3,3), fill_value=1)

the fill_value should be '1.0' instead of '1', since the following output shows that the datatype is floating, not int.

Instead, you could fix the output to int. They have to be consistent.

HIDEMOTO NAKADA  May 20, 2024 
PDF Page p.5
in the middle of the code

# Generate a matrix of shape (3,3) containing all ones
matrix = np.full(shape=(3,3), fill_value=1)

the fill_value should be '1.0' instead of '1', since the following output shows that the datatype is floating, not int.

Instead, you could fix the output to int. They have to be consistent.

HIDEMOTO NAKADA  May 20, 2024 
PDF Page p.95
in the middle.

# Get feature names
feature_names = dictvectorizer.get_feature_names()

get_feature_names is renamed to get_feature_names_out

HIDEMOTO NAKADA  May 20, 2024 
PDF, ePub Page p.114
in the middle

`We can use the get_feature_names method to view the word associated with each feature:`

'get_feature_names' should be 'get_feature_names_out'

HIDEMOTO NAKADA  May 20, 2024 
Printed Page 1.0 Introduction
Page 1 Creating a Vector

I dont believe anything is wrong with the text, my problem is with setting up my Python environment within Visual Studio to facilitate navigating through the examples within the text.
after using GitHub's Cookiecutter extension instructions for the VS setup for Python, a simple library load command "import numpy as np" gave me the following error "An error was encountered while opening associated documents the last time this solution was loaded. Document load is being skipped during this solution load in order to avoid that error."
Python 3.9 (64-bit) interactive window [PTVS 17.0.23189.3-17.0]
Type $help for a list of commands.
>>> 4+4
8
>>> #Load library
... import numpy as np
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ModuleNotFoundError: No module named 'numpy'
>>>

C J Houston  Oct 16, 2023 
Other Digital Version 1.19 Inverting a Matrix
Code snippets

# Multiply matrix and its inverse
matrix @ np.linalg.inv(matrix)
array([[ 1., 0.],
[ 0., 1.]])

Need to call np.round(matrix @ np.linalg.inv(matrix)) to get the desired output.

Vimal Kaur  Apr 11, 2023 
Other Digital Version 3.3 Slicing DataFrames
Code snippets

# Select four rows
dataframe.iloc[1:4]

This selects 3 rows instead of 4 so comment needs to be updated

# Select three rows
dataframe.iloc[:4]
This select 4 rows instead of 3 as comment needs to be updated.

Vimal Kaur  Apr 11, 2023 
Other Digital Version 4.4
Solution, explaination of degree=3

Polynomial features given as:

x1 , x2 , x1^2 , x2^2 , x1^3 , x2^3 , x1^ 2 , x1^3 , x2^3

which should be:

x1, x2, x1^2, x1*x2, x2^2, x1^3, x1^2*x2, x1*x2^2, x2^3

Dhani Prasad  Aug 07, 2023 
Printed Page 26
Section 2.3

The sample data files from the first edition that were hosted on Chris Albon's github repo here (used starting in Chapter 2 and elsewhere in the book) are no longer available.

I'm not sure if these are available directly or there are new links in the Dockerized repo posted by Kyle Gallatin - I was able to successfully mount and run it but Jupyter comes up empty - for us Windows users Docker can be hit-or-miss, and I gave up troubleshooting it. I also think a lot of novice / intermediate Python users (especially students non-Linux readers) will be unfamiliar with it, so a simple location for the sample data would be helpful.

If a new repo is available and links could be posted on the book's resources page that would be awesome, or possibly just zip all the sample files for download and post on the Docker repo - I think it's easy enough even for beginners to change the code from loading from a URL to a local path.

Joe Cat  Nov 30, 2023 
PDF Page 317
code in the end

```
# Select all elements of a vector
vector[:]

array([1, 2, 3, 4, 5, 6])
```

The result should be tensor, instead of array.

HIDEMOTO NAKADA  May 01, 2024 
PDF Page 321
solution code

# Create a two-dimensional tensor
tensor = torch.tensor([[[1,2,3]]])

while the comment says 'two-dimensional' ,
the code actually creates a three-dimensional tensor,
and thus, the results following the code are also affected.

this should be

tensor = torch.tensor([[1,2,3]])

HIDEMOTO NAKADA  May 02, 2024