
More Data Won't Fix Every Model: Reading Bias and Variance from Learning Curves
- كاتب موثّق
محتويات المقال
The common misconception
"More data beats a cleverer algorithm" is a popular saying, and large models keep improving as their datasets grow. It's exactly the right fix for : the scikit-learn user guide lists more training data as a way to reduce variance. Data feels like the safe investment. It doesn't require changing the model, or even understanding why it fails.
What actually happens
Two ways to be wrong
Why rows can't fix bias
make_friedman1, a known nonlinear function that includes 10 * sin(pi * x0 * x1) and 20 * (x2 - 0.5) ** 2. A linear regression on the raw features predicts a weighted sum of them, and no weighted sum bends like a sine or a parabola. Extra rows only pin down the best flat approximation more precisely. The guide puts it plainly: collect more training data only if the true function is too complex to be approximated by an estimator with a lower variance.
Read it from a learning curve
learning_curve computes it with cross-validation, so you can run the "what if we had more data?" experiment on subsets of the data you already have.
from sklearn.datasets import make_friedman1from sklearn.linear_model import LinearRegressionfrom sklearn.model_selection import train_test_splitX, y = make_friedman1(n_samples=10000, n_features=5, noise=1.0, random_state=0)X_pool, X_test, y_pool, y_test = train_test_split( X, y, test_size=2000, random_state=0)# "The model is weak, so label 4x more data. Then 4x more."for n in [400, 1600, 6400]: model = LinearRegression().fit(X_pool[:n], y_pool[:n]) print(f"{n:>5} rows test R^2 {model.score(X_test, y_test):.3f}")# 400 rows test R^2 0.725# 1600 rows test R^2 0.730# 6400 rows test R^2 0.732from sklearn.datasets import make_friedman1from sklearn.linear_model import LinearRegressionfrom sklearn.model_selection import ShuffleSplit, learning_curvefrom sklearn.pipeline import make_pipelinefrom sklearn.preprocessing import PolynomialFeaturesfrom sklearn.tree import DecisionTreeRegressorX, y = make_friedman1(n_samples=10000, n_features=5, noise=1.0, random_state=0)cv = ShuffleSplit(n_splits=5, test_size=2000, random_state=0)models = {"linear": LinearRegression(), "deep tree": DecisionTreeRegressor(random_state=0), "cubic": make_pipeline(PolynomialFeatures(3), LinearRegression())}for name, model in models.items(): _, train, val = learning_curve(model, X, y, cv=cv, train_sizes=[400, 1600, 6400]) t, v = train.mean(axis=1), val.mean(axis=1) print(f"{name:<9} train {t[0]:.3f} -> {t[-1]:.3f}" f" validation {v[0]:.3f} -> {v[1]:.3f} -> {v[-1]:.3f}")# linear train 0.716 -> 0.722 validation 0.723 -> 0.726 -> 0.727# deep tree train 1.000 -> 1.000 validation 0.597 -> 0.723 -> 0.802# cubic train 0.962 -> 0.957 validation 0.946 -> 0.954 -> 0.956LinearRegression, fed powers and products of the features up to degree 3, scores 0.946 with just 400 rows. Its learning curve is almost flat too, but high: there's little left to gain from rows or from a cleverer model.
Flat curves tell you to stop
Variance has cheaper fixes too
How to apply it in your project
Plot the curve before buying data Run learning_curveon your current data with several training sizes, using the same metric you report.Read the gap first Small gap, low scores: bias. Large gap: variance. A training score near perfect with a low validation score is variance, whatever the dataset size. Fix bias with capacity and features Try a more flexible model family, add features such as polynomial or spline terms, or lower the regularization. Re-plot: the curves should rise together. Fix variance with data or constraints More rows, stronger regularization, tree limits such as min_samples_leaf, or bagging. Re-plot: the gap should shrink.Look for new information when both plateau If every model flattens at the same level, ask what signal is missing from the columns, not how many rows to add.
Key takeaways
More training data reduces variance; it leaves bias untouched. A learning curve shows which one you have: low, converged scores mean bias; a wide, closing gap means variance. In the example, 6,400 rows lifted a linear model from 0.725 to 0.732, while better features reached 0.946 with 400. When every model plateaus at the same level, look for new features, not more rows.
التعليقات (0)