File size: 9,111 Bytes
e4d0ed5
 
 
 
 
 
 
 
 
 
 
 
 
23335ef
 
4025e12
23335ef
9926092
 
e4d0ed5
 
23335ef
 
 
 
9926092
23335ef
 
 
9926092
23335ef
 
 
9926092
 
 
 
 
 
 
 
 
 
 
 
e4d0ed5
9926092
 
 
e4d0ed5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9926092
 
 
e4d0ed5
9926092
 
e4d0ed5
9926092
 
e4d0ed5
9926092
 
23335ef
 
 
 
 
 
 
 
 
 
 
 
e4d0ed5
23335ef
 
 
9926092
23335ef
e447c36
23335ef
e447c36
23335ef
e447c36
23335ef
e447c36
23335ef
e447c36
23335ef
e447c36
23335ef
4a5a573
 
23335ef
e447c36
23335ef
e447c36
23335ef
9926092
23335ef
 
e447c36
23335ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---
datasets:
- ufc-fight-data
language:
- en
tags:
- ufc
- mma
- fight-stats
- web-scraping
license: mit
pretty_name: UFC Fight Stats
---
# UFC Data Extractor

A python-based web scraping project that extracts all available UFC fight and fighter data from [ufcstats.com](http://ufcstats.com), transforms it into structured wide-format tables, and enriches it with historical performance statistics. 

The UFC (Ultimate Fighting Championship) is a premier mixed martial arts (MMA) promotion showcasing elite-level fighters across multiple weight classes.

Author: Kristine Karp ([email protected])

## Project Overview

This tool performs the following:

- Scrapes **all available** data from `ufcstats.com` including:
  - Fighter profiles (name, height, reach, stance, etc.)
  - Fight outcomes and statistics (strikes, takedowns, control time, etc.)
  - Event information (event title, date, winner)
- Transforms the raw data into a clean wide-format table, where:
  - Each row represents **one fight**
  - Contains data for **both fighters** in separate columns
- Computes **cumulative performance metrics** for each fighter across fights to enable longitudinal analysis
- Converts units from U.S. customary to metric system (e.g., inches to centimeters, pounds to kilograms) to support European-format data handling

Note: The original dataset does not include cumulative or historical statistics for each fighter prior to a given fight (e.g., total significant strikes, takedowns, or submission attempts). To enable performance analysis, these metrics are calculated separately based on each fighter’s fight history up to that point. However, to keep the dataset compact, these intermediate cumulative values are not stored in the final output—only the derived pre-fight performance metrics are retained.
Data was last extracted on March 10, 2025.

## Libraries Used
- Data Consolidation: argparse, json, os, re
- Web Scraping: BeautifulSoup, requests, time
- Data Analysis & Transformation: pandas, numpy, math

## Workflow
1. Scrape web data from [ufcstats.com] using custom scripts.
2. Cache all raw HTML and JSON files locally for reproducibility and offline access (fight urls, fighter's basic information, events url and information, fight outcome and statistics)
3. Transform scraped data into structured format:
   - Flatten nested data
   - Convert units (from U.S. customary to EU metric system)
4. Compute the following historical performance statistics by calculating cumulative strikes, takedowns, opponent's strikes and defence, etc per fighter from previous fights before the next fight.
- **Significant Strikes Absorbed per Minute (SApM)**  
   `SApM = Previous fights' Opponent's Landed Significant Strikes / Total Fight Time (min)`

- **Average Takedowns Landed per 15 Minutes (TD Avg.)**  
  `TD Avg. = (Fighter's Total Takedowns from previous fights × 15) / Total Fight Time (min)`

- **Significant Strikes Landed per Minute (SLpM)**  
  `SLpM = Fighter's Landed Significant Strikes from previous fights / Total Fight Time (min)`

- **Average Submissions Landed per 15 Minutes (Sub. Avg.)**  
  `Sub Avg. = (Fighter's Submissions from previous fights × 15) / Total Fight Time (min)`

- **Significant Striking Accuracy (Str. Acc.)**  
  `Str. Acc. = Fighter's Landed Significant Strikes from previous fights / Fighter's Total Strikes from previous fights`

- **Takedown Accuracy (TD Acc.)**  
  `TD Acc. = Fighter's Successful Takedowns from previous fights / Fighter's Total Takedown Attempts from previous fights`

- **Takedown Defense (TD Def.)**  
  `TD Def. = (Previous fights' Opponent's Total Takedown Attempts - Previous fights' Opponent's Successful Takedowns) / Previous fights' Opponent's Total Takedown`

- **Significant Strike Defense (Str. Def.)**  
   `Str. Def. = (Previous fights' Opponent's Total Significant Strikes -  previous fights' Opponent's Landed Significant Strikes) /  Previous fights' Opponent's Total Significant Strike`

5. Create final csv output where one unique fight is one row containing information about the event (url, date), the two fighters (url, basic information such as reach, stance, birthdate and age (to identify the age during the event, it is calculated using birthdate and event date)), fight outcome and statistics (winner, significant strikes, takedowns, submissions) and calculated performance statistics of each fighter. 

## Sample of Preliminary Extracts Cached to JSON
1. 📄 [sample_fight_urls.json](./sample_fight_urls.json)
- ![All Available Fight Urls](assets/sample_fight_urls.jpg)

2. 📄 [sample_constant_info.json](./sample_constant_info.json)
- ![Fighter Basic Information](assets/sample_constant_info.jpg)

3. 📄 [sample_Aalon_Cruz_vs_Spike_Carlyle_0bcb04163f8d8ead.json](./sample_Aalon_Cruz_vs_Spike_Carlyle_0bcb04163f8d8ead.json)
- ![Fight Statistics](assets/sample_fight_info.jpg)

## Sample of Final Output

Below is a simplified example of what the dataset looks like. Each row represents one fight and includes data for both fighters.

| event_name                     | event_date | fighter1_name | fighter2_name   | fighter1_knockdown | fighter2_knockdown | fighter1_sig_strikes | fighter2_sig_strikes | fighter1_control_time | fighter2_control_time | event_winner   |
|-------------------------------|------------|---------------|-----------------|---------------------|---------------------|-----------------------|-----------------------|------------------------|------------------------|----------------|
| UFC Fight Night: Benavidez vs. Figueiredo | 2020-02-29 | Aalon Cruz    | Spike Carlyle | 0                   | 0                   | 2                     | 20                    | 5                      | 7                      | Spike Carlyle  |

**Note:**  
- This is only a sample; the actual dataset contains over **80 features** per fighter including:
  - Fighter stats: height, reach, weight, age, stance, striking/takedown accuracy & defense
  - Fight stats: control time, knockdowns, strike breakdown (head/body/leg, distance/clinch/ground)
  - Derived metrics: cumulative win %, strike absorption rate, etc.
- The uploaded dataset 📄 [ufc_fights_data_first_200.csv](./ufc_fights_data_first_200.csv)includes only the first 200 rows. The full dataset and processing scripts are not shared to respect the intellectual property of the source website.

The full schema includes both raw data and calculated performance metrics to support deep analysis or model training.

## Quick Statistics of the Extracted Data

![Summary Statistics](assets/summary_statistics.jpg)

![Win Method Distribution](assets/win_method_distribution.jpg)

![Stance Distribution](assets/stance_distribution.jpg)

![Fight Duration Summary](assets/fight_duration_summary.jpg)

![Fight Count by Weight Class](assets/fight_count_by_weight_class.png)

![Age Distribution by Weight Class](assets/age_distribution_by_weight_class.jpg)

![Correlation Matrix](assets/corr_matrix.png)

### Fighters with the Most Number of Fights
![Fighters with Most Number of Fights](assets/most_active_fighters.jpg)

![Fighters with the Most Wins](assets/top_fighters_win_pct.jpg)


## Sample Analysis

![Fighter's Historical Performance Statistics](assets/sample_fighter_historical_performance.jpg)

> 💡 **Note:** All statistics below are calculated based on a fighter's **entire historical fight record** from the dataset. They represent cumulative performance trends across previous bouts.

- **Significant Strikes Absorbed per Minute (SApM):**  
  The average number of significant strikes a fighter absorbs **per minute**, based on all past fights.

- **Average Takedowns Landed per 15 Minutes (TD Avg.):**  
  The average number of takedowns a fighter lands **every 15 minutes**, aggregated from all their previous bouts.

- **Significant Strikes Landed per Minute (SLpM):**  
  The average number of significant strikes a fighter lands **per minute** over their full fight history.

- **Average Submissions Landed per 15 Minutes (Sub. Avg.):**  
  The average number of successful submissions attempted **per 15 minutes** in previous matches.

- **Significant Striking Accuracy (Str. Acc.):**  
  The percentage of significant strikes landed out of all attempted, across **all prior fights**.

- **Takedown Accuracy (TD Acc.):**  
  The success rate of takedown attempts based on a fighter's **historical data**.

- **Takedown Defense (TD Def.):**  
  The percentage of opponent takedowns a fighter **successfully defended** over their entire fight history.

- **Significant Strike Defense (Str. Def.):**  
  The percentage of opponents’ significant strike attempts that **did not land**, averaged over all previous fights.


## Disclaimer

This project is **not affiliated with**, **endorsed by**, or **connected to** the UFC or `ufcstats.com` in any way.

- All data is publicly available on [ufcstats.com](http://ufcstats.com)
- This tool is intended for **educational and research purposes only**
- Please ensure your use complies with the site's [robots.txt](http://ufcstats.com/robots.txt) and terms of service