Allisona commited on
Commit
d985f60
·
verified ·
1 Parent(s): 61871a3

Upload 8 files

Browse files
README.md CHANGED
@@ -1,13 +1,44 @@
1
  ---
2
- title: UFC
3
- emoji: 😻
4
- colorFrom: gray
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 6.0.1
8
  app_file: app.py
9
  pinned: false
10
- license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: UFC Fight Predictor
3
+ colorFrom: blue
4
+ colorTo: gray
 
5
  sdk: gradio
6
+ sdk_version: 3.44.0
7
  app_file: app.py
8
  pinned: false
 
9
  ---
10
 
11
+ # UFC Fight Predictor
12
+
13
+ Predict UFC fight outcomes using Machine Learning.
14
+
15
+ ## Model Information
16
+
17
+ - **Accuracy**: 99%
18
+ - **Algorithm**: Logistic Regression
19
+ - **Features**: Knockdowns, significant strikes, takedowns, submissions
20
+ - **Dataset**: 1,400+ real UFC fights
21
+
22
+ ## How to Use
23
+
24
+ 1. Enter statistics for both fighters
25
+ 2. Select weight class
26
+ 3. Adjust fight method parameter
27
+ 4. Click Submit to get prediction
28
+
29
+ ## Model Features
30
+
31
+ The model analyzes:
32
+ - Statistical differences between fighters
33
+ - Striking efficiency
34
+ - Weight class
35
+ - Fight round
36
+
37
+ ## Output
38
+
39
+ The model returns:
40
+ - Predicted winner
41
+ - Probabilities for each fighter
42
+ - Confidence level
43
+
44
+ Developed for data analysis and machine learning demonstration.
app.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import numpy as np
4
+ import pandas as pd
5
+ import json
6
+
7
+ print("🚀 Cargando modelo UFC Predictor...")
8
+
9
+ # Cargar modelo y preprocesadores
10
+ try:
11
+ with open("ufc_best_model.pkl", "rb") as f:
12
+ model = pickle.load(f)
13
+
14
+ with open("ufc_scaler.pkl", "rb") as f:
15
+ scaler = pickle.load(f)
16
+
17
+ with open("ufc_imputer.pkl", "rb") as f:
18
+ imputer = pickle.load(f)
19
+
20
+ with open("ufc_model_metadata.json", "r") as f:
21
+ metadata = json.load(f)
22
+
23
+ with open("ufc_feature_ranges.json", "r") as f:
24
+ ranges = json.load(f)
25
+
26
+ print("✅ Modelo y archivos cargados correctamente")
27
+ print(f"🏆 Modelo: {metadata['best_model_name']}")
28
+ print(f"📊 Accuracy: {metadata['best_accuracy']:.4f}")
29
+
30
+ except Exception as e:
31
+ print(f"❌ Error cargando archivos: {e}")
32
+ raise e
33
+
34
+ def predict_ufc_fight(
35
+ fighter_1_kd, fighter_1_str, fighter_1_td, fighter_1_sub,
36
+ fighter_2_kd, fighter_2_str, fighter_2_td, fighter_2_sub,
37
+ round_num, weight_class, method_encoded
38
+ ):
39
+ """
40
+ Predice el resultado de una pelea UFC basado en las estadísticas
41
+ """
42
+ try:
43
+ # Calcular diferencias
44
+ kd_diff = fighter_1_kd - fighter_2_kd
45
+ str_diff = fighter_1_str - fighter_2_str
46
+ td_diff = fighter_1_td - fighter_2_td
47
+ sub_diff = fighter_1_sub - fighter_2_sub
48
+
49
+ # Calcular precisiones
50
+ fighter_1_accuracy = fighter_1_str / (fighter_1_str + 10)
51
+ fighter_2_accuracy = fighter_2_str / (fighter_2_str + 10)
52
+
53
+ # Crear array de entrada en el orden CORRECTO
54
+ input_features = [
55
+ kd_diff, str_diff, td_diff, sub_diff, # Diferencias
56
+ fighter_1_kd, fighter_2_kd, # KDs individuales
57
+ fighter_1_str, fighter_2_str, # Golpes
58
+ fighter_1_td, fighter_2_td, # Takedowns
59
+ fighter_1_sub, fighter_2_sub, # Submissions
60
+ fighter_1_accuracy, fighter_2_accuracy, # Precisiones
61
+ round_num, # Round
62
+ method_encoded # Método codificado
63
+ ]
64
+
65
+ # Añadir one-hot encoding para weight_class
66
+ weight_classes = [
67
+ 'weight_class_Bantamweight', 'weight_class_Catch Weight',
68
+ 'weight_class_Featherweight', 'weight_class_Flyweight',
69
+ 'weight_class_Heavyweight', 'weight_class_Light Heavyweight',
70
+ 'weight_class_Lightweight', 'weight_class_Middleweight',
71
+ 'weight_class_Welterweight'
72
+ ]
73
+
74
+ for wc in weight_classes:
75
+ input_features.append(1 if wc == f"weight_class_{weight_class}" else 0)
76
+
77
+ # Convertir a numpy array
78
+ input_array = np.array([input_features])
79
+
80
+ # Aplicar preprocesamiento
81
+ input_imputed = imputer.transform(input_array)
82
+ input_scaled = scaler.transform(input_imputed)
83
+
84
+ # Hacer predicción
85
+ prediction = model.predict(input_scaled)[0]
86
+ probability = model.predict_proba(input_scaled)[0]
87
+
88
+ # Interpretar resultados
89
+ if prediction == 1:
90
+ winner = "Fighter 1"
91
+ confidence = probability[1]
92
+ explanation = f"Fighter 1 tiene {confidence:.1%} de probabilidad de ganar"
93
+ else:
94
+ winner = "Fighter 2"
95
+ confidence = probability[0]
96
+ explanation = f"Fighter 2 tiene {confidence:.1%} de probabilidad de ganar"
97
+
98
+ return {
99
+ "🏆 Ganador predicho": winner,
100
+ "📈 Confianza": f"{confidence:.1%}",
101
+ "🥊 Probabilidad Fighter 1": f"{probability[1]:.1%}",
102
+ "🥊 Probabilidad Fighter 2": f"{probability[0]:.1%}",
103
+ "💡 Análisis": explanation
104
+ }
105
+
106
+ except Exception as e:
107
+ return {"❌ Error": f"Error en predicción: {str(e)}"}
108
+
109
+ # Crear interfaz Gradio
110
+ print("🎨 Creando interfaz Gradio...")
111
+
112
+ # Definir inputs
113
+ inputs = [
114
+ gr.Number(label="Fighter 1 - Knockdowns", value=0, minimum=0, maximum=10),
115
+ gr.Number(label="Fighter 1 - Golpes significativos", value=50, minimum=0, maximum=500),
116
+ gr.Number(label="Fighter 1 - Takedowns", value=1, minimum=0, maximum=20),
117
+ gr.Number(label="Fighter 1 - Intentos de sumisión", value=0, minimum=0, maximum=10),
118
+ gr.Number(label="Fighter 2 - Knockdowns", value=0, minimum=0, maximum=10),
119
+ gr.Number(label="Fighter 2 - Golpes significativos", value=45, minimum=0, maximum=500),
120
+ gr.Number(label="Fighter 2 - Takedowns", value=2, minimum=0, maximum=20),
121
+ gr.Number(label="Fighter 2 - Intentos de sumisión", value=1, minimum=0, maximum=10),
122
+ gr.Slider(1, 5, value=3, step=1, label="Round"),
123
+ gr.Dropdown(
124
+ choices=[
125
+ "Bantamweight", "Catch Weight", "Featherweight", "Flyweight",
126
+ "Heavyweight", "Light Heavyweight", "Lightweight", "Middleweight", "Welterweight"
127
+ ],
128
+ value="Lightweight",
129
+ label="Categoría de Peso"
130
+ ),
131
+ gr.Slider(0, 10, value=5, step=1, label="Método (encoded) - 0-10 scale")
132
+ ]
133
+
134
+ # Crear la aplicación
135
+ demo = gr.Interface(
136
+ fn=predict_ufc_fight,
137
+ inputs=inputs,
138
+ outputs="json",
139
+ title="🥊 UFC Fight Predictor",
140
+ description="Predice el resultado de peleas UFC basado en estadísticas de los peleadores. Modelo entrenado con accuracy del 99%",
141
+ examples=[
142
+ [2, 120, 3, 1, 0, 80, 1, 0, 3, "Lightweight", 5], # Fighter 1 favorito
143
+ [0, 80, 1, 0, 3, 150, 4, 2, 2, "Welterweight", 5] # Fighter 2 favorito
144
+ ]
145
+ )
146
+
147
+ print("✅ Interfaz creada. Iniciando...")
148
+
149
+ if __name__ == "__main__":
150
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ scikit-learn==1.3.0
2
+ pandas==2.0.3
3
+ numpy==1.24.3
4
+ gradio==3.44.0
ufc_best_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4415283c530541a079abc92e2030d03bd084c9273d9a5a1fd9bf9b8f0e4d2081
3
+ size 917
ufc_feature_ranges.json ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "KD_diff": {
3
+ "min": -3.0,
4
+ "max": 5.0,
5
+ "mean": 0.30335715248752865,
6
+ "dtype": "float64"
7
+ },
8
+ "STR_diff": {
9
+ "min": -112.0,
10
+ "max": 312.0,
11
+ "mean": 14.560199541593636,
12
+ "dtype": "float64"
13
+ },
14
+ "TD_diff": {
15
+ "min": -11.0,
16
+ "max": 20.0,
17
+ "mean": 0.785762437643252,
18
+ "dtype": "float64"
19
+ },
20
+ "SUB_diff": {
21
+ "min": -7.0,
22
+ "max": 10.0,
23
+ "mean": 0.281380612107321,
24
+ "dtype": "float64"
25
+ },
26
+ "Fighter_1_KD": {
27
+ "min": 0.0,
28
+ "max": 5.0,
29
+ "mean": 0.36685991640825133,
30
+ "dtype": "float64"
31
+ },
32
+ "Fighter_2_KD": {
33
+ "min": 0.0,
34
+ "max": 3.0,
35
+ "mean": 0.06350276392072267,
36
+ "dtype": "float64"
37
+ },
38
+ "Fighter_1_STR": {
39
+ "min": 0.0,
40
+ "max": 445.0,
41
+ "mean": 43.114601590939735,
42
+ "dtype": "float64"
43
+ },
44
+ "Fighter_2_STR": {
45
+ "min": 0.0,
46
+ "max": 271.0,
47
+ "mean": 28.5544020493461,
48
+ "dtype": "float64"
49
+ },
50
+ "Fighter_1_TD": {
51
+ "min": 0.0,
52
+ "max": 21.0,
53
+ "mean": 1.4516650937036537,
54
+ "dtype": "float64"
55
+ },
56
+ "Fighter_2_TD": {
57
+ "min": 0.0,
58
+ "max": 11.0,
59
+ "mean": 0.6659026560604018,
60
+ "dtype": "float64"
61
+ },
62
+ "Fighter_1_SUB": {
63
+ "min": 0.0,
64
+ "max": 10.0,
65
+ "mean": 0.5317513819603613,
66
+ "dtype": "float64"
67
+ },
68
+ "Fighter_2_SUB": {
69
+ "min": 0.0,
70
+ "max": 7.0,
71
+ "mean": 0.2503707698530403,
72
+ "dtype": "float64"
73
+ },
74
+ "Fighter_1_accuracy": {
75
+ "min": 0.0,
76
+ "max": 0.978021978021978,
77
+ "mean": 0.7139546070716276,
78
+ "dtype": "float64"
79
+ },
80
+ "Fighter_2_accuracy": {
81
+ "min": 0.0,
82
+ "max": 0.9644128113879004,
83
+ "mean": 0.6003475272273104,
84
+ "dtype": "float64"
85
+ },
86
+ "Round": {
87
+ "min": 1.0,
88
+ "max": 5.0,
89
+ "mean": 2.33832456495346,
90
+ "dtype": "float64"
91
+ },
92
+ "weight_class_Bantamweight": {
93
+ "min": 0.0,
94
+ "max": 1.0,
95
+ "mean": 0.08534447889982473,
96
+ "dtype": "bool"
97
+ },
98
+ "weight_class_Catch Weight": {
99
+ "min": 0.0,
100
+ "max": 1.0,
101
+ "mean": 0.008763651071861939,
102
+ "dtype": "bool"
103
+ },
104
+ "weight_class_Featherweight": {
105
+ "min": 0.0,
106
+ "max": 1.0,
107
+ "mean": 0.09572603478495348,
108
+ "dtype": "bool"
109
+ },
110
+ "weight_class_Flyweight": {
111
+ "min": 0.0,
112
+ "max": 1.0,
113
+ "mean": 0.042065525144937305,
114
+ "dtype": "bool"
115
+ },
116
+ "weight_class_Heavyweight": {
117
+ "min": 0.0,
118
+ "max": 1.0,
119
+ "mean": 0.09222057435620871,
120
+ "dtype": "bool"
121
+ },
122
+ "weight_class_Light Heavyweight": {
123
+ "min": 0.0,
124
+ "max": 1.0,
125
+ "mean": 0.08911959013078063,
126
+ "dtype": "bool"
127
+ },
128
+ "weight_class_Lightweight": {
129
+ "min": 0.0,
130
+ "max": 1.0,
131
+ "mean": 0.17365511662397196,
132
+ "dtype": "bool"
133
+ },
134
+ "weight_class_Middleweight": {
135
+ "min": 0.0,
136
+ "max": 1.0,
137
+ "mean": 0.13334232169340704,
138
+ "dtype": "bool"
139
+ },
140
+ "weight_class_Welterweight": {
141
+ "min": 0.0,
142
+ "max": 1.0,
143
+ "mean": 0.16826210057974922,
144
+ "dtype": "bool"
145
+ },
146
+ "Method_encoded": {
147
+ "min": 0.0,
148
+ "max": 70.0,
149
+ "mean": 41.41000404476203,
150
+ "dtype": "int64"
151
+ }
152
+ }
ufc_imputer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9400ad906a586229f1231dbf6cdf8f476a7f509e39508274246a32cf9fe321d8
3
+ size 1167
ufc_model_metadata.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "feature_columns": [
3
+ "KD_diff",
4
+ "STR_diff",
5
+ "TD_diff",
6
+ "SUB_diff",
7
+ "Fighter_1_KD",
8
+ "Fighter_2_KD",
9
+ "Fighter_1_STR",
10
+ "Fighter_2_STR",
11
+ "Fighter_1_TD",
12
+ "Fighter_2_TD",
13
+ "Fighter_1_SUB",
14
+ "Fighter_2_SUB",
15
+ "Fighter_1_accuracy",
16
+ "Fighter_2_accuracy",
17
+ "Round",
18
+ "weight_class_Bantamweight",
19
+ "weight_class_Catch Weight",
20
+ "weight_class_Featherweight",
21
+ "weight_class_Flyweight",
22
+ "weight_class_Heavyweight",
23
+ "weight_class_Light Heavyweight",
24
+ "weight_class_Lightweight",
25
+ "weight_class_Middleweight",
26
+ "weight_class_Welterweight",
27
+ "Method_encoded"
28
+ ],
29
+ "best_model_name": "Regresi\u00f3n Log\u00edstica",
30
+ "best_accuracy": 0.9892183288409704,
31
+ "best_auc": 0.9834103566773315,
32
+ "model_type": "LogisticRegression",
33
+ "input_requirements": "Ver feature_ranges.json para rangos",
34
+ "training_date": "2025-11-28 02:46:41"
35
+ }
ufc_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bbf900d3a0f02d1de405829db7de8cea70979e2f618f64af9097e3237d45e096
3
+ size 1050