
The Learning Rate Isn't a Speed Knob: How Step Size Makes or Breaks Training
- كاتب موثّق
محتويات المقال
The common misconception
The name suggests it. A higher "rate" of learning sounds like learning the same thing faster. Google's Machine Learning Crash Course itself describes the learning rate as a number that influences how quickly the model converges, and below a certain point that's exactly what you see. Training cost really is the pain point. When a job takes hours, the knob with "rate" in its name is the first thing people reach for.
What actually happens
The learning rate scales every step
Three regimes, not one dial
Too small: each step is tiny, so you need many of them. The Crash Course says such a rate can take too many iterations to converge. About right: you get close to the bottom within a reasonable number of steps, and the loss flattens out. Too big: you step over the bottom to the other side, again and again. The Crash Course describes the model bouncing around the best weights without converging, with a loss that fluctuates or keeps rising. Far too big, and every step overshoots further than the last: the loss explodes.
What it looks like in code
eta0) at four sizes.
from sklearn.datasets import load_diabetesfrom sklearn.linear_model import SGDRegressorfrom sklearn.metrics import mean_squared_errorfrom sklearn.preprocessing import StandardScalerX, y = load_diabetes(return_X_y=True)X = StandardScaler().fit_transform(X)# "Training is slow: raise the learning rate so it finishes sooner"for eta0 in [0.0001, 0.001, 0.1, 1.0]: sgd = SGDRegressor(learning_rate="constant", eta0=eta0, random_state=0) sgd.fit(X, y) # no error, no warning, even when it diverges mse = mean_squared_error(y, sgd.predict(X)) print(f"eta0={eta0:<6} epochs {sgd.n_iter_:<4} training MSE {mse:.4g}")# eta0=0.0001 epochs 184 training MSE 2879# eta0=0.001 epochs 21 training MSE 2879# eta0=0.1 epochs 9 training MSE 4624# eta0=1.0 epochs 6 training MSE 9.336e+25from sklearn.datasets import load_diabetesfrom sklearn.linear_model import LinearRegression, SGDRegressorfrom sklearn.metrics import mean_squared_errorfrom sklearn.preprocessing import StandardScalerX, y = load_diabetes(return_X_y=True)X = StandardScaler().fit_transform(X)exact = mean_squared_error(y, LinearRegression().fit(X, y).predict(X))print(f"exact solution training MSE {exact:.4g}")# Sweep on a log scale; "adaptive" divides the step by 5 when loss stallsfor eta0 in [0.001, 0.01, 0.1, 1.0]: sgd = SGDRegressor(learning_rate="adaptive", eta0=eta0, random_state=0) sgd.fit(X, y) mse = mean_squared_error(y, sgd.predict(X)) print(f"eta0={eta0:<6} epochs {sgd.n_iter_:<4} training MSE {mse:.4g}")# exact solution training MSE 2860# eta0=0.001 epochs 803 training MSE 2874# eta0=0.01 epochs 81 training MSE 2865# eta0=0.1 epochs 87 training MSE 2860# eta0=1.0 epochs 239 training MSE 2862fit returns normally.
"Stopped" doesn't mean "converged"
tol for n_iter_no_change epochs in a row. With a big constant step, the weights keep jumping across the minimum, the loss stops improving, and the stopping rule fires. The run ended early because it got stuck bouncing, not because it arrived.
learning_rate="adaptive", scikit-learn divides the step by 5 each time the stopping criterion is reached, and only stops once the step drops below 1e-6. Big steps early, small steps late: starting at 0.1, it reaches 2860, the same training error as the exact least-squares solution that LinearRegression computes directly.
The best value depends on everything else
How to apply it in your project
Scale your features first Put StandardScalerbefore any gradient-based model in a pipeline, so one learning rate suits every feature.Compare loss, not epochs When you change the learning rate, compare the final training and validation loss. A run that stops sooner may simply have stopped improving. Sweep, then refine Search on a log scale, pick the best region, then try a few values in between. Keep the sweep's loss curves in your experiment notes. Use a schedule In scikit-learn, try learning_rate="adaptive"withSGDRegressororSGDClassifier. In deep learning, the Playbook suggests a warmup, which ramps the learning rate up from 0, when training is unstable early on.Retune after big changes A new batch size, optimizer or feature set can move the best learning rate. Rerun the sweep instead of reusing an old value.
Key takeaways
The learning rate multiplies every step; it changes where training goes, not just how fast. Below the best value, raising it speeds training up; above it, the loss bounces or explodes. Fewer epochs can mean the run stopped improving, not that it converged; compare final loss. Find it with a log-scale sweep, use a schedule, and retune when batch size or features change.
📚 المصادر
Linear regression: Hyperparameters — Google Machine Learning Crash Course Linear regression: Gradient descent — Google Machine Learning Crash Course Deep Learning Tuning Playbook: FAQs — Google for Developers Deep Learning Tuning Playbook: Guide for starting a new project — Google for Developers Stochastic Gradient Descent — scikit-learn User Guide
التعليقات (0)