Data Analysis with Python: From Raw Data to Real-World Insights
BOOK 2 · APPLIED ANALYSIS · CHAPTER 14

Chapter 14 exercises: Preparing for Machine Learning and Deep Learning

On this page

Attempt these tasks before opening the worked answers. Use the chapter experiment notebook, or import NumPy as np and Pandas as pd in your own notebook. Retain your first attempt and explain each correction.

B2-14-E01 · Evaluate a numeric baseline

Calculate MAE and RMSE in minutes and verify one error by hand.

actual=np.array([9.,15.,18.]);prediction=np.array([11.,11.,11.])
One hint after an attempt

Start with the three residuals.

B2-14-E02 · Reject preprocessing leakage

Learn the centering value from training only and transform evaluation with it.

train=np.array([10.,20.]);evaluation=np.array([100.,200.])
One hint after an attempt

Record the fitted parameter once.

B2-14-E03 · Align targets by ID

Construct y in the feature-row order and verify [2,1].

features=pd.DataFrame({"id":["b","a"],"x":[20,10]}).set_index("id")
target=pd.Series([1,2],index=["a","b"])
One hint after an attempt

Use the feature index as the target order.

Reflect and get feedback

Explain one result without looking at the code. Identify one boundary case that would change your method. An optional tutor prompt is: “Here is my attempt at B2-14-E03. Give one hint about the violated assumption; do not give the solution yet.” Then use the worked answers.

Teaching edition · verified experiments · PDF and EPUB editions not generated.