Predicting Tuesday
Can a neural network predict election outcomes better than traditional statistics?
Hello from Morningside Heights!
Well, Election Day is nearing, and the Nates are fighting again. To the layperson, it might seem silly, but there’s a tremendous amount at stake in this election, especially for a pollster. It’s the most uncertain election we’ve seen in a long while, and a lot is riding on the ballot: abortion, censorship, and the future of our voting systems no less. This climate makes for a trial by fire for even the most battle-hardened of journalistic statisticians, for whom any attempt to spin a semblance of narrative will quickly be met with accusations of reading tea leaves.
So it’s definitely not an ideal time to jump into the ring myself, but here I go anyways. I’ve always been curious how well a neural network would fare at the task of election prediction, so this past week I collected a dataset from various sources to answer that question.
First, I downloaded census data broken down by district from the excellent, if a bit archaic, My Congressional District portal. It has incredibly detailed statistics, broken down in across many different demographics, though it’s missing North Carolina for some reason. Oh well, guess I can’t make great predictions there.
Second, I downloaded election results and polling data from 538, which has been a delightfully simple experience. All of their rich, comprehensive data is freely available here. And the CSVs are a data scientist’s dream — tidy, self-explanatory, and consistently formatted. It’s always nice to see how the experts do it.
Last, I trained the neural network. I wanted a way to combine the static features related to demographics with the dynamic features related to temporal variations in polling. With no clear idea of how to progress, I turned to the wonder that is Stack Overflow, and as usual, found an uncannily similar problem statement with an incredibly thoughtful and clear answer.
Another user was so inspired by the answer that they neatly packaged a dedicated software module to implement the answer’s description. I went ahead and downloaded the module to use for myself. It’s lovely how the incentives to learn and share can align so nicely for everyone.
Further perusal of the website lead to more nice insights. For instance, it turns out swapping “time” dimensions isn’t such a kooky idea after all. According to this answer, it could be a more optimal way to represent data for fast training:
There is an argument in favor of not using
batch_first
, which states that the underlying API provided by Nvidia CUDA runs considerably faster using batch as secondary.
Last but not least, I found myself stuck for a while on the Dead ReLU problem — causing the model to be far too careful with its predictions (essentially defaulting to saying each race would be 50/50). Luckily all it took was changing my activation functions to use Leaky ReLU, and the model began to make some actual bets!
So here are its predictions:
The Democrats will lose their Senate majority, by a lot. Under the modeled scenario, Republicans would win in 22 states, 12 more than the Democrats, including Georgia (Herschel Walker) and Pennsylvania (Oz). They might even win a filibuster-proof majority. Not that that matters — Biden is still president, for now.
The House is looking even grimmer for the Dems — the model predicts they will lose 58 seats relative to the GOP.
The Democrats’ only consolation, according to the model, may be that they’re predicted to “win” the generic Congressional ballot (e.g. win most of the votes in the country). But with the way the political map is set, winning the country most certainly does not mean winning the House and Senate.
Please take all of this with a grain of salt. It’s not a good model. This was all mainly to satisfy my curiosity. Trust your own instinct, do what’s right, and don’t forget to vote! And with that, see you all next week.