Regularized Regression in Excel and MATLAB CVX | Worked Example
Build a regularized regression model from a small Excel dataset and reproduce it in MATLAB with CVX. The example uses synthetic scooter-rental data to show how residuals and categorical predictors affect the fit. The final step uses an L1 penalty to encourage selected coefficients to agree.
Screen times follow the original lesson. Edited YouTube versions may run shorter.
Build the input table
Arrange the response and predictors in columns with one row per observation. Export a rectangular numeric dataset for MATLAB.

Fit a baseline and inspect residuals
Use the CSV to reproduce the unregularized fit. A residual is the observed value minus the prediction.

Encode the categories
Build indicator columns for categories and choose a reference category when using an intercept.

Reproduce the fit in CVX
Express coefficients as variables and residual size as the objective. Compare the optimizer’s predictions with the baseline before adding penalties.

Add an L1 penalty
Penalize coefficient differences when groups should behave similarly. Larger penalty weights encourage agreement at the expense of some in-sample fit.
