EXERCISE
1With thousands of data points, scatter plots reveal patterns that are invisible in small samples.
Save
Small data sets are like looking at a few stars — you cannot see the constellation. But scale to thousands of points and the pattern emerges like a galaxy revealing its spiral arms.
Generating and plotting large data:
import numpy
import matplotlib.pyplot as plt
# X: normal distribution, mean=5, std=1
x = numpy.random.normal(5.0, 1.0, 1000)
# Y: normal distribution, mean=10, std=2
y = numpy.random.normal(10.0, 2.0, 1000)
plt.scatter(x, y, alpha=0.5)
plt.xlabel("X values (mean=5, std=1)")
plt.ylabel("Y values (mean=10, std=2)")
plt.show()
# Output: An oval cloud centred at (5, 10)
# The cloud is wider vertically (std=2) than horizontally (std=1)
What the cloud shape tells you:
import numpy
import matplotlib.pyplot as plt
# CORRELATED data — x and y move together
x = numpy.random.normal(0, 1, 1000)
y = x * 2 + numpy.random.normal(0, 0.5, 1000)
plt.scatter(x, y, alpha=0.5)
plt.title("Correlated: dots form a line")
plt.show()
# Output: Dots form a diagonal band from lower-left to upper-right
| Cloud Shape | Relationship | ML Implication |
|---|---|---|
| Diagonal band ↗ | Strong positive | will work well |
| Diagonal band ↘ | Strong negative | Linear regression will work well |
| Circular cloud | No relationship | Regression is useless here |
| Curved band | Non-linear | Try polynomial regression |
> 💡 Key Insight: The tightness of the scatter plot cloud directly corresponds to the r-value you will learn about in the next unit. A tight diagonal band → r near ±1. A wide cloud → r near 0. You are literally seeing the correlation strength.