File size: 2,769 Bytes
528396d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ef123c
528396d
 
 
 
 
 
 
 
00d481f
 
 
 
 
 
528396d
 
 
6ef123c
528396d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ef123c
528396d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
tags:
- pytorch
- xG
- football
- soccer
- expected-goals
- mlp
- binary-classification
library_name: pytorch
---

# MLP xG Prediction Model

This is a Multi-Layer Perceptron (MLP) model trained to predict Expected Goals (xG) in football/soccer.

## Model Description

- **Architecture**: Multi-Layer Perceptron with 3 hidden layers
- **Hidden Dimensions**: 128 → 64 → 32
- **Input Features**: 22 features
- **Output**: Binary probability (goal vs no goal)
- **Framework**: PyTorch
- **Dropout Rate**: 0.3
- **Activation**: ReLU (hidden layers), Sigmoid (output)
- **Normalization**: Batch Normalization after each hidden layer

## Performance Metrics

- **Accuracy**: 0.8797
- **Precision**: 0.6452
- **Recall**: 0.1225
- **F1 Score**: 0.2060
- **ROC AUC**: 0.7866
- **Log Loss**: 0.3169

## Features

The model uses the following 22 features:

- angle_to_gk
- angle_to_goal
- ball_closer_than_gk
- body_part_name_Left Foot
- body_part_name_Other
- body_part_name_Right Foot
- dist_to_gk
- distance_to_goal
- goal_dist_to_gk
- minute
- nearest_opponent_dist
- nearest_teammate_dist
- opponents_within_5m
- play_pattern_name_From Counter
- play_pattern_name_From Free Kick
- play_pattern_name_From Goal Kick
- play_pattern_name_From Keeper
- play_pattern_name_From Kick Off
- play_pattern_name_From Throw In
- play_pattern_name_Other
- play_pattern_name_Regular Play
- teammates_within_5m

## Usage

```python
import torch
import joblib
from huggingface_hub import hf_hub_download

# Download files
model_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="best_mlp_model.pth")
architecture_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="model_architecture.py")
scaler_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="scaler.pkl")
config_path = hf_hub_download(repo_id="rokati/mlp_xg", filename="config.json")

# Load architecture
import importlib.util
spec = importlib.util.spec_from_file_location("model_architecture", architecture_path)
model_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(model_module)

# Load model
model = model_module.MLP(input_dim=22, hidden_dims=[128, 64, 32], dropout_rate=0.3)
model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')))
model.eval()

# Load scaler
scaler = joblib.load(scaler_path)

# Make prediction
# X_new should be a pandas DataFrame or numpy array with the correct features
X_scaled = scaler.transform(X_new)
X_tensor = torch.FloatTensor(X_scaled)
with torch.no_grad():
    xg_prediction = model(X_tensor).numpy()
```

## Training

The model was trained on football shot event data with:
- Binary Cross Entropy loss
- Adam optimizer (lr=0.001, weight_decay=1e-5)
- ReduceLROnPlateau scheduler
- Batch size: 256
- Epochs: 50

## License

MIT