This repository is outdated
Reworked scraper and prediction model available at new repository Advanced UFC Analyzer
This project uses machine learning to predict the winner between 2 UFC fighters using historical fight data and fighter statistics. Using a supervised learning approach, the model is built on a neural network architecture that processes attributes of fighters, including height, weight, age, striking, grappling statistics and etc...
By analyzing patterns and relationships in the historical matchups, it gives greater weight to features of fighters that have been more apparent in past winners.
We do some preprocessing on the data to make sure the quality of it is as good and not overfitted, then duplicate the fight data, swapping fighter1
for fighter2
, balancing out the dataset, avoiding bias from the model so it focuses on the comparative features instead of the order of the fighters.
When the data is ready, we train the model, we save it in the models/
directory so that we can reuse it without training the model every time a prediction is to be made.
For the dataset, I used jansen88's UFC data scraper, follow the instructions there.
Data Handling:
- Extracted useful fighter statistics (height, weight, age, striking and grappling statistics)
- Calculated advantages (e.g. height/reach advantage, striking efficiency)
- Encoded fighter stances and weight classes numerically with LabelEncoder
Machine Learning Model:
- Built a neural network using TensorFlow/Keras in Python to predict fight outcomes
- With the preprocessed data, train the model and valide its performance to make sure we get reliable predictions
- Saved the model in
models/
and load it from there
Prediction:
- Using the trained model, it predicts the favored fighter based on their statistics, providing a confidence score
API:
- I used FastAPI to make the backend to handle requests for predictions.
UI:
- Created the responsive frontend using Vue, TypeScript and TailwindCSS
- Users can input the names of two fighters and send the request to the API from the site
- Python 3.10 or higher: Install from python.org.
- pip: Python package manager (comes with Python installations).
- Node.js (v14 or later): Install from nodejs.org
Install the required Python packages from requirements.txt
found in the root folder.
pip install -r requirements.txt
- Clone the repository
git clone https://github.com/markbakos/ufc-predictor.git
cd ufc-predictor
- Install dependencies for frontend
cd client
npm install
- Start the development server
- Frontend:
cd client
npm run dev
- Backend:
# Make sure you are in root folder
source venv/bin/activate
uvicorn app.server:app
- Include dataset
Place your dataset into the app/data/
folder. Make sure it is called complete_ufc_data.csv
- Open the app in your browser
Navigate to http://localhost:5173 or the address provided in your terminal to use the app.
The model currently shows accuracy of around ~66.5% for blind data.
The current model only compares the fighters' physical and fighting statistics, it still lacks many features, including:
(These might not improve the accuracy of the model, only a theory)
- Fighter's win streaks, win rates and momentum (v1.1) ✔️
Improved overall accuracy by about ~0.5% - ~0.8%.
⚠️ Checking betting odds
Tried comparing advantage of past favorite/underdog status in fights, that lead to a ~-0.5% decrease in accuracy, have to try a different approach.- Categorizing fighters and both checking IF they have fought against someone in that category, and if they did, how they competed
- Octagon time for fighters
- Improve the model to include more in the prediction (Predicted time, Outcome of DEC/SUB/KO)
Feel free to fork this repository, make changes, and submit a pull request.
For any inquiries, feel free to reach out:
Email: markbakosss@gmail.com
GitHub: markbakos