The dataset
We’ll treat one day of grid load as a regression problem. The input is the normalized time of day, and the target is the total load across the MISO system. After fetching the data from the gridstatus.io API, we standardize it to zero mean and unit variance. We then keep just ten readings for training. That tiny sample is intentional: it gives a degree-9 polynomial plenty of room to overfit, just as it did in the closed-form example. The rest of the day’s readings are held out so we can evaluate each value of .MISO, the Midcontinent Independent System Operator, manages the wholesale electricity market and balances electricity supply and demand across 15 US states and Manitoba. The curve below shows one real day from the gridstatus.io MISO load dataset, fetched through the gridstatus API.
Real MISO system load on 2026-06-30, using five-minute readings from the gridstatus.io

miso_load dataset.Forecast errors have real consequences here. Grid operators schedule generation ahead of time, but supply and demand must stay balanced from moment to moment. If a forecast is too low, operators may need emergency power purchases and, in severe cases, load shedding. If it is too high, they may commit expensive generators that were not needed. A model that follows noise instead of the underlying demand pattern can therefore make the grid harder and more expensive to operate.
Standardized polynomial features
Our model is a degree-9 polynomial, The raw terms have very different scales on . As a result, one gradient step can affect some coefficients far more than others, and the penalty does not act evenly across them. We avoid that problem by standardizing every feature to zero mean and unit variance. A single learning rate and a single value of then make sense for all nine coefficients. This also matches the feature scaling used on the closed-form page, so the two results can be compared directly. We handle the intercept separately by centering the targets at .The regularized objective and the SGD update
SGD minimizes the same ridge objective that the closed-form solution minimizes: the sum of squared residuals plus an penalty. The minimum satisfies the normal equations . Because both methods use this convention, has the same meaning here as it does in the closed-form solution. At each step, SGD draws a mini-batch containing examples. Multiplying the batch sum by gives us an unbiased estimate of the full gradient:Finding a good value for
The training loss cannot tell us how much regularization to use. It will always favor , since weaker shrinkage lets the polynomial fit the ten training points more closely. To choose based on how well the model generalizes, we use two loops:- In the inner loop, SGD trains the degree-9 model for one fixed value of and returns its error on the held-out readings.
- In the outer loop, Optuna proposes values of across a wide logarithmic range. It uses the validation error from each inner run to decide what to try next.

Comparing the two solutions
Once the search has found , we train the degree-9 model one more time and compare its SGD weights with the closed-form ridge solution at the same value of . The two fits should be nearly identical. They minimize the same objective; they simply take different routes to get there.
What to take away
- Choosing is a model-selection problem. Optuna tries candidate values in the outer loop, while SGD trains and evaluates a model in the inner loop. Training loss alone is not enough because it always favors less shrinkage.
- The regularization term contributes to the gradient. This shrinks the weights at every update and helps keep the degree-9 polynomial from overfitting.
- When SGD and the closed-form method use the same standardized features and the same , they reach the same regularized solution.
- On this grid-load sample, the search settles near . That is close in scale to the found for the unit-variance sinusoid on the closed-form page, even though the value was tuned independently.
References
- Andrychowicz, M., Denil, M., Gomez, S., Hoffman, M., Pfau, D., et al. (2016). Learning to learn by gradient descent by gradient descent.
- Bottou, L., Curtis, F., Nocedal, J. (2016). Optimization Methods for Large-Scale Machine Learning.
- Keskar, N., Mudigere, D., Nocedal, J., Smelyanskiy, M., Tang, P. (2016). On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima.

