EXERCISE
1Polynomial regression has the same trap as linear — if there is no pattern, fitting a curve just makes your mistakes fancier.
Save
A beautifully curved line through random noise is art, not science. Always check R² before trusting a polynomial model.
Good fit — clear pattern:
import numpy
from sklearn.metrics import r2_score
x = [1,2,3,5,6,7,8,9,10,12,13,14,15,16,18,19,21,22]
y = [100,90,80,60,60,55,60,65,70,70,75,76,78,79,90,99,99,100]
mymodel = numpy.poly1d(numpy.polyfit(x, y, 3))
print(f"R²: {round(r2_score(y, mymodel(x)), 4)}")
# Output: R²: 0.9433
# 94% explained → excellent, use this model ✅
Bad fit — random data:
import numpy
from sklearn.metrics import r2_score
x = [89,43,36,36,95,10,66,34,38,20,26,29,48,64,6,5,36,66,72,40]
y = [21,46,3,35,67,95,53,72,58,10,26,34,90,33,38,20,56,2,47,15]
mymodel = numpy.poly1d(numpy.polyfit(x, y, 3))
print(f"R²: {round(r2_score(y, mymodel(x)), 4)}")
# Output: R²: 0.0100
# 1% explained → useless, do NOT use this model ❌
R² reference table:
| R² Value | Quality | Verdict |
|---|---|---|
| > 0.90 | Excellent | Ship it |
| 0.70 – 0.90 | Good | Useful with caveats |
| 0.40 – 0.70 | Moderate | Investigate other approaches |
| < 0.40 | Poor | This model is not helpful |
> 💡 Key Insight: A high R² does not automatically mean a good model. If you increase the polynomial degree enough, R² will approach 1.0 — but the model will be memorising noise (). The test: does the model predict NEW data well, or only the data it trained on? That question leads directly to train/test splitting, which you will learn in Unit 7.