| Father height | n | Mean son height |
|---|---|---|
| 59 | 4 | 64.7 |
| 61 | 16 | 65.5 |
| 63 | 77 | 66.3 |
| 65 | 208 | 67.5 |
| 67 | 276 | 68.2 |
| 69 | 275 | 69.5 |
| 71 | 152 | 70.2 |
| 73 | 63 | 71.4 |
| 75 | 7 | 71.6 |
EDA for Machine Learning
Given information about one variable, what can we say about another?
Example: If we know a father’s height, what can we predict about his son’s height?
This leads to the concept of conditional distributions.
Figure 1: Heights of father-son pairs
Figure 2: Son’s height distribution for each father height interval
The conditional expectation \(E(Y | X)\) is the average value of \(Y\) given \(X\).
| Father height | n | Mean son height |
|---|---|---|
| 59 | 4 | 64.7 |
| 61 | 16 | 65.5 |
| 63 | 77 | 66.3 |
| 65 | 208 | 67.5 |
| 67 | 276 | 68.2 |
| 69 | 275 | 69.5 |
| 71 | 152 | 70.2 |
| 73 | 63 | 71.4 |
| 75 | 7 | 71.6 |
Figure 3: Conditional mean of son’s height given father’s height
The graph of averages is approximately linear.
This suggests we can approximate the conditional expectation with a straight line.
→ The regression line
To compare variables on different scales, convert to standard units (z-scores):
\[Z_x = \frac{X - \mu_x}{\sigma_x}\]
Interpretation: Number of standard deviations above or below the mean.
In practice, we use sample estimates:
\[\hat{Z}_x(x_k) = \frac{x_k - \bar{x}}{s_x}\]
where \(\bar{x}\) is the sample mean and \(s_x\) is the sample standard deviation.
The SD line passes through the point of averages with slope \(\frac{s_y}{s_x}\):
\[y = \bar{y} + \frac{s_y}{s_x}(x - \bar{x})\]
Equivalently: \(\hat{Z}_y = \hat{Z}_x\)
Property: Minimizes sum of squared perpendicular distances to points.
The regression line has slope \(r \cdot \frac{s_y}{s_x}\):
\[y = \bar{y} + r \frac{s_y}{s_x}(x - \bar{x})\]
Equivalently: \(\hat{Z}_y = r \cdot \hat{Z}_x\)
Property: Minimizes sum of squared vertical distances to points.
Figure 4: Regression line (blue) vs SD line (red)
Both lines pass through \((\bar{x}, \bar{y})\).
The regression line is less steep because \(|r| \le 1\).
This is the mathematical basis of regression to the mean.
\[r = \frac{1}{n-1} \sum_{k=1}^{n} \hat{Z}_x(x_k) \cdot \hat{Z}_y(y_k)\]
Properties:
| Statistic | Value |
|---|---|
| Father mean | 67.70 |
| Son mean | 68.70 |
| Father SD | 2.74 |
| Son SD | 2.81 |
| Correlation r | 0.50 |
With \(r \approx 0.5\), the regression line has about half the slope of the SD line.
For each observation:
Residuals measure how far each point falls from the regression line.
Figure 5: Histogram of regression residuals
Patterns in residuals suggest the model is missing something.
If \((X, Y)\) follows a bivariate normal distribution:
Father-son heights are well approximated by a bivariate normal.
Conditioning on \(X\) reduces the variance of \(Y\):
\[\text{Var}(Y|X) = \sigma_y^2 (1 - r^2)\]
For father-son data with \(r \approx 0.5\):
\[\sqrt{1 - r^2} \approx 0.87\]
Knowing father’s height reduces son’s height SD by about 13%.
The mean and SD are sensitive to outliers.
Alternatives:
| Sensitive | Robust |
|---|---|
| Mean | Median |
| Standard deviation | IQR |
The regression line inherits this sensitivity.
Four data sets with identical summary statistics:
Yet the data look completely different!
Figure 6: Four data sets with identical regression statistics
Always visualize your data!
Summary statistics can hide:
Random variables \((X, Y)\) are independent if:
\[P(X \in A, Y \in B) = P(X \in A) \cdot P(Y \in B)\]
for all sets \(A\) and \(B\).
Implication: Knowing \(X\) tells you nothing about \(Y\).
If \((X, Y)\) are independent, then \(r = 0\).
But the converse is false!
\(r = 0\) only means no linear association.
Variables can be dependent but uncorrelated.
For categorical variables, use the chi-squared test.
Idea: Compare observed counts to expected counts under independence.
\[\chi^2 = \sum_{j,k} \frac{(O_{jk} - E_{jk})^2}{E_{jk}}\]
| handedness | male | female |
|---|---|---|
| right | 934 | 1070 |
| left | 113 | 92 |
| ambi | 20 | 8 |
Is handedness independent of sex?
\(\chi^2 =\) 11.8, df = 2, p-value = 0.0027
Conclusion: Strong evidence against independence.
Males are more likely to be left-handed or ambidextrous.
| Sex | Admission Rate |
|---|---|
| Male | 44.5% |
| Female | 30.4% |
This looks like clear evidence of bias against women.
| Dept | Male % | Female % |
|---|---|---|
| A | 62 | 82 |
| B | 63 | 68 |
| C | 37 | 34 |
| D | 33 | 35 |
| E | 28 | 24 |
| F | 6 | 7 |
Four of six departments admitted women at higher rates!
Women applied disproportionately to departments with low overall admission rates.
Department is a confounding variable.
The aggregate pattern reverses when we condition on department.
A pattern in aggregated data can reverse when data are disaggregated by a relevant variable.
Always ask: Is there a confounding variable I’m missing?
| Variables | Measure |
|---|---|
| Both continuous | Correlation \(r\) |
| Both categorical | Chi-squared \(\chi^2\) |
Both measure departure from independence.
Information theory provides an alternative framework:
These capture nonlinear relationships that correlation might miss.
→ Chapter 6
| Concept | Formula |
|---|---|
| Z-score | \(\hat{Z}_x = \frac{x - \bar{x}}{s_x}\) |
| Regression line | \(\hat{Z}_y = r \cdot \hat{Z}_x\) |
| Correlation | \(r = \frac{1}{n-1}\sum \hat{Z}_x \hat{Z}_y\) |
| Chi-squared | \(\chi^2 = \sum \frac{(O - E)^2}{E}\) |
Given independent standard normal \(X\) and \(Z\), and correlation \(r\):
The UC Berkeley admissions example showed an aggregate bias that reversed within departments.
Construct an example where \(X\) and \(Y\) are statistically dependent but have \(r = 0\).
“Correlation does not imply causation.” When does correlation suggest causation?
In what situations is an aggregated analysis appropriate despite Simpson’s paradox?
How would you explain conditional expectation to a manager?