Plot two variables against each other and let your eyes do what statistics alone cannot — see the relationship.
Save
Complete lesson & earn 250 PX
EXERCISE
1A scatter plot lets you see the relationship between two variables — each dot is one data point plotted on an x-y grid.
Save
EXERCISE
2With thousands of data points, scatter plots reveal patterns that are invisible in small samples.
Save
EXERCISE
3The scatter plot is not the answer — it is the question. The shape you see determines which model you should try.
Save
A scatter plot is like a connect-the-dots puzzle without the lines. Each dot represents one observation, and your eyes naturally start seeing patterns — lines, curves, clusters, or nothing at all.
Your first scatter plot:
import matplotlib.pyplot as plt
x = [5, 7, 8, 7, 2, 17, 2, 9, 4, 11, 12, 9, 6]
y = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86]
plt.scatter(x, y)
plt.xlabel("Car Age (years)")
plt.ylabel("Speed (km/h)")
plt.title("Car Age vs Speed")
plt.show()
# Output: A scatter plot showing that newer cars tend to be faster
Reading the plot:
| What You See | What It Means |
|---|---|
| Dots trend downward ↘ | Negative relationship (as x↑, y↓) |
| Dots trend upward ↗ | Positive relationship (as x↑, y↑) |
| Dots form a random cloud | No clear relationship |
| Dots follow a curve | Non-linear relationship |
> 💡 Key Insight: Before running any ML algorithm, always plot your data first. A 30-second scatter plot can reveal patterns, outliers, and nonlinear relationships that no amount of statistical calculations can show. Always visualise before you model.
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.
A scatter plot is like a diagnostic scan before surgery. You do not operate based on a guess — you look at the scan, identify the problem, and choose the right tool. In ML, the scatter plot tells you which algorithm to try.
The decision process:
import matplotlib.pyplot as plt
# Scenario 1: Linear pattern → use linear regression
x1 = [1, 2, 3, 4, 5, 6, 7, 8]
y1 = [2, 4, 5, 4, 5, 7, 8, 9]
plt.scatter(x1, y1)
plt.title("Linear trend → try linear regression")
plt.show()
# Output: Dots rising in a rough line
import matplotlib.pyplot as plt
# Scenario 2: Curved pattern → use polynomial regression
x2 = [1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 21, 22]
y2 = [100, 90, 80, 60, 60, 55, 60, 65, 70, 70, 75, 76, 78, 79, 90, 99, 99, 100]
plt.scatter(x2, y2)
plt.title("Curved trend → try polynomial regression")
plt.show()
# Output: Dots following a U-shape curve
The ML practitioner checklist after seeing a scatter plot:
> 💡 Key Insight: In the next two units, you will turn the patterns you see in scatter plots into actual models. Linear regression draws a line through a linear pattern. Polynomial regression draws a curve through a curved pattern. The scatter plot is always your starting point — never skip it.
A scatter plot shows each data point as a dot on an x-y grid. Patterns in the dots reveal relationships between variables.