/W07
实验Lab: Explore California housing
- Dataset
- California housing (20,640 districts, 1990 US Census)
- Time
- 3 hours
- Before you start
- slides ch 9 quiz ch 9 notebook (opens in a new tab)
This week you'll be able to
- Run a structured EDA: shape, distributions, relationships, target, data quality.
- Spot a confounder or a Simpson-style reversal and show it with a grouped view.
- Choose a chart for a question and write the finding in one sentence.
Goal
Run a structured exploratory analysis and write it up as findings a stakeholder could act on. Find the data problems before any model does.
Data
One row per census block group in California, from the 1990 US Census. The target, MedHouseVal, is the median house value in units of $100,000. It ships with scikit-learn and downloads on first use.
from sklearn.datasets import fetch_california_housing
housing = fetch_california_housing(as_frame=True).frame
housing.describe()Tasks
- Profile the table in five minutes (Procedure 9.1). Note anything odd before you plot anything.
- Plot the distribution of every numeric column (Procedure 9.3). Two columns pile up at their maximum. Find them and count the rows. What does that do to a model that predicts house value?
- Look at
AveRooms,AveBedrmsandAveOccup. Find the extreme values (Procedure 9.5). Are they errors or real places? - Compute and plot the correlation matrix (Procedure 9.4). Which feature is most related to the target? Which two features are nearly redundant?
- Plot house value against longitude and latitude. Describe the spatial pattern in two sentences.
- Split income into quintiles. Compare house value across them with box plots (Procedure 9.6).
- Write five findings. Each one gets one chart and one sentence. At least one must be a data-quality warning.
Deliverable
A short EDA report: the five findings, their charts, and a list of the data issues a model must handle.
Done when
- Both capped columns are found, with counts.
- Every chart has a title, labelled axes, and units.
- Each finding is one sentence a non-specialist could read.
Stretch
Fit a quick linear model of house value on income alone. Plot its residuals against the capped values. Show how the cap biases the fit.