Pokemon Battle Predictor

A Machine Learning Browser Extension

Pokemon Battle Predictor is a browser extension for Pokemon Showdown which uses TensorFlow.js machine learning models trained on 2,000,000+ battles to tell you the current probability of:

  • Who will win the battle

  • Your opponent switching out or choosing a move

  • Which move they will use if they stay in

  • Which Pokemon they will switch to if they switch

This extension is currently in beta, so if you find any bug or have any suggestions, please email contact@battlepredictor.com with them!

Download the extension

How does it work?

Step 1: Search

The best way to learn what someone will do in the future is by knowing what they and others have done in the past, so the first step in this project was searching for data on people playing Pokemon. Enter Pokemon Showdown, an online Pokemon battle simulator which supports many different kinds of ways people play and is conveniently made by data nerds as well!

After a battle, users can upload their battle to the Pokemon Showdown server, which can then be viewed by anyone at a latter date. Because of the site's popularity among competitive players, there are millions of battles to possibly learn from. Along with storing past battles, an extensive set of usage statistics for the meta-games they support are calculated, including insightful info such as the most common moves a Pokemon uses in battle, how often one Pokemon wins over the other, and more. This combination of breadth and depth of data made this the best source. The developers of Showdown know their data is useful as well, grant data to those looking to do research on it, and therefore provided this project with 2,000,000 battles to analyze.

Another consideration is making sure the people in the battles being learned from know what they're doing themselves. Thankfully players on Showdown have rankings based on the ELO rating system, so only battles of players above a decent ranking are considered. Those battles are then split into groups to represent different segments of player ratings as to accommodate for players of different skill levels playing differently.

Step 2: Train

The heart of this project, machine learning models enable the program to make its predictions. The TensorFlow.js API is used to create different neural networks for the 4 different types of predictions which are trained from the parsed and prepared battle data. If you are unfamiliar with machine learning, you should read parts of this simplified overview to learn more before continuing. (Or just read all of it, you'll learn some pretty cool stuff!)

Because each model is run at the start of every turn and does not know every detail about the opponents team, the model makes its predictions based on information that's available to both players after the previous turn finished and general past player behavior. All of the models have a similar groups of inputs which are taken for each turn of each battle, making creating all 4 an easier task.

The inputs within each group are different depending on the meta-game to reflect what Pokemon available, effects possible, moves usable, etc. The models will take those inputs and be trained with the goal of calculating the chance of its desired output. Key word here is chance, as there is a difference between trying to predict what will happen next and the chance of something happening. The difference is the former is judged by the accuracy of each prediction while the latter is judged by whether the outputs of a specific chance are accurate "that chance" of the time. Predicting chance was chosen as this is far more useful for any kind of game and this one in particular is way too random to find anything but chance reliably.

To train the models, they are fed the inputs with their correct outputs and the outputs are where the shapes of the models diverge. For predicting the chance to win, the models were trained on an equal number of turns where the battle's outcome was player 1 or player 2 winning so the model learns to return a signal number where a high value means player 1 will win and a low value means player 2 will win. The model for whether your opponent will choose to make a move or switch out the next turn works similarly where instead the correct outputs are a 1 when the opponent switches and a 0 when a move is made.

For predicting what move your opponent will use or which team member they will switch to, the models are trained so it finds the chance of every move/Pokemon being used/brought in, then based on what the opponent is either known or presumed to be capable of, multiplies those chances by a number from 1 to 0 representing the likelihood of that option being possible (1 for the option is known for sure and 0 if the option is impossible). This is done to both teach the model what moves a Pokemon can use and the likelihood of the Pokemon having the learnable move.

It should be noted that neural networks, especially for predicting the chance to win, are not the "right" models to solve these problems. It was honestly surprising the winning chance model using this method worked! However, given that the models are still very effective at their goal and this project started as a Tensorflow.js experiment, neural networks were used throughout. This may change with future updates.

Step 3: Battle

Once the models are trained and tested, it's time to put them to use! The Pokemon Battle Predictor extension runs a lighter version of the code used to make the models to provide just the functionality needed to understand what the current state of the battle is and make the prediction. It works by adding code to a Pokemon Showdown battle which translates their representation of a battle at the end of each turn into a form the models can accept, sending that data to the server the machine learning models reside on, running the models to find their predictions, and creating UI elements on the page to show what was found. Users can also choose which predictions they want to see at a time.