119 lines
3.1 KiB
Markdown
119 lines
3.1 KiB
Markdown
# Prédiction de Matchs de Tennis avec FastAPI
|
|
|
|
Ce projet utilise FastAPI pour fournir des prédictions de matchs de tennis basées sur un modèle de machine learning pré-entraîné. L'API permet de faire des prédictions en lot ou pour un seul match, en utilisant diverses caractéristiques des joueurs et des matchs.
|
|
|
|
## Prérequis
|
|
|
|
Assurez-vous d'avoir Docker installé sur votre machine.
|
|
|
|
## Installation
|
|
|
|
1. Clonez ce dépôt sur votre machine locale :
|
|
```sh
|
|
git clone https://gitea.mortreau.net/aslane/Tennis-AI.git
|
|
cd Tennis-AI
|
|
```
|
|
|
|
2. Placez votre modèle `pipeline_xgb.pkl` dans le répertoire du projet.
|
|
|
|
3. Assurez-vous que votre fichier `requirements.txt` contient les dépendances nécessaires, y compris `fastapi`, `uvicorn`, `gunicorn`, `numpy`, `pydantic`, etc.
|
|
|
|
## Construction et Exécution du Conteneur Docker
|
|
|
|
1. Construisez l'image Docker :
|
|
```sh
|
|
docker build -t tennis-prediction-app .
|
|
```
|
|
|
|
2. Exécutez le conteneur :
|
|
```sh
|
|
docker run -p 8000:8000 tennis-prediction-app
|
|
```
|
|
|
|
## Utilisation de l'API
|
|
|
|
### Endpoint de Prédiction en Lot
|
|
|
|
- **URL** : `/predict_batch`
|
|
- **Méthode** : `POST`
|
|
- **Corps de la Requête** :
|
|
```json
|
|
{
|
|
"matches": [
|
|
{
|
|
"match_id": 1,
|
|
"player_id1": 101,
|
|
"player_id2": 102,
|
|
"p1_niveau_rank": 5.0,
|
|
"p1_niveau_win_total": 10.0,
|
|
"p1_niveau_win_surface_total": 3.0,
|
|
...
|
|
"idc_p2_historique_estimated": 0.5,
|
|
"tournament_round": 2,
|
|
"tournament_type": 1,
|
|
"tournament_surface": 0
|
|
},
|
|
{
|
|
"match_id": 2,
|
|
"player_id1": 103,
|
|
"player_id2": 104,
|
|
...
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
- **Réponse** :
|
|
```json
|
|
{
|
|
"predictions": [
|
|
{
|
|
"match_id": 1,
|
|
"win_probability_j1": 0.65,
|
|
"win_probability_j2": 0.35
|
|
},
|
|
{
|
|
"match_id": 2,
|
|
...
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### Endpoint de Prédiction pour un Seul Match
|
|
|
|
- **URL** : `/predict`
|
|
- **Méthode** : `POST`
|
|
- **Corps de la Requête** :
|
|
```json
|
|
{
|
|
"match_id": 1,
|
|
"player_id1": 101,
|
|
"player_id2": 102,
|
|
"p1_niveau_rank": 5.0,
|
|
"p1_niveau_win_total": 10.0,
|
|
"p1_niveau_win_surface_total": 3.0,
|
|
...
|
|
"idc_p2_historique_estimated": 0.5,
|
|
"tournament_round": 2,
|
|
"tournament_type": 1,
|
|
"tournament_surface": 0
|
|
}
|
|
```
|
|
|
|
- **Réponse** :
|
|
```json
|
|
{
|
|
"match_id": 1,
|
|
"win_probability_j1": 0.65,
|
|
"win_probability_j2": 0.35
|
|
}
|
|
```
|
|
|
|
## Structure du Projet
|
|
|
|
- `main.py` : Contient le code principal de l'application FastAPI.
|
|
- `pipeline_xgb.pkl` : Fichier du modèle pré-entraîné.
|
|
- `requirements.txt` : Liste des dépendances Python.
|
|
- `Dockerfile` : Fichier de configuration pour Docker.
|
|
- `start.sh` : Script pour démarrer l'application avec Gunicorn. |