Errata

Low-Code AI

Errata for Low-Code AI

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
PDF Page 209
source code in the middle of the page

The imputation code at page 209 is wrong and do not comply with statements in the text. My experiments shows that plot generated using code present in book result to different plot than the plot shown at fig 7-6. Original code in book:

df_2['AvgMonthlyCharge'] = (df_2['TotalCharges'].div(df_2['tenure']).replace(np.nan,0))
df_2['DiffCharges'] = df_2['MonthlyCharges']-df_2['AvgMonthlyCharge']
df_2['DiffCharges'].describe()

At first line: in case of nan value, it replaces AvgMonthlyCharge by 0, not a MonthlyCharges (which is non-zero, even customer did not pay anything yet).
At second line it efficiently computes diff MonthlyCharger - 0 (because AvgMonthlyCharge is zero from previous line) and thus difference is not computed as 0, but just MonthlyCharges are promoted to DiffCharges which does not make sense.

One possible approach of making imputation correct:

df_2["AvgCharges"] = df_2["TotalCharges"].div(df_2["tenure"])
df_2["AvgCharges"] = np.where(df_2['AvgCharges'] == np.nan, df_2['MonthlyCharges'], df_2['AvgCharges'])
df_2["DiffCharges"] = df_2["MonthlyCharges"] - df_2["AvgCharges"]
df_2["DiffCharges"].describe()

this code later result to the same plot as shown in fig 7-6.

Anonymous  Mar 19, 2024