Suppose you want to forecast the return of a particular stock using many different predictors (think: past returns, market cap, asset growth, etc…). One way to do this would be to use the LASSO. Alternatively, you could use a neural network to make your forecast. On the surface, these two approaches look very different. However, it turns out that it’s possible to recast the LASSO as a *really* simple neural network.
This post outlines how.
This connection suggests we can use penalized regressions, such as the LASSO, as microscopes for studying more complicated machine-learning models, like neural networks, which often exhibit surprising new behavior. For example, if you include more predictors than observations in an OLS regression, then you’ll be able to perfectly fit your training data but your out-of-sample performance will be terrible. By contrast, highly over-parameters neural networks often have the best out-of-sample fit.
Because these models are so complicated, it’s often hard to understand why a pattern like this might emerge. Penalized regression models like the LASSO occupy a middle ground between OLS and complicated machine-learning models. Thus, if the LASSO can be viewed as a really simple neural net, then it might be possible to use this intermediate setup as a laboratory for understanding more complicated procedures. That’s the idea behind HastieMontanariRossetTibshirani22. And KellyMalamudZhou22 build on their logic.
General setup
Imagine that you’ve got historical data on the returns of different stocks, , and you want to make the best forecast possible for the future return of the st stock, . You have access to different return predictors. Let denote the value of the th predictor for the th stock. Assume that each predictor has been normalized to have mean zero and variance in the cross-section. Without loss of generality, also assume that the cross-sectional average return is zero.
If there were only one predictor, , then it’d be possible to estimate the OLS regression below:
In this case, the solution is given by . If the predictor tends to be positive, , for stocks that subsequently realize positive returns, , then the OLS slope coefficient associated with it will be positive. It will also be profitable to trade on this predictor, too.
You can also use an OLS regression to create a return forecast when you have more than one predictor
provided that you still have more observations than predictors, . If you’ve got predictors and stocks in your training data, then you’re in business. However, if your training data only contains stocks, then you’re SOL. You’ll have to use something other than an OLS regression.
The LASSO
One popular approach is to fit a LASSO specification. This is essentially an OLS regression with an additional absolute-value penalty applied to each predictive coefficient:
The pre-factor of in front of the penalty term is a tuning parameter, which can be optimally chosen via cross-validation. Notice that, when , there is no penalty at all and the LASSO is equivalent to OLS. But when , the LASSO’s coefficients will differ from OLS estimates as shown in the interactive figure below.
To see what I mean, let’s return to the case where there’s only one predictor. Alternatively, you could think about a world with orthogonal predictors, for all . In either case, we have:
This expression tells us that the LASSO does two things. First, it shrinks large OLS coefficients toward zero, . Second, it forces all small OLS coefficients, , to be exactly zero, .
Neural network
The LASSO is still able to make forecasts in situations where there are more predictors than observations because it kills off all the smallest predictors. Morally speaking, if only of your predictors have any forecasting power, then you shouldn’t need observations to figure this out. data points should do just fine. An alternative approach to making a return forecast when would be to use a neural network. On the surface, this seems like a very different strategy. Instead of a bet on sparsity, large neural networks often perform best when highly over-parameterized.
There are lots of kinds of neural networks. In this post, I’m going to mainly focus on neural networks with only one hidden layer that has the same number of nodes as predictors. e.g., with predictors, there will be hidden nodes. The diagram to the left shows what this would look like in a situation with predictors and hidden nodes so that we can see what’s going on.
The value of each hidden node is determined by an activation function that takes a linear combination of predictor values as its input:
e.g., you could set , , or something else entirely. contains the weights that go into the th hidden node. It has elements due to the intercept term.
The return forecast generated by this neural network, , is then a weighted average of its hidden nodes where the weights are chosen by solving the optimization problem below:
This objective function includes a penalty term just like the LASSO, but the penalty is quadratic. It’s equivalent to the common practice of training a neural network via gradient descent with weight decay.
Degrees of freedom
If our goal is to write down the LASSO as a special case of a neural network, then there are two apparent differences that need to be finessed. The first involves degrees of freedom. In the LASSO, there is one parameter that needs to be estimated for each predictor. In the neural network above, each predictor is associated with free parameters. In addition, you must also choose an activation function, .
To represent the LASSO as a neural network, we’re going to have to shut down of the degrees of freedom associated with each predictor. So, let’s start by looking at a neural network that’s “simply connected”—i.e., a network where whenever . Let’s also assume a linear activation function, , and restrict ourselves to the case where there’s no constant term, .
After making these assumptions, we are left with the neural network in the diagram above. There are now only two free parameters associated with each predictor: and . To estimate all of these values, we must maximize the objective below:
This looks almost like the LASSO objective function. But there’s still one glaring difference left…
Nature of the penalty
In the LASSO, we’ve got an absolute-value penalty; whereas, the neural network has a quadratic penalty. This seems important! To see why, consider replacing the absolute-value penalty in the LASSO with
When you do this, you’re left with something called the Ridge regression.
Just like with the LASSO, we can characterize the Ridge estimates relative to OLS in the case where there’s only one predictor or all predictors are orthogonal to one another:
When you increase the value of in the figure to the right, you’ll see that the slope of the line changes. The larger the , the less changes in response to a change in . Notice how this effect is qualitatively different from the effect of increasing in a LASSO specification. There, controlled the size of the inaction region. But, provided that , the LASSO estimate always moved one-for-one with .
However, this Ridge intuition is misleading. In the simply-connected neural-network structure that I outline above, we are not choosing a single coefficient . Instead, because there is a hidden layer, we are choosing the product of . And this makes all the difference. For any value of , we have that
where the minimum is at . This is just the inequality relating arithmetic and geometric averages. It’s what allows a single hidden layer to sneak in a threshold through the back door.
Some extensions
We’ve just seen that you can think about the LASSO as a simply-connected two-layer neural network with a linear activation function and no bias terms, which was trained via gradient descent with weight decay. This is not my observation. I first saw it in Tibshirani21. The step where you reduce the degrees of freedom is obvious enough. But I had never made the connection with the arithmetic/geometric mean inequality. That second step struck me (and still strikes me) as really cool. It’s also a very concrete example of the flexibility inherent in neural networks. The hidden layer allows a neural network to do things you wouldn’t guess possible based only on the functional forms involved.
In addition to outlining the argument above, Tibshirani21 also gives a couple of other interesting extensions. e.g., the note shows how, by increasing the number of hidden layers in the neural network, you can reproduce the output of a LASSO-like specification below
The more hidden layers you include, the closer you get to best-subset selection, . The note also shows that it’s possible to write group-LASSO as a neural network that ain’t quite so simply connected.